feat: add ClientRequestContext type alias for client-side handlers (#1989)
This commit is contained in:
parent
74f41ff1ae
commit
4fc49c62bd
7 changed files with 55 additions and 37 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from mcp.client._transport import Transport
|
||||
from mcp.client.client import Client
|
||||
from mcp.client.context import ClientRequestContext
|
||||
from mcp.client.session import ClientSession
|
||||
|
||||
__all__ = ["Client", "ClientSession", "Transport"]
|
||||
__all__ = ["Client", "ClientRequestContext", "ClientSession", "Transport"]
|
||||
|
|
|
|||
16
src/mcp/client/context.py
Normal file
16
src/mcp/client/context.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"""Request context for MCP client handlers."""
|
||||
|
||||
from mcp.client.session import ClientSession
|
||||
from mcp.shared._context import RequestContext
|
||||
|
||||
ClientRequestContext = RequestContext[ClientSession]
|
||||
"""Context for handling incoming requests in a client session.
|
||||
|
||||
This context is passed to client-side callbacks (sampling, elicitation, list_roots) when the server sends requests
|
||||
to the client.
|
||||
|
||||
Attributes:
|
||||
request_id: The unique identifier for this request.
|
||||
meta: Optional metadata associated with the request.
|
||||
session: The client session handling this request.
|
||||
"""
|
||||
|
|
@ -19,7 +19,7 @@ from typing import TYPE_CHECKING, Protocol
|
|||
from pydantic import TypeAdapter
|
||||
|
||||
import mcp.types as types
|
||||
from mcp.shared.context import RequestContext
|
||||
from mcp.shared._context import RequestContext
|
||||
from mcp.shared.session import RequestResponder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from pydantic import TypeAdapter
|
|||
import mcp.types as types
|
||||
from mcp.client.experimental import ExperimentalClientFeatures
|
||||
from mcp.client.experimental.task_handlers import ExperimentalTaskHandlers
|
||||
from mcp.shared.context import RequestContext
|
||||
from mcp.shared._context import RequestContext
|
||||
from mcp.shared.message import SessionMessage
|
||||
from mcp.shared.session import BaseSession, ProgressFnT, RequestResponder
|
||||
from mcp.shared.version import SUPPORTED_PROTOCOL_VERSIONS
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from typing_extensions import TypeVar
|
|||
|
||||
from mcp.server.experimental.request_context import Experimental
|
||||
from mcp.server.session import ServerSession
|
||||
from mcp.shared.context import RequestContext
|
||||
from mcp.shared._context import RequestContext
|
||||
from mcp.shared.message import CloseSSEStreamCallback
|
||||
|
||||
LifespanContextT = TypeVar("LifespanContextT")
|
||||
|
|
|
|||
20
src/mcp/shared/_context.py
Normal file
20
src/mcp/shared/_context.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""Request context for MCP handlers."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Generic
|
||||
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from mcp.shared.session import BaseSession
|
||||
from mcp.types import RequestId, RequestParamsMeta
|
||||
|
||||
SessionT = TypeVar("SessionT", bound=BaseSession[Any, Any, Any, Any, Any])
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class RequestContext(Generic[SessionT]):
|
||||
"""Common context for handling incoming requests."""
|
||||
|
||||
request_id: RequestId
|
||||
meta: RequestParamsMeta | None
|
||||
session: SessionT
|
||||
|
|
@ -5,7 +5,7 @@ from typing import Generic
|
|||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mcp.shared.context import RequestContext, SessionT
|
||||
from mcp.shared._context import RequestContext, SessionT
|
||||
from mcp.types import ProgressToken
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue