Skip to content

Commit 60869b0

Browse files
BabyChrist666claude
andcommitted
fix: resolve pyright type errors in experimental.py and tests
- Fix Server type arg count in ExperimentalHandlers (1 param, not 2) - Add proper type annotations to all test functions and parameters Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent db56033 commit 60869b0

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/mcp/server/lowlevel/experimental.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ExperimentalHandlers(Generic[LifespanResultT]):
5454

5555
def __init__(
5656
self,
57-
server: Server[LifespanResultT, Any],
57+
server: Server[LifespanResultT],
5858
) -> None:
5959
self._server = server
6060
self._task_support: TaskSupport | None = None
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
"""Tests for public handler registration/deregistration API on low-level Server."""
22

3+
from typing import Any
4+
35
import pytest
46

7+
from mcp.server.context import ServerRequestContext
58
from mcp.server.lowlevel.server import Server
69

710

811
@pytest.fixture
9-
def server():
12+
def server() -> Server[None]:
1013
return Server(name="test-server")
1114

1215

13-
async def _dummy_request_handler(ctx, params):
16+
async def _dummy_request_handler(ctx: ServerRequestContext[None], params: Any) -> dict[str, str]:
1417
return {"result": "ok"}
1518

1619

17-
async def _dummy_notification_handler(ctx, params):
20+
async def _dummy_notification_handler(ctx: ServerRequestContext[None], params: Any) -> None:
1821
pass
1922

2023

2124
class TestAddRequestHandler:
22-
def test_add_request_handler(self, server):
25+
def test_add_request_handler(self, server: Server[None]) -> None:
2326
server.add_request_handler("custom/method", _dummy_request_handler)
2427
assert server.has_handler("custom/method")
2528

26-
def test_add_request_handler_replaces_existing(self, server):
27-
async def handler_a(ctx, params):
29+
def test_add_request_handler_replaces_existing(self, server: Server[None]) -> None:
30+
async def handler_a(ctx: ServerRequestContext[None], params: Any) -> str:
2831
return "a"
2932

30-
async def handler_b(ctx, params):
33+
async def handler_b(ctx: ServerRequestContext[None], params: Any) -> str:
3134
return "b"
3235

3336
server.add_request_handler("custom/method", handler_a)
@@ -37,27 +40,27 @@ async def handler_b(ctx, params):
3740

3841

3942
class TestRemoveRequestHandler:
40-
def test_remove_request_handler(self, server):
43+
def test_remove_request_handler(self, server: Server[None]) -> None:
4144
server.add_request_handler("custom/method", _dummy_request_handler)
4245
assert server.has_handler("custom/method")
4346
server.remove_request_handler("custom/method")
4447
assert not server.has_handler("custom/method")
4548

46-
def test_remove_request_handler_not_found(self, server):
49+
def test_remove_request_handler_not_found(self, server: Server[None]) -> None:
4750
with pytest.raises(KeyError):
4851
server.remove_request_handler("nonexistent/method")
4952

5053

5154
class TestAddNotificationHandler:
52-
def test_add_notification_handler(self, server):
55+
def test_add_notification_handler(self, server: Server[None]) -> None:
5356
server.add_notification_handler("custom/notify", _dummy_notification_handler)
5457
assert server.has_handler("custom/notify")
5558

56-
def test_add_notification_handler_replaces_existing(self, server):
57-
async def handler_a(ctx, params):
59+
def test_add_notification_handler_replaces_existing(self, server: Server[None]) -> None:
60+
async def handler_a(ctx: ServerRequestContext[None], params: Any) -> None:
5861
pass
5962

60-
async def handler_b(ctx, params):
63+
async def handler_b(ctx: ServerRequestContext[None], params: Any) -> None:
6164
pass
6265

6366
server.add_notification_handler("custom/notify", handler_a)
@@ -66,29 +69,29 @@ async def handler_b(ctx, params):
6669

6770

6871
class TestRemoveNotificationHandler:
69-
def test_remove_notification_handler(self, server):
72+
def test_remove_notification_handler(self, server: Server[None]) -> None:
7073
server.add_notification_handler("custom/notify", _dummy_notification_handler)
7174
assert server.has_handler("custom/notify")
7275
server.remove_notification_handler("custom/notify")
7376
assert not server.has_handler("custom/notify")
7477

75-
def test_remove_notification_handler_not_found(self, server):
78+
def test_remove_notification_handler_not_found(self, server: Server[None]) -> None:
7679
with pytest.raises(KeyError):
7780
server.remove_notification_handler("nonexistent/notify")
7881

7982

8083
class TestHasHandler:
81-
def test_has_handler_request(self, server):
84+
def test_has_handler_request(self, server: Server[None]) -> None:
8285
server.add_request_handler("custom/method", _dummy_request_handler)
8386
assert server.has_handler("custom/method")
8487

85-
def test_has_handler_notification(self, server):
88+
def test_has_handler_notification(self, server: Server[None]) -> None:
8689
server.add_notification_handler("custom/notify", _dummy_notification_handler)
8790
assert server.has_handler("custom/notify")
8891

89-
def test_has_handler_unregistered(self, server):
92+
def test_has_handler_unregistered(self, server: Server[None]) -> None:
9093
assert not server.has_handler("nonexistent/method")
9194

92-
def test_has_handler_default_ping(self, server):
95+
def test_has_handler_default_ping(self, server: Server[None]) -> None:
9396
"""The ping handler is registered by default."""
9497
assert server.has_handler("ping")

0 commit comments

Comments
 (0)