Commit d207ad3
Fix MCPStreamableHTTPTool auth headers not being passed correctly (#146)
* Fix MCPStreamableHTTPTool auth headers not being passed correctly
* code review
* code review
* Add unit tests for httpx client configuration in MCP tool registration
Tests verify that:
- Authorization header is set on httpx.AsyncClient
- User-Agent header is set on httpx.AsyncClient
- MCP_HTTP_CLIENT_TIMEOUT_SECONDS constant (90s) is used
- MCPStreamableHTTPTool receives http_client param (not headers)
- httpx clients are tracked in _http_clients for cleanup
- cleanup() properly closes all httpx clients
These tests prevent regression to the bug where passing headers
directly to MCPStreamableHTTPTool was silently ignored.
* Add end-to-end httpx client lifecycle tests
New TestHttpxClientLifecycle class with 4 tests:
- test_full_client_lifecycle_single_server: verifies client created by
add_tool_servers_to_agent() is properly closed by cleanup()
- test_full_client_lifecycle_multiple_servers: verifies all clients are
tracked and cleaned up when multiple MCP servers are configured
- test_cleanup_idempotent_no_clients: verifies cleanup() is safe when
no clients exist
- test_cleanup_called_twice_after_creating_clients: verifies calling
cleanup() multiple times doesn't cause issues
These tests ensure connection/file-descriptor leaks are prevented by
verifying the full client lifecycle from creation to cleanup.
* Add httpx as runtime dependency for agentframework tooling extension
httpx is now used directly in mcp_tool_registration_service.py to create
AsyncClient instances with pre-configured headers. Without this explicit
dependency, consumers could hit ModuleNotFoundError if httpx isn't
available through transitive dependencies.
* Fix linting issues in MCP tool registration tests
- Remove unused httpx import
- Remove unused mock_mcp_tool variable assignments
- Sort imports properly
- Remove trailing whitespace from blank lines
* Apply ruff formatting to test file
---------
Co-authored-by: Josina Joy <josjoy@microsoft.com>1 parent fb1b171 commit d207ad3
File tree
3 files changed
+752
-3
lines changed- libraries/microsoft-agents-a365-tooling-extensions-agentframework
- microsoft_agents_a365/tooling/extensions/agentframework/services
- tests/tooling/extensions/agentframework/services
3 files changed
+752
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
| |||
114 | 120 | | |
115 | 121 | | |
116 | 122 | | |
117 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
118 | 130 | | |
119 | 131 | | |
120 | 132 | | |
121 | | - | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
| |||
339 | 351 | | |
340 | 352 | | |
341 | 353 | | |
| 354 | + | |
342 | 355 | | |
343 | 356 | | |
344 | 357 | | |
345 | 358 | | |
346 | 359 | | |
347 | | - | |
| 360 | + | |
348 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
349 | 370 | | |
350 | 371 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
0 commit comments