Add a client extension API (#3034)

This commit is contained in:
Max 2026-06-30 21:31:02 +01:00 • committed by GitHub
commit 4df609119f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3410 additions and 180 deletions

View file

@ -8,6 +8,7 @@ https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/dr
from mcp_types._types import (
CLIENT_CAPABILITIES_META_KEY,
CLIENT_INFO_META_KEY,
CORE_RESULT_TYPES,
DEFAULT_NEGOTIATED_VERSION,
LOG_LEVEL_META_KEY,
PROTOCOL_VERSION_META_KEY,
@ -231,6 +232,7 @@ __all__ = [
"CLIENT_CAPABILITIES_META_KEY",
"LOG_LEVEL_META_KEY",
# Type aliases and variables
"CORE_RESULT_TYPES",
"ContentBlock",
"ElicitRequestedSchema",
"ElicitRequestParams",

View file

@ -8,7 +8,7 @@ the negotiated version. Per-field docstrings note version availability. The
from __future__ import annotations
from typing import Annotated, Any, Final, Generic, Literal, TypeAlias, TypeVar
from typing import Annotated, Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar, get_args
from pydantic import (
BaseModel,
@ -128,6 +128,12 @@ class Request(MCPModel, Generic[RequestParamsT, MethodT]):
method: MethodT
params: RequestParamsT
name_param: ClassVar[str | None] = None
"""Wire-params key mirrored into the `Mcp-Name` header on sends; SEP-2663 requires it for tasks/*.
Subclasses override by bare assignment: re-annotating as `ClassVar` trips pyright's invariance check.
"""
class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[MethodT]):
"""Base class for paginated requests, matching the schema's PaginatedRequest interface."""
@ -144,7 +150,9 @@ class Notification(MCPModel, Generic[NotificationParamsT, MethodT]):
params: NotificationParamsT
ResultType = Literal["complete", "input_required"] | str
_CoreResultType = Literal["complete", "input_required"]
ResultType = _CoreResultType | str
"""Tags a `Result` so the client knows how to parse it (2026-07-28).
"complete" means the result is final; "input_required" means it is an
@ -152,6 +160,9 @@ ResultType = Literal["complete", "input_required"] | str
Absent `resultType` is equivalent to "complete".
"""
CORE_RESULT_TYPES: Final[frozenset[str]] = frozenset(get_args(_CoreResultType))
"""The `resultType` tags owned by the core protocol vocabulary; extension claims may not re-key them."""
class Result(MCPModel):
"""Base class for JSON-RPC results.