MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / test_context_propagation

Function test_context_propagation

tests/client/test_client.py:388–403  ·  view source on GitHub ↗

Sender's contextvars.Context is propagated to the server handler.

()

Source from the content-addressed store, hash-verified

386
387
388async 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
406async def test_client_auto_mode_probes_discover_then_adopts(simple_server: Server) -> None:

Callers

nothing calls this directly

Calls 4

MCPServerClass · 0.90
ClientClass · 0.90
_set_test_contextvarFunction · 0.85
call_toolMethod · 0.45

Tested by

no test coverage detected