Sender's contextvars.Context is propagated to the server handler.
()
| 386 | |
| 387 | |
| 388 | async def test_context_propagation(): |
| 389 | """Sender's contextvars.Context is propagated to the server handler.""" |
| 390 | server = MCPServer("test") |
| 391 | |
| 392 | @server.tool() |
| 393 | async def check_context() -> str: |
| 394 | """Return the contextvar value visible to the handler.""" |
| 395 | return _TEST_CONTEXTVAR.get() |
| 396 | |
| 397 | async with Client(server) as client: |
| 398 | with _set_test_contextvar("client_value"): |
| 399 | result = await client.call_tool("check_context", {}) |
| 400 | |
| 401 | assert result.content[0].text == "client_value", ( # type: ignore[union-attr] |
| 402 | "Server handler did not see the sender's contextvars.Context" |
| 403 | ) |
| 404 | |
| 405 | |
| 406 | async def test_client_auto_mode_probes_discover_then_adopts(simple_server: Server) -> None: |
nothing calls this directly
no test coverage detected