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

Class StubOutbound

tests/server/test_stateless_mode.py:23–53  ·  view source on GitHub ↗

Records `send_raw_request` / `notify` calls and returns a canned result. Structurally a `DispatchContext[Any]` so it can stand in for the per-request channel.

Source from the content-addressed store, hash-verified

21
22
23class StubOutbound:
24 """Records `send_raw_request` / `notify` calls and returns a canned result.
25
26 Structurally a `DispatchContext[Any]` so it can stand in for the per-request channel.
27 """
28
29 transport: Any = None
30 can_send_request: bool = True
31 request_id: Any = None
32 message_metadata: Any = None
33 cancel_requested: Any = None
34
35 def __init__(self, result: dict[str, Any] | None = None) -> None:
36 self.requests: list[tuple[str, Mapping[str, Any] | None, CallOptions | None]] = []
37 self.notifications: list[tuple[str, Mapping[str, Any] | None]] = []
38 self.result = result if result is not None else {}
39
40 async def send_raw_request(
41 self,
42 method: str,
43 params: Mapping[str, Any] | None,
44 opts: CallOptions | None = None,
45 ) -> dict[str, Any]:
46 self.requests.append((method, params, opts))
47 return self.result
48
49 async def notify(self, method: str, params: Mapping[str, Any] | None, opts: CallOptions | None = None) -> None:
50 self.notifications.append((method, params))
51
52 async def progress(self, progress: float, total: float | None = None, message: str | None = None) -> None:
53 raise NotImplementedError # pragma: no cover
54
55
56def _no_channel_session(request_ch: StubOutbound | None = None) -> tuple[ServerSession, StubOutbound]:

Calls

no outgoing calls