Skip to content

Commit 047b5d8

Browse files
authored
Merge pull request #15 from modelcontextprotocol/davidsp/type-fixes
Type Fixes
2 parents 0ccff90 + ac6064b commit 047b5d8

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

mcp_python/server/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
CompleteRequest,
2121
ErrorData,
2222
JSONRPCMessage,
23+
ListPromptsRequest,
24+
ListPromptsResult,
2325
ListResourcesRequest,
2426
ListResourcesResult,
2527
LoggingLevel,
@@ -57,8 +59,6 @@ def request_context(self) -> RequestContext:
5759
return request_ctx.get()
5860

5961
def list_prompts(self):
60-
from mcp_python.types import ListPromptsRequest, ListPromptsResult
61-
6262
def decorator(func: Callable[[], Awaitable[list[Prompt]]]):
6363
logger.debug(f"Registering handler for PromptListRequest")
6464

@@ -90,7 +90,7 @@ def decorator(
9090

9191
async def handler(req: GetPromptRequest):
9292
prompt_get = await func(req.params.name, req.params.arguments)
93-
messages = []
93+
messages: list[SamplingMessage] = []
9494
for message in prompt_get.messages:
9595
match message.content:
9696
case str() as text_content:

mcp_python/server/stdio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
from mcp_python.types import JSONRPCMessage
99

10-
1110
@asynccontextmanager
1211
async def stdio_server(
13-
stdin: anyio.AsyncFile | None = None, stdout: anyio.AsyncFile | None = None
12+
stdin: anyio.AsyncFile[str] | None = None, stdout: anyio.AsyncFile[str] | None = None
1413
):
1514
"""
1615
Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.

mcp_python/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ class Meta(BaseModel):
4141
This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
4242
"""
4343

44-
4544
RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams)
4645
NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams)
46+
MethodT = TypeVar("MethodT", bound=str)
4747

4848

49-
class Request(BaseModel, Generic[RequestParamsT]):
49+
class Request(BaseModel, Generic[RequestParamsT, MethodT]):
5050
"""Base class for JSON-RPC requests."""
5151

52-
method: str
52+
method: MethodT
5353
params: RequestParamsT
5454
model_config = ConfigDict(extra="allow")
5555

5656

57-
class Notification(BaseModel, Generic[NotificationParamsT]):
57+
class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
5858
"""Base class for JSON-RPC notifications."""
5959

60-
method: str
60+
method: MethodT
6161
model_config = ConfigDict(extra="allow")
6262

6363

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ packages = ["mcp_python"]
2222

2323
[tool.pyright]
2424
include = ["mcp_python", "tests"]
25-
typeCheckingMode = "strict"
2625
venvPath = "."
2726
venv = ".venv"
2827

0 commit comments

Comments
 (0)