diff --git a/mcp_python/server/__init__.py b/mcp_python/server/__init__.py index 375cbfe8d..581f259e7 100644 --- a/mcp_python/server/__init__.py +++ b/mcp_python/server/__init__.py @@ -20,6 +20,8 @@ CompleteRequest, ErrorData, JSONRPCMessage, + ListPromptsRequest, + ListPromptsResult, ListResourcesRequest, ListResourcesResult, LoggingLevel, @@ -57,8 +59,6 @@ def request_context(self) -> RequestContext: return request_ctx.get() def list_prompts(self): - from mcp_python.types import ListPromptsRequest, ListPromptsResult - def decorator(func: Callable[[], Awaitable[list[Prompt]]]): logger.debug(f"Registering handler for PromptListRequest") @@ -90,7 +90,7 @@ def decorator( async def handler(req: GetPromptRequest): prompt_get = await func(req.params.name, req.params.arguments) - messages = [] + messages: list[SamplingMessage] = [] for message in prompt_get.messages: match message.content: case str() as text_content: diff --git a/mcp_python/server/stdio.py b/mcp_python/server/stdio.py index bfcc76c4d..b55df0ef5 100644 --- a/mcp_python/server/stdio.py +++ b/mcp_python/server/stdio.py @@ -7,10 +7,9 @@ from mcp_python.types import JSONRPCMessage - @asynccontextmanager async def stdio_server( - stdin: anyio.AsyncFile | None = None, stdout: anyio.AsyncFile | None = None + stdin: anyio.AsyncFile[str] | None = None, stdout: anyio.AsyncFile[str] | None = None ): """ Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout. diff --git a/mcp_python/types.py b/mcp_python/types.py index becc2b1fc..108752650 100644 --- a/mcp_python/types.py +++ b/mcp_python/types.py @@ -41,23 +41,23 @@ class Meta(BaseModel): This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications. """ - RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams) NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams) +MethodT = TypeVar("MethodT", bound=str) -class Request(BaseModel, Generic[RequestParamsT]): +class Request(BaseModel, Generic[RequestParamsT, MethodT]): """Base class for JSON-RPC requests.""" - method: str + method: MethodT params: RequestParamsT model_config = ConfigDict(extra="allow") -class Notification(BaseModel, Generic[NotificationParamsT]): +class Notification(BaseModel, Generic[NotificationParamsT, MethodT]): """Base class for JSON-RPC notifications.""" - method: str + method: MethodT model_config = ConfigDict(extra="allow") diff --git a/pyproject.toml b/pyproject.toml index e0cb38bbd..4d2258b14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,6 @@ packages = ["mcp_python"] [tool.pyright] include = ["mcp_python", "tests"] -typeCheckingMode = "strict" venvPath = "." venv = ".venv"