11"""Typed MCP request sugar over an `Outbound`.
22
33`PeerMixin` defines the server-to-client request methods (sampling, elicitation,
4- roots, ping) once. Any class that satisfies `Outbound` (i.e. has `send_request `
4+ roots, ping) once. Any class that satisfies `Outbound` (i.e. has `send_raw_request `
55and `notify`) can mix it in and get the typed methods for free — `Context`,
66`Connection`, `Client`, or the bare `Peer` wrapper below.
77
88The mixin does no capability gating: it builds the params, calls
9- ``self.send_request (method, params)``, and parses the result into the typed
10- model. Gating (and `NoBackChannelError`) is the host's `send_request `'s job.
9+ ``self.send_raw_request (method, params)``, and parses the result into the typed
10+ model. Gating (and `NoBackChannelError`) is the host's `send_raw_request `'s job.
1111"""
1212
1313from collections .abc import Mapping
@@ -43,7 +43,7 @@ class PeerMixin:
4343 """Typed server-to-client request methods.
4444
4545 Each method constrains ``self`` to `Outbound` so the mixin can be applied
46- to anything with ``send_request ``/``notify`` — pyright checks the host
46+ to anything with ``send_raw_request ``/``notify`` — pyright checks the host
4747 class structurally at the call site.
4848 """
4949
@@ -113,7 +113,7 @@ async def sample(
113113 tools = tools ,
114114 tool_choice = tool_choice ,
115115 )
116- result = await self .send_request ("sampling/createMessage" , _dump (params ), opts )
116+ result = await self .send_raw_request ("sampling/createMessage" , _dump (params ), opts )
117117 if tools is not None :
118118 return CreateMessageResultWithTools .model_validate (result )
119119 return CreateMessageResult .model_validate (result )
@@ -131,7 +131,7 @@ async def elicit_form(
131131 NoBackChannelError: No back-channel for server-initiated requests.
132132 """
133133 params = ElicitRequestFormParams (message = message , requested_schema = requested_schema )
134- result = await self .send_request ("elicitation/create" , _dump (params ), opts )
134+ result = await self .send_raw_request ("elicitation/create" , _dump (params ), opts )
135135 return ElicitResult .model_validate (result )
136136
137137 async def elicit_url (
@@ -148,7 +148,7 @@ async def elicit_url(
148148 NoBackChannelError: No back-channel for server-initiated requests.
149149 """
150150 params = ElicitRequestURLParams (message = message , url = url , elicitation_id = elicitation_id )
151- result = await self .send_request ("elicitation/create" , _dump (params ), opts )
151+ result = await self .send_raw_request ("elicitation/create" , _dump (params ), opts )
152152 return ElicitResult .model_validate (result )
153153
154154 async def list_roots (self : Outbound , opts : CallOptions | None = None ) -> ListRootsResult :
@@ -158,7 +158,7 @@ async def list_roots(self: Outbound, opts: CallOptions | None = None) -> ListRoo
158158 MCPError: The peer responded with an error.
159159 NoBackChannelError: No back-channel for server-initiated requests.
160160 """
161- result = await self .send_request ("roots/list" , None , opts )
161+ result = await self .send_raw_request ("roots/list" , None , opts )
162162 return ListRootsResult .model_validate (result )
163163
164164 async def ping (self : Outbound , opts : CallOptions | None = None ) -> None :
@@ -168,7 +168,7 @@ async def ping(self: Outbound, opts: CallOptions | None = None) -> None:
168168 MCPError: The peer responded with an error.
169169 NoBackChannelError: No back-channel for server-initiated requests.
170170 """
171- await self .send_request ("ping" , None , opts )
171+ await self .send_raw_request ("ping" , None , opts )
172172
173173
174174class Peer (PeerMixin ):
@@ -182,13 +182,13 @@ class Peer(PeerMixin):
182182 def __init__ (self , outbound : Outbound ) -> None :
183183 self ._outbound = outbound
184184
185- async def send_request (
185+ async def send_raw_request (
186186 self ,
187187 method : str ,
188188 params : Mapping [str , Any ] | None ,
189189 opts : CallOptions | None = None ,
190190 ) -> dict [str , Any ]:
191- return await self ._outbound .send_request (method , params , opts )
191+ return await self ._outbound .send_raw_request (method , params , opts )
192192
193193 async def notify (self , method : str , params : Mapping [str , Any ] | None ) -> None :
194194 await self ._outbound .notify (method , params )
0 commit comments