Skip to content

Commit

Permalink
add request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretiveShell committed Jan 4, 2025
1 parent cce8519 commit 368782c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import AnyUrl

import mcp.types as types
from mcp.shared.session import BaseSession
from mcp.shared.session import BaseSession, RequestResponder
from mcp.shared.version import SUPPORTED_PROTOCOL_VERSIONS

sampling_function_signature = Callable[
Expand Down Expand Up @@ -255,3 +255,17 @@ async def send_roots_list_changed(self) -> None:
)
)
)

async def _received_request(
self, responder: RequestResponder["types.ServerRequest", "types.ClientResult"]
) -> None:
if isinstance(responder.request.root, types.CreateMessageRequest):
print("Received create message request")
if self.sampling_callback is None:
raise RuntimeError("Sampling callback is not set")
response = await self.sampling_callback(responder.request.root.params)

client_response = types.ClientResult(**response.model_dump())

print(f"Response: {response.dict()}")
await responder.respond(client_response)

0 comments on commit 368782c

Please sign in to comment.