From ac6064b016157d3922c39fe0144441fc3ab975d0 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 11 Oct 2024 11:48:52 +0100 Subject: [PATCH] Make request and notification method generic The request and notification method were defined as str but later overwritten in subclasses with literals. This causes a reportIncompatibleVariableOverride issue. We need to make method generic. --- mcp_python/types.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mcp_python/types.py b/mcp_python/types.py index becc2b1..1087526 100644 --- a/mcp_python/types.py +++ b/mcp_python/types.py @@ -41,23 +41,23 @@ class NotificationParams(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")