|
| 1 | +"""Deprecated: the protocol types moved to the standalone `mcp_types` package. |
| 2 | +
|
| 3 | +`import mcp.types` still works in v2 as a compatibility shim, but it emits an |
| 4 | +`MCPDeprecationWarning` and will be removed in v3. Import from `mcp_types` instead: |
| 5 | +
|
| 6 | + from mcp_types import Tool, TextContent |
| 7 | +
|
| 8 | +Field names also changed from camelCase to snake_case (`tool.input_schema`, not |
| 9 | +`tool.inputSchema`), so an import that succeeds through this shim can still fail |
| 10 | +later on attribute access. See the migration guide, "Types and wire format". |
| 11 | +""" |
| 12 | + |
| 13 | +# A wildcard mirror of the mcp_types namespace is the whole point of this shim. |
| 14 | +# pyright: reportWildcardImportFromLibrary=false |
| 15 | + |
| 16 | +import warnings |
| 17 | + |
| 18 | +from mcp_types import * |
| 19 | +from mcp_types import __all__ as __all__ |
| 20 | + |
| 21 | +from mcp.shared.exceptions import MCPDeprecationWarning |
| 22 | + |
| 23 | +warnings.warn( |
| 24 | + "mcp.types is deprecated; import from mcp_types. Fields are now snake_case; see the migration guide.", |
| 25 | + MCPDeprecationWarning, |
| 26 | + stacklevel=2, |
| 27 | +) |
| 28 | + |
| 29 | +# Names v1's mcp.types exposed that no longer exist. A bare "cannot import name" |
| 30 | +# leaves people grepping; naming the replacement finishes the migration step. |
| 31 | +_REMOVED = { |
| 32 | + "Content": "use ContentBlock", |
| 33 | + "ResourceReference": "use ResourceTemplateReference", |
| 34 | + "Cursor": "use str", |
| 35 | + "AnyFunction": "use Callable[..., Any]", |
| 36 | + "MethodT": "it was an internal TypeVar, not public API", |
| 37 | + "RequestParamsT": "it was an internal TypeVar, not public API", |
| 38 | + "NotificationParamsT": "it was an internal TypeVar, not public API", |
| 39 | + "ClientRequestType": "the union is now the bare name ClientRequest", |
| 40 | + "ClientNotificationType": "the union is now the bare name ClientNotification", |
| 41 | + "ClientResultType": "the union is now the bare name ClientResult", |
| 42 | + "ServerRequestType": "the union is now the bare name ServerRequest", |
| 43 | + "ServerNotificationType": "the union is now the bare name ServerNotification", |
| 44 | + "ServerResultType": "the union is now the bare name ServerResult", |
| 45 | + "TaskExecutionMode": "use the string literals directly", |
| 46 | + "TASK_FORBIDDEN": "use the string literal 'forbidden'", |
| 47 | + "TASK_OPTIONAL": "use the string literal 'optional'", |
| 48 | + "TASK_REQUIRED": "use the string literal 'required'", |
| 49 | + "TASK_STATUS_CANCELLED": "use the string literal 'cancelled'; TaskStatus remains", |
| 50 | + "TASK_STATUS_COMPLETED": "use the string literal 'completed'; TaskStatus remains", |
| 51 | + "TASK_STATUS_FAILED": "use the string literal 'failed'; TaskStatus remains", |
| 52 | + "TASK_STATUS_INPUT_REQUIRED": "use the string literal 'input_required'; TaskStatus remains", |
| 53 | + "TASK_STATUS_WORKING": "use the string literal 'working'; TaskStatus remains", |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +def __getattr__(name: str) -> object: |
| 58 | + if (hint := _REMOVED.get(name)) is not None: |
| 59 | + # ImportError, not AttributeError: `from mcp.types import X` swallows an |
| 60 | + # AttributeError raised here and reports a generic "cannot import name", |
| 61 | + # discarding the hint; an ImportError propagates through both the |
| 62 | + # from-import and plain attribute-access paths with the message intact. |
| 63 | + raise ImportError(f"mcp.types.{name} was removed in v2; {hint}. See the migration guide.") |
| 64 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
0 commit comments