Skip to content

methods

Per-version method maps and parse/serialize functions for MCP traffic.

This module is supported public API; the mcp_types._v* packages it draws on are internal validators and not for direct import.

Surface maps key (method, version) to per-version wire types (key absence is the version gate; shape validation is per schema era, i.e. 2025-11-25 for every pre-2026 version and 2026-07-28 for 2026). Monolith maps key method to the version-free mcp_types models user code receives.

SERVER_RESULTS module-attribute

SERVER_RESULTS: Final[
    Mapping[tuple[str, str], type[BaseModel] | UnionType]
] = MappingProxyType(
    {
        (
            "completion/complete",
            "2024-11-05",
        ): v2025.CompleteResult,
        (
            "initialize",
            "2024-11-05",
        ): v2025.InitializeResult,
        (
            "logging/setLevel",
            "2024-11-05",
        ): v2025.EmptyResult,
        ("ping", "2024-11-05"): v2025.EmptyResult,
        (
            "prompts/get",
            "2024-11-05",
        ): v2025.GetPromptResult,
        (
            "prompts/list",
            "2024-11-05",
        ): v2025.ListPromptsResult,
        (
            "resources/list",
            "2024-11-05",
        ): v2025.ListResourcesResult,
        (
            "resources/read",
            "2024-11-05",
        ): v2025.ReadResourceResult,
        (
            "resources/subscribe",
            "2024-11-05",
        ): v2025.EmptyResult,
        (
            "resources/templates/list",
            "2024-11-05",
        ): v2025.ListResourceTemplatesResult,
        (
            "resources/unsubscribe",
            "2024-11-05",
        ): v2025.EmptyResult,
        ("tools/call", "2024-11-05"): v2025.CallToolResult,
        ("tools/list", "2024-11-05"): v2025.ListToolsResult,
        (
            "completion/complete",
            "2025-03-26",
        ): v2025.CompleteResult,
        (
            "initialize",
            "2025-03-26",
        ): v2025.InitializeResult,
        (
            "logging/setLevel",
            "2025-03-26",
        ): v2025.EmptyResult,
        ("ping", "2025-03-26"): v2025.EmptyResult,
        (
            "prompts/get",
            "2025-03-26",
        ): v2025.GetPromptResult,
        (
            "prompts/list",
            "2025-03-26",
        ): v2025.ListPromptsResult,
        (
            "resources/list",
            "2025-03-26",
        ): v2025.ListResourcesResult,
        (
            "resources/read",
            "2025-03-26",
        ): v2025.ReadResourceResult,
        (
            "resources/subscribe",
            "2025-03-26",
        ): v2025.EmptyResult,
        (
            "resources/templates/list",
            "2025-03-26",
        ): v2025.ListResourceTemplatesResult,
        (
            "resources/unsubscribe",
            "2025-03-26",
        ): v2025.EmptyResult,
        ("tools/call", "2025-03-26"): v2025.CallToolResult,
        ("tools/list", "2025-03-26"): v2025.ListToolsResult,
        (
            "completion/complete",
            "2025-06-18",
        ): v2025.CompleteResult,
        (
            "initialize",
            "2025-06-18",
        ): v2025.InitializeResult,
        (
            "logging/setLevel",
            "2025-06-18",
        ): v2025.EmptyResult,
        ("ping", "2025-06-18"): v2025.EmptyResult,
        (
            "prompts/get",
            "2025-06-18",
        ): v2025.GetPromptResult,
        (
            "prompts/list",
            "2025-06-18",
        ): v2025.ListPromptsResult,
        (
            "resources/list",
            "2025-06-18",
        ): v2025.ListResourcesResult,
        (
            "resources/read",
            "2025-06-18",
        ): v2025.ReadResourceResult,
        (
            "resources/subscribe",
            "2025-06-18",
        ): v2025.EmptyResult,
        (
            "resources/templates/list",
            "2025-06-18",
        ): v2025.ListResourceTemplatesResult,
        (
            "resources/unsubscribe",
            "2025-06-18",
        ): v2025.EmptyResult,
        ("tools/call", "2025-06-18"): v2025.CallToolResult,
        ("tools/list", "2025-06-18"): v2025.ListToolsResult,
        (
            "completion/complete",
            "2025-11-25",
        ): v2025.CompleteResult,
        (
            "initialize",
            "2025-11-25",
        ): v2025.InitializeResult,
        (
            "logging/setLevel",
            "2025-11-25",
        ): v2025.EmptyResult,
        ("ping", "2025-11-25"): v2025.EmptyResult,
        (
            "prompts/get",
            "2025-11-25",
        ): v2025.GetPromptResult,
        (
            "prompts/list",
            "2025-11-25",
        ): v2025.ListPromptsResult,
        (
            "resources/list",
            "2025-11-25",
        ): v2025.ListResourcesResult,
        (
            "resources/read",
            "2025-11-25",
        ): v2025.ReadResourceResult,
        (
            "resources/subscribe",
            "2025-11-25",
        ): v2025.EmptyResult,
        (
            "resources/templates/list",
            "2025-11-25",
        ): v2025.ListResourceTemplatesResult,
        (
            "resources/unsubscribe",
            "2025-11-25",
        ): v2025.EmptyResult,
        ("tools/call", "2025-11-25"): v2025.CallToolResult,
        ("tools/list", "2025-11-25"): v2025.ListToolsResult,
        (
            "completion/complete",
            "2026-07-28",
        ): v2026.CompleteResult,
        (
            "prompts/get",
            "2026-07-28",
        ): v2026.AnyGetPromptResult,
        (
            "prompts/list",
            "2026-07-28",
        ): v2026.ListPromptsResult,
        (
            "resources/list",
            "2026-07-28",
        ): v2026.ListResourcesResult,
        (
            "resources/read",
            "2026-07-28",
        ): v2026.AnyReadResourceResult,
        (
            "resources/templates/list",
            "2026-07-28",
        ): v2026.ListResourceTemplatesResult,
        (
            "server/discover",
            "2026-07-28",
        ): v2026.DiscoverResult,
        (
            "subscriptions/listen",
            "2026-07-28",
        ): v2026.SubscriptionsListenResult,
        (
            "tools/call",
            "2026-07-28",
        ): v2026.AnyCallToolResult,
        ("tools/list", "2026-07-28"): v2026.ListToolsResult,
    }
)

