litellm/scripts/check_mcp_sdk_install.py
Mateo Wang 0a1dbc0fb4
refactor(mcp): drop the experimental label from the MCP server and client paths (#48513)
* refactor(mcp): drop the experimental label from the MCP server and client paths

Move litellm/proxy/_experimental/mcp_server to litellm/proxy/mcp_server and litellm/experimental_mcp_client to litellm/mcp_client, with the mirrored tests moved under tests/unit/proxy/mcp_server and tests/unit/mcp_client. Both old packages stay as shims that warn with DeprecationWarning, re-export the new package's public names and alias every submodule in sys.modules so deep imports keep resolving to the same objects. The OpenAPI docs gate now puts the merge base's enterprise package on PYTHONPATH so its base counts do not mix the checked-out enterprise code with the base litellm tree

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* ci(mcp): keep tests/unit/proxy/_experimental as a sharded root for the shim tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mcp): alias namespace subpackages and bind attributes in the deprecated MCP shims

pkgutil.walk_packages skipped mcp_server/auth because it has no __init__.py, so old imports of litellm.proxy._experimental.mcp_server.auth.* failed, and sys.modules entries alone left litellm.experimental_mcp_client.tools unreachable as an attribute. Walk the package on disk and setattr each alias on its old parent.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-27 17:47:50 +00:00

77 lines
2.6 KiB
Python

import argparse
import importlib
import importlib.metadata
import sys
from typing import Final
MINIMUM_MCP_VERSION: Final[tuple[int, int, int]] = (2, 2, 0)
IMPORTED_MODULES: Final[tuple[str, ...]] = (
"litellm",
"litellm.mcp_client",
"litellm.mcp_client.client",
"litellm.proxy.mcp_server.server",
"litellm.proxy.mcp_server.mcp_server_manager",
"litellm.proxy.mcp_server.rest_endpoints",
)
def _version_tuple(distribution: str) -> tuple[int, ...]:
return tuple(int(part) for part in importlib.metadata.version(distribution).split(".") if part.isdigit())
def main() -> int:
parser: Final = argparse.ArgumentParser()
parser.add_argument("--extra", choices=("mcp", "proxy"), default="proxy")
extra: Final = parser.parse_args().extra
for module_name in IMPORTED_MODULES if extra == "proxy" else IMPORTED_MODULES[:3]:
try:
importlib.import_module(module_name)
except Exception as exc:
sys.stderr.write(f"failed to import {module_name}: {exc}\n")
return 1
mcp_version: Final = _version_tuple("mcp")
if mcp_version < MINIMUM_MCP_VERSION:
sys.stderr.write(f"mcp {importlib.metadata.version('mcp')} below floor 2.2.0\n")
return 1
from mcp_types.version import HANDSHAKE_PROTOCOL_VERSIONS
for required in ("2024-11-05", "2025-06-18"):
if required not in HANDSHAKE_PROTOCOL_VERSIONS:
sys.stderr.write(f"HANDSHAKE_PROTOCOL_VERSIONS missing {required}\n")
return 1
if extra == "proxy":
scope: Final = {
"type": "http",
"method": "POST",
"path": "/mcp",
"headers": [(b"mcp-protocol-version", b"2026-07-28")],
}
mcp_server: Final = sys.modules["litellm.proxy.mcp_server.server"]
if mcp_server.unsupported_protocol_version(scope) != "2026-07-28":
sys.stderr.write("unsupported_protocol_version accepted a modern-only version\n")
return 1
if (
mcp_server.unsupported_protocol_version(dict(scope, headers=[(b"mcp-protocol-version", b"2025-06-18")]))
is not None
):
sys.stderr.write("unsupported_protocol_version rejected a handshake version\n")
return 1
sys.stdout.write(
"python {} mcp {} httpx2 {} pydantic {} litellm {}\n".format(
sys.version.split()[0],
importlib.metadata.version("mcp"),
importlib.metadata.version("httpx2"),
importlib.metadata.version("pydantic"),
importlib.metadata.version("litellm"),
)
)
return 0
if __name__ == "__main__":
sys.exit(main())