Skip to content

Commit 85e9e19

Browse files
committed
handle ping requests
1 parent acb89b4 commit 85e9e19

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mcp_python/server/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ClientNotification,
1919
ClientRequest,
2020
CompleteRequest,
21+
EmptyResult,
2122
ErrorData,
2223
JSONRPCMessage,
2324
ListPromptsRequest,
@@ -27,6 +28,7 @@
2728
ListToolsRequest,
2829
ListToolsResult,
2930
LoggingLevel,
31+
PingRequest,
3032
ProgressNotification,
3133
Prompt,
3234
PromptReference,
@@ -52,7 +54,9 @@
5254
class Server:
5355
def __init__(self, name: str):
5456
self.name = name
55-
self.request_handlers: dict[type, Callable[..., Awaitable[ServerResult]]] = {}
57+
self.request_handlers: dict[type, Callable[..., Awaitable[ServerResult]]] = {
58+
PingRequest: _ping_handler,
59+
}
5660
self.notification_handlers: dict[type, Callable[..., Awaitable[None]]] = {}
5761
logger.info(f"Initializing server '{name}'")
5862

@@ -413,3 +417,7 @@ async def run(
413417
logger.info(
414418
f"Warning: {warning.category.__name__}: {warning.message}"
415419
)
420+
421+
422+
async def _ping_handler(request: PingRequest) -> ServerResult:
423+
return ServerResult(EmptyResult())

0 commit comments

Comments
 (0)