Results servers send, keyed by the originating client request's (method, version).

CLIENT_RESULTS module-attribute

CLIENT_RESULTS: Final[
    Mapping[tuple[str, str], type[BaseModel] | UnionType]
] = MappingProxyType(
    {
        ("ping", "2024-11-05"): v2025.EmptyResult,
        ("roots/list", "2024-11-05"): v2025.ListRootsResult,
        (
            "sampling/createMessage",
            "2024-11-05",
        ): v2025.CreateMessageResult,
        ("ping", "2025-03-26"): v2025.EmptyResult,
        ("roots/list", "2025-03-26"): v2025.ListRootsResult,
        (
            "sampling/createMessage",
            "2025-03-26",
        ): v2025.CreateMessageResult,
        (
            "elicitation/create",
            "2025-06-18",
        ): v2025.ElicitResult,
        ("ping", "2025-06-18"): v2025.EmptyResult,
        ("roots/list", "2025-06-18"): v2025.ListRootsResult,
        (
            "sampling/createMessage",
            "2025-06-18",
        ): v2025.CreateMessageResult,
        (
            "elicitation/create",
            "2025-11-25",
        ): v2025.ElicitResult,
        ("ping", "2025-11-25"): v2025.EmptyResult,
        ("roots/list", "2025-11-25"): v2025.ListRootsResult,
        (
            "sampling/createMessage",
            "2025-11-25",
        ): v2025.CreateMessageResult,
    }
)

Results clients send, keyed by the originating server request's (method, version).

SPEC_CLIENT_METHODS module-attribute

SPEC_CLIENT_METHODS: Final[frozenset[str]] = frozenset(
    m for m, _ in CLIENT_REQUESTS
)

Spec request methods a client may send (any version); the server-side spec-method discriminator.

SPEC_CLIENT_NOTIFICATION_METHODS module-attribute

SPEC_CLIENT_NOTIFICATION_METHODS: Final[frozenset[str]] = (
    frozenset(m for m, _ in CLIENT_NOTIFICATIONS)
)

Spec notification methods a client may send (any version); the server-side spec-method discriminator.

MONOLITH_REQUESTS module-attribute

MONOLITH_REQUESTS: Final[
    Mapping[str, type[Request[Any, Any]]]
] = MappingProxyType(
    {
        "completion/complete": types.CompleteRequest,
        "elicitation/create": types.ElicitRequest,
        "initialize": types.InitializeRequest,
        "logging/setLevel": types.SetLevelRequest,
        "ping": types.PingRequest,
        "prompts/get": types.GetPromptRequest,
        "prompts/list": types.ListPromptsRequest,
        "resources/list": types.ListResourcesRequest,
        "resources/read": types.ReadResourceRequest,
        "resources/subscribe": types.SubscribeRequest,
        "resources/templates/list": types.ListResourceTemplatesRequest,
        "resources/unsubscribe": types.UnsubscribeRequest,
        "roots/list": types.ListRootsRequest,
        "sampling/createMessage": types.CreateMessageRequest,
        "server/discover": types.DiscoverRequest,
        "subscriptions/listen": types.SubscriptionsListenRequest,
        "tools/call": types.CallToolRequest,
        "tools/list": types.ListToolsRequest,
    }
)

Monolith request model per method, both directions.

MONOLITH_NOTIFICATIONS module-attribute

MONOLITH_NOTIFICATIONS: Final[
    Mapping[str, type[Notification[Any, Any]]]
] = MappingProxyType(
    {
        "notifications/cancelled": types.CancelledNotification,
        "notifications/elicitation/complete": types.ElicitCompleteNotification,
        "notifications/initialized": types.InitializedNotification,
        "notifications/message": types.LoggingMessageNotification,
        "notifications/progress": types.ProgressNotification,
        "notifications/prompts/list_changed": types.PromptListChangedNotification,
        "notifications/resources/list_changed": types.ResourceListChangedNotification,
        "notifications/resources/updated": types.ResourceUpdatedNotification,
        "notifications/roots/list_changed": types.RootsListChangedNotification,
        "notifications/subscriptions/acknowledged": types.SubscriptionsAcknowledgedNotification,
        "notifications/tools/list_changed": types.ToolListChangedNotification,
    }
)

Monolith notification model per method, both directions.

MONOLITH_RESULTS module-attribute

MONOLITH_RESULTS: Final[
    Mapping[str, type[Result] | UnionType]
] = MappingProxyType(
    {
        "completion/complete": types.CompleteResult,
        "elicitation/create": types.ElicitResult,
        "initialize": types.InitializeResult,
        "logging/setLevel": types.EmptyResult,
        "ping": types.EmptyResult,
        "prompts/get": types.GetPromptResult
        | types.InputRequiredResult,
        "prompts/list": types.ListPromptsResult,
        "resources/list": types.ListResourcesResult,
        "resources/read": types.ReadResourceResult
        | types.InputRequiredResult,
        "resources/subscribe": types.EmptyResult,
        "resources/templates/list": types.ListResourceTemplatesResult,
        "resources/unsubscribe": types.EmptyResult,
        "roots/list": types.ListRootsResult,
        "sampling/createMessage": types.CreateMessageResult
        | types.CreateMessageResultWithTools,
        "server/discover": types.DiscoverResult,
        "subscriptions/listen": types.SubscriptionsListenResult,
        "tools/call": types.CallToolResult
        | types.InputRequiredResult,
        "tools/list": types.ListToolsResult,
    }
)

Monolith result model (or two-arm union) per request method.

CacheableMethod module-attribute

CacheableMethod = Literal[
    "prompts/list",
    "resources/list",
    "resources/read",
    "resources/templates/list",
    "server/discover",
    "tools/list",
]

Methods whose results carry ttlMs/cacheScope; hand-written Literal, welded to CACHEABLE_METHODS by tests.

CACHEABLE_METHODS module-attribute

CACHEABLE_METHODS: Final[frozenset[str]] = frozenset(
    method
    for method, row in (MONOLITH_RESULTS.items())
    if any(
        (issubclass(arm, types.CacheableResult))
        for arm in (
            get_args(row)
            if isinstance(row, UnionType)
            else (row,)
        )
    )
)

Runtime mirror of CacheableMethod, derived from MONOLITH_RESULTS.

INPUT_REQUIRED_METHODS module-attribute

INPUT_REQUIRED_METHODS: Final[frozenset[str]] = frozenset(
    method
    for method, row in (MONOLITH_RESULTS.items())
    if any(
        (issubclass(arm, types.InputRequiredResult))
        for arm in (
            get_args(row)
            if isinstance(row, UnionType)
            else (row,)
        )
    )
)

