Skip to content

Bug fix: a missing type variable ReceiveResultT in the BaseSession class definition. #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mcp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""FastMCP CLI package."""
# pyright: reportUnknownVariableType=false

from .cli import app

Expand Down
4 changes: 4 additions & 0 deletions src/mcp/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""MCP CLI tools."""
# pyright: reportMissingImports=false
# pyright: reportUnknownMemberType=false
# pyright: reportUnknownVariableType=false
# pyright: reportUntypedFunctionDecorator=false

import importlib.metadata
import importlib.util
Expand Down
11 changes: 6 additions & 5 deletions src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ async def _default_logging_callback(

class ClientSession(
BaseSession[
types.ClientRequest,
types.ClientNotification,
types.ClientResult,
types.ServerRequest,
types.ServerNotification,
types.ClientRequest, # SendRequestT
types.ClientNotification, # SendNotificationT
types.ClientResult, # SendResultT
types.ServerRequest, # ReceiveRequestT
Any, # ReceiveResultT,Any Type
types.ServerNotification, # ReceiveNotificationT
]
):
def __init__(
Expand Down
5 changes: 5 additions & 0 deletions src/mcp/client/websocket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# pyright: reportMissingImports=false
# pyright: reportUnknownVariableType=false
# pyright: reportUnknownArgumentType=false
# pyright: reportUnknownMemberType=false

import json
import logging
from collections.abc import AsyncGenerator
Expand Down
1 change: 1 addition & 0 deletions src/mcp/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ServerSession(
types.ServerNotification,
types.ServerResult,
types.ClientRequest,
Any,
types.ClientNotification,
]
):
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/shared/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mcp.shared.session import BaseSession
from mcp.types import RequestId, RequestParams

SessionT = TypeVar("SessionT", bound=BaseSession[Any, Any, Any, Any, Any])
SessionT = TypeVar("SessionT", bound=BaseSession[Any, Any, Any, Any, Any, Any])
LifespanContextT = TypeVar("LifespanContextT")
RequestT = TypeVar("RequestT", default=Any)

Expand Down
17 changes: 13 additions & 4 deletions src/mcp/shared/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BaseSession,
ReceiveNotificationT,
ReceiveRequestT,
ReceiveResultT,
SendNotificationT,
SendRequestT,
SendResultT,
Expand All @@ -23,8 +24,12 @@ class Progress(BaseModel):


@dataclass
class ProgressContext(Generic[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT]):
session: BaseSession[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT]
class ProgressContext(
Generic[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT, ReceiveResultT]
):
session: BaseSession[
SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveResultT, ReceiveNotificationT
]
progress_token: ProgressToken
total: float | None
current: float = field(default=0.0, init=False)
Expand All @@ -40,12 +45,16 @@ async def progress(self, amount: float, message: str | None = None) -> None:
@contextmanager
def progress(
ctx: RequestContext[
BaseSession[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT],
BaseSession[
SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveResultT, ReceiveNotificationT
],
LifespanContextT,
],
total: float | None = None,
) -> Generator[
ProgressContext[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT],
ProgressContext[
SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT, ReceiveResultT
],
None,
]:
if ctx.meta is None or ctx.meta.progressToken is None:
Expand Down
2 changes: 2 additions & 0 deletions src/mcp/shared/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(
SendNotificationT,
SendResultT,
ReceiveRequestT,
ReceiveResultT,
ReceiveNotificationT
]""",
on_complete: Callable[["RequestResponder[ReceiveRequestT, SendResultT]"], Any],
Expand Down Expand Up @@ -162,6 +163,7 @@ class BaseSession(
SendNotificationT,
SendResultT,
ReceiveRequestT,
ReceiveResultT,
ReceiveNotificationT,
],
):
Expand Down
2 changes: 1 addition & 1 deletion tests/shared/test_progress_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async def handle_client_message(
# cast for type checker
typed_context = cast(
RequestContext[
BaseSession[Any, Any, Any, Any, Any],
BaseSession[Any, Any, Any, Any, Any, Any],
Any,
],
request_context,
Expand Down
Loading