mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
fix(mcp): upgrade to MCP SDK 2.3.0 and raise the per-event SSE size cap
MCP SDK 2.x reads Streamable HTTP responses through httpx2's SSE parser, which rejects any single event over 1 MiB, so a large tools/call result failed with 'SSE stream ended without a response'. mcp 2.3.0 exposes max_sse_event_size, and MCPClient now passes a 64 MiB default, configurable with LITELLM_MCP_MAX_SSE_EVENT_SIZE_BYTES Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
aa32e4cc88
commit
828c770857
7 changed files with 51 additions and 20 deletions
|
|
@ -239,6 +239,7 @@ MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS: Final = get_env_int("MCP_PER_USER_TOKE
|
|||
|
||||
# MCP timeout defaults (seconds). Override via env vars for slow/custom MCP servers.
|
||||
MCP_CLIENT_TIMEOUT: Final = get_env_float("LITELLM_MCP_CLIENT_TIMEOUT", 60.0)
|
||||
MCP_MAX_SSE_EVENT_SIZE_BYTES: Final = get_env_int("LITELLM_MCP_MAX_SSE_EVENT_SIZE_BYTES", 64 * 1024 * 1024)
|
||||
MCP_TOOL_LISTING_TIMEOUT: Final = get_env_float("LITELLM_MCP_TOOL_LISTING_TIMEOUT", 30.0)
|
||||
MCP_METADATA_TIMEOUT: Final = get_env_float("LITELLM_MCP_METADATA_TIMEOUT", 10.0)
|
||||
MCP_HEALTH_CHECK_TIMEOUT: Final = get_env_float("LITELLM_MCP_HEALTH_CHECK_TIMEOUT", 10.0)
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ from pydantic import AnyUrl, TypeAdapter
|
|||
from litellm._logging import verbose_logger
|
||||
from litellm.constants import (
|
||||
MCP_CLIENT_TIMEOUT,
|
||||
MCP_MAX_SSE_EVENT_SIZE_BYTES,
|
||||
MCP_NPM_CACHE_DIR,
|
||||
MCP_TOOL_LISTING_MAX_PAGES,
|
||||
MCP_TOOL_LISTING_TIMEOUT,
|
||||
|
|
@ -631,6 +632,7 @@ class MCPClient:
|
|||
transport_ctx: Final = streamable_http_client(
|
||||
url=self.server_url,
|
||||
http_client=http_client,
|
||||
max_sse_event_size=MCP_MAX_SSE_EVENT_SIZE_BYTES,
|
||||
)
|
||||
return transport_ctx, http_client
|
||||
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ proxy = [
|
|||
"boto3>=1.43.1,<2.0",
|
||||
"azure-identity>=1.25.2,<2.0",
|
||||
"azure-storage-blob>=12.28.0,<13.0",
|
||||
"mcp>=2.2.0,<3",
|
||||
"httpx2>=2.5.0,<3",
|
||||
"mcp>=2.3.0,<3",
|
||||
"httpx2>=2.10.0,<3",
|
||||
"pydantic>=2.12.0,<3",
|
||||
"litellm-proxy-extras==0.4.109",
|
||||
"litellm-enterprise==0.1.77",
|
||||
|
|
@ -123,7 +123,7 @@ utils = [
|
|||
"numpydoc>=1.8.0,<2.0",
|
||||
]
|
||||
caching = ["diskcache>=5.6.3,<6.0"]
|
||||
mcp = ["mcp>=2.2.0,<3", "httpx2>=2.5.0,<3", "pydantic>=2.12.0,<3"]
|
||||
mcp = ["mcp>=2.3.0,<3", "httpx2>=2.10.0,<3", "pydantic>=2.12.0,<3"]
|
||||
# Driver for the MongoDB Atlas vector store; Atlas Vector Search has no HTTP query API.
|
||||
# The floor is 4.9 because that is the release AsyncMongoClient landed in.
|
||||
# SAML SSO for the admin UI. python3-saml pulls in xmlsec/lxml, whose wheels
|
||||
|
|
@ -241,7 +241,7 @@ e2e-dev = [
|
|||
"locust==2.45.0",
|
||||
"anthropic==0.84.0",
|
||||
"psutil==7.2.2",
|
||||
"mcp>=2.2.0,<3",
|
||||
"mcp>=2.3.0,<3",
|
||||
]
|
||||
admin-mcp = [
|
||||
"litellm-admin-mcp @ https://github.com/BerriAI/liteadmin-mcp/archive/d35ec9c19c117d4c50cc1eccf6ce1296aac25a1a.tar.gz#sha256=86b930f6706fb2da10d53d1798ee7fd14e44fb0afdef0da122cf0e6bb88fa2c3 ; python_version >= '3.12'",
|
||||
|
|
@ -300,7 +300,7 @@ healthcheck = [
|
|||
benchmarks = [
|
||||
"pytest==9.0.3",
|
||||
"pytest-codspeed==4.3.0",
|
||||
"mcp>=2.2.0,<3",
|
||||
"mcp>=2.3.0,<3",
|
||||
"a2a-sdk==1.1.0",
|
||||
]
|
||||
|
||||
|
|
@ -359,6 +359,8 @@ override-dependencies = [
|
|||
# a2a-sdk 1.x requires packaging>=24.0; lunary 1.4.x still caps at <24.0.
|
||||
"packaging>=24.0",
|
||||
"cryptography>=50.0.0,<51.0",
|
||||
# litellm-admin-mcp pins mcp==2.2.0, which lacks max_sse_event_size
|
||||
"mcp>=2.3.0,<3",
|
||||
]
|
||||
default-groups = ["dev"]
|
||||
required-version = ">=0.10.9"
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ class ScriptedTool:
|
|||
respond: Callable[[JsonRpc], Reply | JsonRpc]
|
||||
description: str | Callable[[Mapping[str, str]], str] | None = None
|
||||
input_schema: JsonRpc = field(default_factory=lambda: {"type": "object"})
|
||||
event_stream: bool = False
|
||||
|
||||
def listing(self, headers: Mapping[str, str]) -> JsonRpc:
|
||||
described: Final = self.description(headers) if callable(self.description) else self.description
|
||||
|
|
@ -334,7 +335,10 @@ def scripted_peer(*tools: ScriptedTool) -> Iterator[McpPeer]:
|
|||
if tool is None:
|
||||
return jsonrpc_error(identity, -32602, "unknown tool")
|
||||
produced: Final = tool.respond(body["params"])
|
||||
return produced if isinstance(produced, Reply) else jsonrpc_reply(identity, produced)
|
||||
reply: Final = produced if isinstance(produced, Reply) else jsonrpc_reply(identity, produced)
|
||||
if not tool.event_stream:
|
||||
return reply
|
||||
return Reply(content_type="text/event-stream", body=b"event: message\ndata: " + reply.body + b"\n\n")
|
||||
|
||||
with wire_server(provider) as wire:
|
||||
yield McpPeer(wire.url + "/mcp", observed)
|
||||
|
|
|
|||
|
|
@ -17,12 +17,17 @@ from integration._support.mcp import (
|
|||
McpCaller,
|
||||
Outcome,
|
||||
PeerKind,
|
||||
ScriptedTool,
|
||||
_outcome_from_rpc,
|
||||
_parse_rpc_body,
|
||||
call_tool,
|
||||
listed_tools,
|
||||
mcp_peer,
|
||||
official_client_outcomes,
|
||||
peer_of,
|
||||
register_mcp,
|
||||
scripted_peer,
|
||||
text_result,
|
||||
tool_calls,
|
||||
)
|
||||
from integration._support.mcp_grants import create_toolset
|
||||
|
|
@ -817,3 +822,19 @@ def test_sdk_progress_and_cancellation_reach_upstream_without_losing_session(
|
|||
),
|
||||
) as gateway:
|
||||
asyncio.run(exercise(gateway))
|
||||
|
||||
|
||||
def test_tool_result_larger_than_one_mib_in_a_single_sse_event_reaches_the_caller(gateway: Gateway) -> None:
|
||||
payload: Final = "x" * (3 * 1024 * 1024)
|
||||
tool: Final = ScriptedTool("dump", lambda _: text_result(payload), event_stream=True)
|
||||
|
||||
with scripted_peer(tool) as peer, gateway.scenario() as scenario:
|
||||
alias: Final = "bigsse" + uuid.uuid4().hex[:8]
|
||||
identity: Final = register_mcp(scenario, peer, alias)
|
||||
key: Final = scenario.key(object_permission={"mcp_servers": [identity]})
|
||||
name: Final = next(full for full in listed_tools(gateway, key, identity) if full.endswith("dump"))
|
||||
response: Final = call_tool(gateway, key, identity, name, {})
|
||||
assert response.status_code == 200, response.text[:500]
|
||||
body: Final = response.json()
|
||||
assert body["isError"] is False, response.text[:500]
|
||||
assert body["content"][0]["text"] == payload
|
||||
|
|
|
|||
|
|
@ -1503,8 +1503,8 @@ def test_mcp_extra_matches_proxy_extra_and_supports_streamable_http():
|
|||
}
|
||||
|
||||
specifier: Final = Requirement(mcp_extra["mcp"]).specifier
|
||||
assert not specifier.contains("1.28.1")
|
||||
assert specifier.contains("2.2.0")
|
||||
assert not specifier.contains("2.2.0")
|
||||
assert specifier.contains("2.3.0")
|
||||
with (pyproject_path.parent / "uv.lock").open("rb") as f:
|
||||
locked = tomllib.load(f)
|
||||
mcp_versions: Final = [package["version"] for package in locked["package"] if package["name"] == "mcp"]
|
||||
|
|
|
|||
25
uv.lock
generated
25
uv.lock
generated
|
|
@ -29,6 +29,7 @@ constraints = [
|
|||
]
|
||||
overrides = [
|
||||
{ name = "cryptography", specifier = ">=50.0.0,<51.0" },
|
||||
{ name = "mcp", specifier = ">=2.3.0,<3" },
|
||||
{ name = "packaging", specifier = ">=24.0" },
|
||||
]
|
||||
|
||||
|
|
@ -4797,8 +4798,8 @@ requires-dist = [
|
|||
{ name = "gunicorn", marker = "extra == 'proxy'", specifier = ">=23.0.0,<24.0" },
|
||||
{ name = "hiredis", marker = "extra == 'proxy'", specifier = ">=3.0.0,<4.0" },
|
||||
{ name = "httpx", extras = ["http2"], specifier = ">=0.28.0,<1.0" },
|
||||
{ name = "httpx2", marker = "extra == 'mcp'", specifier = ">=2.5.0,<3" },
|
||||
{ name = "httpx2", marker = "extra == 'proxy'", specifier = ">=2.5.0,<3" },
|
||||
{ name = "httpx2", marker = "extra == 'mcp'", specifier = ">=2.10.0,<3" },
|
||||
{ name = "httpx2", marker = "extra == 'proxy'", specifier = ">=2.10.0,<3" },
|
||||
{ name = "huggingface-hub", specifier = ">=0.34.0,<2.0" },
|
||||
{ name = "importlib-metadata", specifier = ">=8.0.0,<9.0" },
|
||||
{ name = "inquirerpy", marker = "extra == 'cli'", specifier = ">=0.3.4,<1.0" },
|
||||
|
|
@ -4811,8 +4812,8 @@ requires-dist = [
|
|||
{ name = "litellm-proxy-extras", marker = "extra == 'proxy'", editable = "litellm-proxy-extras" },
|
||||
{ name = "llm-sandbox", marker = "extra == 'proxy-runtime'", specifier = ">=0.3.39,<1.0" },
|
||||
{ name = "mangum", marker = "extra == 'proxy-runtime'", specifier = ">=0.17.0,<1.0" },
|
||||
{ name = "mcp", marker = "extra == 'mcp'", specifier = ">=2.2.0,<3" },
|
||||
{ name = "mcp", marker = "extra == 'proxy'", specifier = ">=2.2.0,<3" },
|
||||
{ name = "mcp", marker = "extra == 'mcp'", specifier = ">=2.3.0,<3" },
|
||||
{ name = "mcp", marker = "extra == 'proxy'", specifier = ">=2.3.0,<3" },
|
||||
{ name = "mlflow", marker = "extra == 'mlflow'", specifier = ">=3.11.1,<4.0" },
|
||||
{ name = "numpy", marker = "extra == 'stt-nvidia-riva'", specifier = ">=1.26.0" },
|
||||
{ name = "numpydoc", marker = "extra == 'utils'", specifier = ">=1.8.0,<2.0" },
|
||||
|
|
@ -4872,7 +4873,7 @@ provides-extras = ["proxy", "cli", "extra-proxy", "utils", "caching", "mcp", "sa
|
|||
admin-mcp = [{ name = "litellm-admin-mcp", marker = "python_full_version >= '3.12'", url = "https://github.com/BerriAI/liteadmin-mcp/archive/d35ec9c19c117d4c50cc1eccf6ce1296aac25a1a.tar.gz" }]
|
||||
benchmarks = [
|
||||
{ name = "a2a-sdk", specifier = "==1.1.0" },
|
||||
{ name = "mcp", specifier = ">=2.2.0,<3" },
|
||||
{ name = "mcp", specifier = ">=2.3.0,<3" },
|
||||
{ name = "pytest", specifier = "==9.0.3" },
|
||||
{ name = "pytest-codspeed", specifier = "==4.3.0" },
|
||||
]
|
||||
|
|
@ -4950,7 +4951,7 @@ dev = [
|
|||
e2e-dev = [
|
||||
{ name = "anthropic", specifier = "==0.84.0" },
|
||||
{ name = "locust", specifier = "==2.45.0" },
|
||||
{ name = "mcp", specifier = ">=2.2.0,<3" },
|
||||
{ name = "mcp", specifier = ">=2.3.0,<3" },
|
||||
{ name = "playwright", specifier = "==1.61.0" },
|
||||
{ name = "psutil", specifier = "==7.2.2" },
|
||||
{ name = "websockets", specifier = ">=15.0.1,<16.0" },
|
||||
|
|
@ -5464,7 +5465,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "mcp"
|
||||
version = "2.2.0"
|
||||
version = "2.3.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "anyio" },
|
||||
|
|
@ -5482,22 +5483,22 @@ dependencies = [
|
|||
{ name = "typing-inspection" },
|
||||
{ name = "uvicorn", marker = "sys_platform != 'emscripten'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/76/31/ac54fb0fdd5b37de704486e288bba4fbbb463f24cfcfedbede407b854513/mcp-2.2.0.tar.gz", hash = "sha256:2dc37ecb1974becdcebdbf7561e7c15a07dbbf20ba21ba16c3593b3038b3afbd", size = 4084129, upload-time = "2026-09-07T16:06:23.439Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/9d/8d/e0d339616f4810e9051d4aba6887afab289ab1f81875fe908b606cdfd0e3/mcp-2.3.0.tar.gz", hash = "sha256:8b147a50441cf059dc88c684e0aeed3687f0aa0f39c6cde7b90330effd2b34d8", size = 4171955, upload-time = "2026-10-02T22:06:56.091Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/1b/ff/8e7eade68b8a28f7da0ed1085544341b51f9c935dbf6b95c76b7edfea6a0/mcp-2.2.0-py3-none-any.whl", hash = "sha256:bde982589473a060ae145e3406e9a5333fe538c97229ba841f5a7f92be004f81", size = 365656, upload-time = "2026-09-07T16:06:19.711Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/20/d7/4a2878f128df729db3ca04e71bfce26405cc2e0c9ebe19c592feeb4c61b9/mcp-2.3.0-py3-none-any.whl", hash = "sha256:dd0c44c089d16453e8ae31a3877a0054d7a2314caaa81f5e0541b9b1734b2377", size = 368664, upload-time = "2026-10-02T22:06:52.119Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mcp-types"
|
||||
version = "2.2.0"
|
||||
version = "2.3.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pydantic" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ae/91/762d7755d971aff8a28d75f7961656148edf27875c8026e6385aaab08ae7/mcp_types-2.2.0.tar.gz", hash = "sha256:d3ed53703ddd10d9c6399f29d322bb66f3f67ab41348ac8556ba23e07fedefad", size = 65892, upload-time = "2026-09-07T16:06:25.187Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/9e/2d/7c251e34207f6c51000312fc8839111ac45cfe02023f90b44e7f1051dd8e/mcp_types-2.3.0.tar.gz", hash = "sha256:d1e46549edb35ee19a94940fcee6d1addd7e589ab7ea92dda83f5d84781fc362", size = 65898, upload-time = "2026-10-02T22:06:57.863Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/8f/d7/6ffba5d8cd5dd9b8a19478875c50e04945314ba5074e84d749283f27f62d/mcp_types-2.2.0-py3-none-any.whl", hash = "sha256:ea476b73ee86709ab5abc9452385ed36cc05907e582355622e294595c9a04f13", size = 69106, upload-time = "2026-09-07T16:06:21.461Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ce/48/32583066b155bb5d4507e7887dc88ee23118cc4de8e2a12870c49719e2a8/mcp_types-2.3.0-py3-none-any.whl", hash = "sha256:968efdbdaedfab06adae40d378a34395f1090c5921d4be3c9cde283aaf76d91d", size = 69108, upload-time = "2026-10-02T22:06:54.099Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue