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 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
True when result is an input_required interim result, typed or wire-shaped.
Source code in src/mcp-types/mcp_types/methods.py
438 439 440 441 442 | |
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
|
|
KeyError
|
|
ValidationError
|
body fails surface validation. |
Source code in src/mcp-types/mcp_types/methods.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
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]]
|
|
CLIENT_REQUESTS
|
monolith
|
Mapping[str, type[Request[Any, Any]]]
|
|
MONOLITH_REQUESTS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
body fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
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]]
|
|
SERVER_REQUESTS
|
monolith
|
Mapping[str, type[Request[Any, Any]]]
|
|
MONOLITH_REQUESTS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
body fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
531 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 | |
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
|
|
KeyError
|
|
ValidationError
|
body fails surface validation. |
Source code in src/mcp-types/mcp_types/methods.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
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]]
|
|
CLIENT_NOTIFICATIONS
|
monolith
|
Mapping[str, type[Notification[Any, Any]]]
|
|
MONOLITH_NOTIFICATIONS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
body fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |
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]]
|
|
SERVER_NOTIFICATIONS
|
monolith
|
Mapping[str, type[Notification[Any, Any]]]
|
|
MONOLITH_NOTIFICATIONS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
body fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
605 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 | |
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
|
|
KeyError
|
|
ValidationError
|
result fails surface validation. |
Source code in src/mcp-types/mcp_types/methods.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
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
|
|
KeyError
|
|
ValidationError
|
result fails surface validation. |
Source code in src/mcp-types/mcp_types/methods.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Mapping[tuple[str, str], type[BaseModel] | UnionType]
|
|
SERVER_RESULTS
|
monolith
|
Mapping[str, type[Result] | UnionType]
|
|
MONOLITH_RESULTS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
result fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
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
|
|
KeyError
|
|
ValidationError
|
result fails surface validation. |
Source code in src/mcp-types/mcp_types/methods.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Mapping[tuple[str, str], type[BaseModel] | UnionType]
|
|
CLIENT_RESULTS
|
monolith
|
Mapping[str, type[Result] | UnionType]
|
|
MONOLITH_RESULTS
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
KeyError
|
|
ValidationError
|
result fails surface or monolith validation. |
RuntimeError
|
surface matched but |
Source code in src/mcp-types/mcp_types/methods.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |