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.
This commit is contained in:
David Soria Parra
2024-10-11 11:48:52 +01:00
parent 04ad96e6cd
commit ac6064b016

View File

@@ -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")