Methods whose results may be InputRequiredResult, derived from MONOLITH_RESULTS.

is_input_required

is_input_required(
    result: object,
) -> TypeGuard[InputRequiredResult | dict[str, Any]]

True when result is an input_required interim result, typed or wire-shaped.

Source code in src/mcp-types/mcp_types/methods.py
439
440
441
442
443
def is_input_required(result: object) -> TypeGuard[types.InputRequiredResult | dict[str, Any]]:
    """True when `result` is an `input_required` interim result, typed or wire-shaped."""
    if isinstance(result, types.InputRequiredResult):
        return True
    return isinstance(result, Mapping) and cast("Mapping[str, Any]", result).get("resultType") == "input_required"

validate_client_request

validate_client_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = CLIENT_REQUESTS
) -> None

Validate a client request against surface only.

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface (the version gate).

ValidationError

body fails surface validation.

Source code in src/mcp-types/mcp_types/methods.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
def validate_client_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = CLIENT_REQUESTS,
) -> None:
    """Validate a client request against `surface` only.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface` (the version gate).
        pydantic.ValidationError: body fails surface validation.
    """
    _check_known_version(version)
    surface[(method, version)].model_validate({**_REQUEST_STUB, **_body(method, params)}, by_name=False)

parse_client_request

parse_client_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = CLIENT_REQUESTS,
    monolith: Mapping[
        str, type[Request[Any, Any]]
    ] = MONOLITH_REQUESTS
) -> Request[Any, Any]

Validate a client request against surface, then parse and return its monolith model.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel]]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

CLIENT_REQUESTS
monolith Mapping[str, type[Request[Any, Any]]]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_REQUESTS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface (the version gate).

ValidationError

body fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
def parse_client_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = CLIENT_REQUESTS,
    monolith: Mapping[str, type[types.Request[Any, Any]]] = MONOLITH_REQUESTS,
) -> types.Request[Any, Any]:
    """Validate a client request against `surface`, then parse and return its `monolith` model.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface` (the version gate).
        pydantic.ValidationError: body fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    validate_client_request(method, version, params, surface=surface)
    return _monolith_row(monolith, method).model_validate(_body(method, params), by_name=False)

parse_server_request

parse_server_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = SERVER_REQUESTS,
    monolith: Mapping[
        str, type[Request[Any, Any]]
    ] = MONOLITH_REQUESTS
) -> Request[Any, Any]

Validate a server request against surface, then parse and return its monolith model.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel]]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

SERVER_REQUESTS
monolith Mapping[str, type[Request[Any, Any]]]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_REQUESTS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface (the version gate).

ValidationError

body fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
def parse_server_request(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = SERVER_REQUESTS,
    monolith: Mapping[str, type[types.Request[Any, Any]]] = MONOLITH_REQUESTS,
) -> types.Request[Any, Any]:
    """Validate a server request against `surface`, then parse and return its `monolith` model.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface` (the version gate).
        pydantic.ValidationError: body fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    _check_known_version(version)
    surface_type = surface[(method, version)]
    surface_type.model_validate({**_REQUEST_STUB, **_body(method, params)}, by_name=False)
    return _monolith_row(monolith, method).model_validate(_body(method, params), by_name=False)

validate_client_notification

validate_client_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = CLIENT_NOTIFICATIONS
) -> None

Validate a client notification against surface only.

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

body fails surface validation.

Source code in src/mcp-types/mcp_types/methods.py
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
def validate_client_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = CLIENT_NOTIFICATIONS,
) -> None:
    """Validate a client notification against `surface` only.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: body fails surface validation.
    """
    _check_known_version(version)
    surface[(method, version)].model_validate({**_NOTIFICATION_STUB, **_body(method, params)}, by_name=False)

parse_client_notification

parse_client_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = CLIENT_NOTIFICATIONS,
    monolith: Mapping[
        str, type[Notification[Any, Any]]
    ] = MONOLITH_NOTIFICATIONS
) -> Notification[Any, Any]

Validate a client notification against surface, then parse and return its monolith model.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel]]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

CLIENT_NOTIFICATIONS
monolith Mapping[str, type[Notification[Any, Any]]]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_NOTIFICATIONS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

body fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
def parse_client_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = CLIENT_NOTIFICATIONS,
    monolith: Mapping[str, type[types.Notification[Any, Any]]] = MONOLITH_NOTIFICATIONS,
) -> types.Notification[Any, Any]:
    """Validate a client notification against `surface`, then parse and return its `monolith` model.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: body fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    validate_client_notification(method, version, params, surface=surface)
    return _monolith_row(monolith, method).model_validate(_body(method, params), by_name=False)

parse_server_notification

parse_server_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel]
    ] = SERVER_NOTIFICATIONS,
    monolith: Mapping[
        str, type[Notification[Any, Any]]
    ] = MONOLITH_NOTIFICATIONS
) -> Notification[Any, Any]

Validate a server notification against surface, then parse and return its monolith model.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel]]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

SERVER_NOTIFICATIONS
monolith Mapping[str, type[Notification[Any, Any]]]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_NOTIFICATIONS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

body fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
def parse_server_notification(
    method: str,
    version: str,
    params: Mapping[str, Any] | None,
    *,
    surface: Mapping[tuple[str, str], type[BaseModel]] = SERVER_NOTIFICATIONS,
    monolith: Mapping[str, type[types.Notification[Any, Any]]] = MONOLITH_NOTIFICATIONS,
) -> types.Notification[Any, Any]:
    """Validate a server notification against `surface`, then parse and return its `monolith` model.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: body fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    _check_known_version(version)
    surface_type = surface[(method, version)]
    surface_type.model_validate({**_NOTIFICATION_STUB, **_body(method, params)}, by_name=False)
    return _monolith_row(monolith, method).model_validate(_body(method, params), by_name=False)

strip_era_foreign_fields

strip_era_foreign_fields(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = SERVER_RESULTS
) -> Mapping[str, Any]

Drop a later revision's fields from a version-scoped result.

The version-free mcp_types models carry every revision's fields, so parsing raw wire data into them lets a field of a revision newer than version (and that revision's constraints) act on a session that never negotiated it. This removes exactly those keys: the ones a newer surface for method declares but version's surface does not. Every other key passes through untouched, so payloads the surface only gates (extension result claims, open _meta) are unaffected, and on a session speaking the newest revision the set is empty. Returns data itself when nothing is stripped; an unknown (method, version) also returns data unchanged.

Source code in src/mcp-types/mcp_types/methods.py
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
def strip_era_foreign_fields(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = SERVER_RESULTS,
) -> Mapping[str, Any]:
    """Drop a later revision's fields from a `version`-scoped result.

    The version-free `mcp_types` models carry every revision's fields, so
    parsing raw wire data into them lets a field of a revision newer than
    `version` (and that revision's constraints) act on a session that never
    negotiated it. This removes exactly those keys: the ones a newer surface
    for `method` declares but `version`'s surface does not. Every other key
    passes through untouched, so payloads the surface only gates (extension
    result claims, open `_meta`) are unaffected, and on a session speaking the
    newest revision the set is empty. Returns `data` itself when nothing is
    stripped; an unknown `(method, version)` also returns `data` unchanged.
    """
    if version not in KNOWN_PROTOCOL_VERSIONS or (method, version) not in surface:
        return data
    foreign = _later_revision_fields(method, version, surface)
    if foreign.isdisjoint(data):
        return data
    return {key: value for key, value in data.items() if key not in foreign}

serialize_server_result

serialize_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = SERVER_RESULTS
) -> dict[str, Any]

Validate data against surface and return its surface-shaped dump.

The surface model carries extra="ignore", so fields not in version's schema are dropped from the returned dict.

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

result fails surface validation.

Source code in src/mcp-types/mcp_types/methods.py
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
def serialize_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = SERVER_RESULTS,
) -> dict[str, Any]:
    """Validate `data` against `surface` and return its surface-shaped dump.

    The surface model carries `extra="ignore"`, so fields not in `version`'s
    schema are dropped from the returned dict.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: result fails surface validation.
    """
    _check_known_version(version)
    adapter = _adapter(surface[(method, version)])
    return adapter.dump_python(
        adapter.validate_python(data, by_name=False), by_alias=True, mode="json", exclude_none=True
    )

validate_server_result

validate_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = SERVER_RESULTS
) -> None

Validate a server result against surface only.

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

result fails surface validation.

Source code in src/mcp-types/mcp_types/methods.py
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
def validate_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = SERVER_RESULTS,
) -> None:
    """Validate a server result against `surface` only.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: result fails surface validation.
    """
    serialize_server_result(method, version, data, surface=surface)

parse_server_result

parse_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = SERVER_RESULTS,
    monolith: Mapping[
        str, type[Result] | UnionType
    ] = MONOLITH_RESULTS
) -> Result

Validate a server result against surface, then parse and return its monolith model.

Cross-era fields (see strip_era_foreign_fields) are removed before the monolith parse, so a later revision's field cannot reach the version-free model on a session that did not negotiate it.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel] | UnionType]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

SERVER_RESULTS
monolith Mapping[str, type[Result] | UnionType]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_RESULTS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

result fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
def parse_server_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = SERVER_RESULTS,
    monolith: Mapping[str, type[types.Result] | UnionType] = MONOLITH_RESULTS,
) -> types.Result:
    """Validate a server result against `surface`, then parse and return its `monolith` model.

    Cross-era fields (see `strip_era_foreign_fields`) are removed before the
    monolith parse, so a later revision's field cannot reach the version-free
    model on a session that did not negotiate it.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: result fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    validate_server_result(method, version, data, surface=surface)
    payload = strip_era_foreign_fields(method, version, data, surface=surface)
    result: types.Result = _adapter(_monolith_row(monolith, method)).validate_python(payload, by_name=False)
    return result

validate_client_result

validate_client_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = CLIENT_RESULTS
) -> None

Validate a client result against surface only.

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

result fails surface validation.

Source code in src/mcp-types/mcp_types/methods.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
def validate_client_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = CLIENT_RESULTS,
) -> None:
    """Validate a client result against `surface` only.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: result fails surface validation.
    """
    _check_known_version(version)
    _adapter(surface[(method, version)]).validate_python(data, by_name=False)

parse_client_result

parse_client_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[
        tuple[str, str], type[BaseModel] | UnionType
    ] = CLIENT_RESULTS,
    monolith: Mapping[
        str, type[Result] | UnionType
    ] = MONOLITH_RESULTS
) -> Result

Validate a client result against surface, then parse and return its monolith model.

Cross-era fields (see strip_era_foreign_fields) are removed before the monolith parse, so a later revision's field cannot reach the version-free model on a session that did not negotiate it.

Parameters:

Name Type Description Default
surface Mapping[tuple[str, str], type[BaseModel] | UnionType]

(method, version) to wire-type map; the version-gate lookup and (per-schema-era) shape check run against this. Pass an extended map to admit custom methods.

CLIENT_RESULTS
monolith Mapping[str, type[Result] | UnionType]

method to version-free model map; the returned instance is parsed from this row. Must cover every method surface admits.

MONOLITH_RESULTS

Raises:

Type Description
ValueError

version is not a known protocol version.

KeyError

(method, version) is not in surface.

ValidationError

result fails surface or monolith validation.

RuntimeError

surface matched but method has no monolith row.

Source code in src/mcp-types/mcp_types/methods.py
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
def parse_client_result(
    method: str,
    version: str,
    data: Mapping[str, Any],
    *,
    surface: Mapping[tuple[str, str], type[BaseModel] | UnionType] = CLIENT_RESULTS,
    monolith: Mapping[str, type[types.Result] | UnionType] = MONOLITH_RESULTS,
) -> types.Result:
    """Validate a client result against `surface`, then parse and return its `monolith` model.

    Cross-era fields (see `strip_era_foreign_fields`) are removed before the
    monolith parse, so a later revision's field cannot reach the version-free
    model on a session that did not negotiate it.

    Args:
        surface: `(method, version)` to wire-type map; the version-gate lookup
            and (per-schema-era) shape check run against this. Pass an extended
            map to admit custom methods.
        monolith: `method` to version-free model map; the returned instance is
            parsed from this row. Must cover every method `surface` admits.

    Raises:
        ValueError: `version` is not a known protocol version.
        KeyError: `(method, version)` is not in `surface`.
        pydantic.ValidationError: result fails surface or monolith validation.
        RuntimeError: surface matched but `method` has no monolith row.
    """
    validate_client_result(method, version, data, surface=surface)
    payload = strip_era_foreign_fields(method, version, data, surface=surface)
    result: types.Result = _adapter(_monolith_row(monolith, method)).validate_python(payload, by_name=False)
    return result