File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 66from pydantic import AnyUrl
77
88import mcp .types as types
9- from mcp .shared .session import BaseSession
9+ from mcp .shared .session import BaseSession , RequestResponder
1010from mcp .shared .version import SUPPORTED_PROTOCOL_VERSIONS
1111
1212sampling_function_signature = Callable [
@@ -255,3 +255,17 @@ async def send_roots_list_changed(self) -> None:
255255 )
256256 )
257257 )
258+
259+ async def _received_request (
260+ self , responder : RequestResponder ["types.ServerRequest" , "types.ClientResult" ]
261+ ) -> None :
262+ if isinstance (responder .request .root , types .CreateMessageRequest ):
263+ print ("Received create message request" )
264+ if self .sampling_callback is None :
265+ raise RuntimeError ("Sampling callback is not set" )
266+ response = await self .sampling_callback (responder .request .root .params )
267+
268+ client_response = types .ClientResult (** response .model_dump ())
269+
270+ print (f"Response: { response .dict ()} " )
271+ await responder .respond (client_response )
You can’t perform that action at this time.
0 commit comments