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

Function on_request

tests/shared/test_dispatcher.py:43–51  ·  view source on GitHub ↗
(
        ctx: DispatchContext[TransportContext], method: str, params: Mapping[str, Any] | None
    )

Source from the content-addressed store, hash-verified

41
42def echo_handlers(recorder: Recorder) -> tuple[OnRequest, OnNotify]:
43 async def on_request(
44 ctx: DispatchContext[TransportContext], method: str, params: Mapping[str, Any] | None
45 ) -> dict[str, Any]:
46 # Strip `_meta` so JSON-RPC and direct dispatch record identically:
47 # the JSON-RPC outbound path always attaches `_meta` (otel injection).
48 recorded = {k: v for k, v in (params or {}).items() if k != "_meta"} if params is not None else None
49 recorder.requests.append((method, recorded))
50 recorder.contexts.append(ctx)
51 return {"echoed": method, "params": recorded or {}}
52
53 async def on_notify(ctx: DispatchContext[TransportContext], method: str, params: Mapping[str, Any] | None) -> None:
54 recorder.notifications.append((method, params))

Callers 1

_handle_requestMethod · 0.50

Calls 1

MCPErrorClass · 0.90

Tested by

no test coverage detected