Add mcp.types as a permanent alias for mcp_types (#3190)

This commit is contained in:
Max 2026-07-27 23:47:04 +01:00 • committed by GitHub
commit b7c9a916d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 467 additions and 364 deletions

View file

@ -6,6 +6,29 @@ from typing import Annotated, Any, Final, Literal
from pydantic import BaseModel, Field, TypeAdapter
__all__ = [
"CONNECTION_CLOSED",
"HEADER_MISMATCH",
"INTERNAL_ERROR",
"INVALID_PARAMS",
"INVALID_REQUEST",
"JSONRPC_VERSION",
"METHOD_NOT_FOUND",
"MISSING_REQUIRED_CLIENT_CAPABILITY",
"PARSE_ERROR",
"REQUEST_TIMEOUT",
"UNSUPPORTED_PROTOCOL_VERSION",
"URL_ELICITATION_REQUIRED",
"ErrorData",
"JSONRPCError",
"JSONRPCMessage",
"JSONRPCNotification",
"JSONRPCRequest",
"JSONRPCResponse",
"RequestId",
"jsonrpc_message_adapter",
]
RequestId = Annotated[int, Field(strict=True)] | str
"""The ID of a JSON-RPC request."""

View file

@ -9,6 +9,18 @@ ordering questions go through KNOWN_PROTOCOL_VERSIONS.
from typing import Final
__all__ = [
"KNOWN_PROTOCOL_VERSIONS",
"HANDSHAKE_PROTOCOL_VERSIONS",
"MODERN_PROTOCOL_VERSIONS",
"SUPPORTED_PROTOCOL_VERSIONS",
"LATEST_PROTOCOL_VERSION",
"LATEST_HANDSHAKE_VERSION",
"LATEST_MODERN_VERSION",
"OLDEST_SUPPORTED_VERSION",
"is_version_at_least",
]
KNOWN_PROTOCOL_VERSIONS: Final[tuple[str, ...]] = (
"2024-11-05",
"2025-03-26",

View file

@ -58,6 +58,9 @@ from mcp_types import (
)
from mcp_types import Role as SamplingRole
# Bind the `mcp.types` submodule on the package, as v1's `from .types import
# ...` did, so `import mcp` followed by `mcp.types.Tool` keeps working.
from . import types as types
from .client._input_required import InputRequiredRoundsExceededError
from .client.client import Client
from .client.session import ClientSession

31
src/mcp/types/__init__.py Normal file
View file

@ -0,0 +1,31 @@
"""The MCP protocol wire types, as the `mcp.types` namespace.
This module mirrors the standalone `mcp_types` package exactly (every name is the
same object), so SDK users can keep the familiar v1 spelling:
import mcp.types as types
types.TextContent(type="text", text="hi")
The `mcp.types.jsonrpc`, `mcp.types.methods`, and `mcp.types.version`
submodules mirror `mcp_types.jsonrpc`, `mcp_types.methods`, and
`mcp_types.version` the same way, so every supported `mcp_types` import has
an `mcp.types` spelling.
Depend on and import `mcp_types` directly instead when you only need to
(de)serialize MCP traffic and don't want the SDK's transport stack: its only
runtime dependencies are `pydantic` and `typing-extensions`.
"""
# A wildcard mirror of the mcp_types namespace is the whole point of this module.
# pyright: reportWildcardImportFromLibrary=false
from mcp_types import *
from mcp_types import __all__ as __all__
# Bind the mirror submodules on the package, so `mcp.types.version.X` is as
# reachable by attribute access as `mcp_types.version.X` (whose `__init__`
# binds `.version` by importing from it), not only via `from ... import`.
from . import jsonrpc as jsonrpc
from . import methods as methods
from . import version as version

13
src/mcp/types/jsonrpc.py Normal file
View file

@ -0,0 +1,13 @@
"""The JSON-RPC 2.0 message and error types, as the `mcp.types.jsonrpc` namespace.
A mirror of `mcp_types.jsonrpc` (every name is the same object), so code that
depends on `mcp` can import from `mcp.types.jsonrpc` without importing the
`mcp_types` distribution directly. Depend on and import `mcp_types.jsonrpc`
instead when you use `mcp-types` without the SDK.
"""
# A wildcard mirror of the mcp_types.jsonrpc namespace is the whole point of this module.
# pyright: reportWildcardImportFromLibrary=false
from mcp_types.jsonrpc import *
from mcp_types.jsonrpc import __all__ as __all__

13
src/mcp/types/methods.py Normal file
View file

@ -0,0 +1,13 @@
"""The MCP method registry, as the `mcp.types.methods` namespace.
A mirror of `mcp_types.methods` (every name is the same object), so code that
depends on `mcp` can import from `mcp.types.methods` without importing the
`mcp_types` distribution directly. Depend on and import `mcp_types.methods`
instead when you use `mcp-types` without the SDK.
"""
# A wildcard mirror of the mcp_types.methods namespace is the whole point of this module.
# pyright: reportWildcardImportFromLibrary=false
from mcp_types.methods import *
from mcp_types.methods import __all__ as __all__

13
src/mcp/types/version.py Normal file
View file

@ -0,0 +1,13 @@
"""The protocol-version registry, as the `mcp.types.version` namespace.
A mirror of `mcp_types.version` (every name is the same object), so code that
depends on `mcp` can write `from mcp.types.version import LATEST_MODERN_VERSION`
without importing the `mcp_types` distribution directly. Depend on and import
`mcp_types.version` instead when you use `mcp-types` without the SDK.
"""
# A wildcard mirror of the mcp_types.version namespace is the whole point of this module.
# pyright: reportWildcardImportFromLibrary=false
from mcp_types.version import *
from mcp_types.version import __all__ as __all__