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 6
6
from pydantic import AnyUrl
7
7
8
8
import mcp .types as types
9
- from mcp .shared .session import BaseSession
9
+ from mcp .shared .session import BaseSession , RequestResponder
10
10
from mcp .shared .version import SUPPORTED_PROTOCOL_VERSIONS
11
11
12
12
sampling_function_signature = Callable [
@@ -255,3 +255,17 @@ async def send_roots_list_changed(self) -> None:
255
255
)
256
256
)
257
257
)
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