Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ plugins:
group_by_category: false
# 3 because docs are in pages with an H2 just above them
heading_level: 3
import:
inventories:
- url: https://docs.python.org/3/objects.inv
- url: https://docs.pydantic.dev/latest/objects.inv
- url: https://typing-extensions.readthedocs.io/en/latest/objects.inv
4 changes: 1 addition & 3 deletions src/mcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
ToolUseContent,
UnsubscribeRequest,
)
from .types import (
Role as SamplingRole,
)
from .types import Role as SamplingRole

__all__ = [
"CallToolRequest",
Expand Down
3 changes: 2 additions & 1 deletion src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def get_server_capabilities(self) -> types.ServerCapabilities | None:
def experimental(self) -> ExperimentalClientFeatures:
"""Experimental APIs for tasks and other features.

WARNING: These APIs are experimental and may change without notice.
!!! warning
These APIs are experimental and may change without notice.

Example:
status = await session.experimental.get_task(task_id)
Expand Down
19 changes: 8 additions & 11 deletions src/mcp/shared/session.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations as _annotations

import logging
from collections.abc import Callable
from contextlib import AsyncExitStack
Expand Down Expand Up @@ -72,14 +74,8 @@ def __init__(
request_id: RequestId,
request_meta: RequestParams.Meta | None,
request: ReceiveRequestT,
session: """BaseSession[
SendRequestT,
SendNotificationT,
SendResultT,
ReceiveRequestT,
ReceiveNotificationT
]""",
on_complete: Callable[["RequestResponder[ReceiveRequestT, SendResultT]"], Any],
session: BaseSession[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT],
on_complete: Callable[[RequestResponder[ReceiveRequestT, SendResultT]], Any],
message_metadata: MessageMetadata = None,
) -> None:
self.request_id = request_id
Expand All @@ -92,7 +88,7 @@ def __init__(
self._on_complete = on_complete
self._entered = False # Track if we're in a context manager

def __enter__(self) -> "RequestResponder[ReceiveRequestT, SendResultT]":
def __enter__(self) -> RequestResponder[ReceiveRequestT, SendResultT]:
"""Enter the context manager, enabling request cancellation tracking."""
self._entered = True
self._cancel_scope = anyio.CancelScope()
Expand Down Expand Up @@ -179,7 +175,7 @@ class BaseSession(
_request_id: int
_in_flight: dict[RequestId, RequestResponder[ReceiveRequestT, SendResultT]]
_progress_callbacks: dict[RequestId, ProgressFnT]
_response_routers: list["ResponseRouter"]
_response_routers: list[ResponseRouter]

def __init__(
self,
Expand Down Expand Up @@ -210,7 +206,8 @@ def add_response_router(self, router: ResponseRouter) -> None:
response stream mechanism. This is used by TaskResultHandler to route
responses for queued task requests back to their resolvers.

WARNING: This is an experimental API that may change without notice.
!!! warn
This is an experimental API that may change without notice.

Args:
router: A ResponseRouter implementation
Expand Down
26 changes: 5 additions & 21 deletions src/mcp/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations as _annotations

from collections.abc import Callable
from datetime import datetime
from typing import Annotated, Any, Final, Generic, Literal, TypeAlias, TypeVar
Expand All @@ -6,24 +8,6 @@
from pydantic.networks import AnyUrl, UrlConstraints
from typing_extensions import deprecated

"""
Model Context Protocol bindings for Python

These bindings were generated from https://github.com/modelcontextprotocol/specification,
using Claude, with a prompt something like the following:

Generate idiomatic Python bindings for this schema for MCP, or the "Model Context
Protocol." The schema is defined in TypeScript, but there's also a JSON Schema version
for reference.

* For the bindings, let's use Pydantic V2 models.
* Each model should allow extra fields everywhere, by specifying `model_config =
ConfigDict(extra='allow')`. Do this in every case, instead of a custom base class.
* Union types should be represented with a Pydantic `RootModel`.
* Define additional model classes instead of using dictionaries. Do this even if they're
not separate types in the schema.
"""

LATEST_PROTOCOL_VERSION = "2025-11-25"

"""
Expand Down Expand Up @@ -557,7 +541,7 @@ class Task(BaseModel):
"""Current task state."""

statusMessage: str | None = None
"""
"""
Optional human-readable message describing the current task state.
This can provide context for any status, including:
- Reasons for "cancelled" status
Expand Down Expand Up @@ -1121,7 +1105,7 @@ class ToolResultContent(BaseModel):
toolUseId: str
"""The unique identifier that corresponds to the tool call's id field."""

content: list["ContentBlock"] = []
content: list[ContentBlock] = []
"""
A list of content objects representing the tool result.
Defaults to empty list if not provided.
Expand Down Expand Up @@ -1523,7 +1507,7 @@ class CreateMessageRequestParams(RequestParams):
stopSequences: list[str] | None = None
metadata: dict[str, Any] | None = None
"""Optional metadata to pass through to the LLM provider."""
tools: list["Tool"] | None = None
tools: list[Tool] | None = None
"""
Tool definitions for the LLM to use during sampling.
Requires clientCapabilities.sampling.tools to be present.
Expand Down