chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Support mcp 2.x (Python SDK): pin blocks mcp 2.0.0

Open SiAgentBuild opened this issue 4 months ago • 2 comments

Summary

chainlit currently pins the MCP Python SDK to the 1.x line and cannot be installed alongside mcp 2.0.0 (released 2026-07-28). This issue tracks the breaking changes in mcp 2.0 that affect the backend.

Current constraint

mcp>=1.11.0,<2.0.0 — backend/pyproject.toml:45.

Breaking changes in mcp 2.0 that affect chainlit

All in backend/chainlit/server.py, verified against the installed mcp==2.0.0 SDK:

  1. streamablehttp_client renamed → streamable_http_client.

    • server.py:1306 — from mcp.client.streamable_http import streamablehttp_client. In 2.0 the function is streamable_http_client.
  2. streamable_http_client / sse_client dropped the headers kwarg.

    • server.py:1434-1437 — streamablehttp_client(url=..., headers=mcp_connection.headers). In 2.0 headers is removed; it must be set on an httpx2.AsyncClient passed as http_client=.
    • server.py:1418-1421 — sse_client(url=..., headers=mcp_connection.headers), same change.

Notes

  • The tuple-arity change is already handled: server.py:1442 does read, write = transport[:2], which works for both the old 3-tuple and the new 2-tuple, so no change needed there. server.py:1445-1449 constructs ClientSession without read_timeout_seconds, so the timedelta→float change does not apply. The main work is the import rename and moving headers into an httpx/httpx2 client.
  • Dependency-floor updates. mcp 2.0 requires pydantic>=2.12, anyio>=4.9, typing-extensions>=4.13, and adds required deps opentelemetry-api and mcp-types (exact-pinned to the SDK version); the SDK's HTTP layer moved from httpx/httpx-sse to httpx2>=2.5.0.

Happy to help with a PR if the maintainers are open to it.

SiAgentBuild avatar Jul 31 '26 02:07 SiAgentBuild

We hit this from the downstream side: chainlit is now the only thing in our dependency graph holding mcp below 2.0.

Two data points that might be useful here:

  • claude-agent-sdk relaxed its own mcp<2.0.0 to <3.0.0 in 0.2.140 and now supports 1.x and 2.x side by side. Of the packages we depend on that touch mcp, every other one is floor-only or capped at <3 — this is the last <2.0.0 we're carrying.
  • Verified by resolution rather than by reading metadata: with a whole-graph mcp>=2.0.0 constraint, the resolve fails through chainlit alone, and chainlit==2.11.1 + mcp>=2.0.0 reports the conflict directly. Worth flagging for anyone else testing this — an unpinned chainlit>=1.0.0 resolves "successfully" by walking back to a version predating the mcp dependency, which looks like a pass but means you've lost chainlit.

The analysis above matches what we see, the three changes look small, and we'd be glad to send a PR.

One practical question first: would a release be likely to follow a merge? The last release was 2.11.1 (2026-04-22) while PRs have kept merging, so a merged fix wouldn't reach consumers via PyPI on its own. Knowing whether to expect a release or to plan on pinning a main SHA would help us — and probably others landing on this issue.

qye-inf avatar Aug 19 '26 10:08 qye-inf

I verified the 2.x surface against the actual SDKs (mcp 1.28.1, 1.29.1 and 2.1.1 on Python 3.13) before picking this up, and two of the details above have changed since the issue was written — both in the direction of making this smaller. Posting the findings and the shape I'd propose, in case you'd rather steer it differently.

1. sse_client still accepts headers= and httpx_client_factory= in 2.x.

mcp 2.1.1
sse_client(url, headers=None, timeout=5.0, sse_read_timeout=300.0,
           httpx_client_factory=create_mcp_http_client, auth=None,
           on_session_created=None)

That is identical to 1.29.1 apart from the httpx→httpx2 types, so the SSE call site needs no signature change.

2. streamable_http_client already exists on the current floor.

server.py still imports the deprecated streamablehttp_client, but the new name landed in 1.24.0 — below the mcp>=1.28.1 floor — and its signature is identical across 1.28.1, 1.29.1 and 2.1.1:

streamable_http_client(url, *, http_client: AsyncClient | None = None,
                       terminate_on_close: bool = True)

So one code path covers both major lines: no conditional imports and no version sniffing. The existing NOTE at server.py:1679 is exactly right about what to do on bump.

3. No dependency-floor changes are needed.

Chainlit's constraints are ranges rather than pins, so the resolver satisfies mcp 2.x on its own. Relaxing only the cap resolves to:

mcp==2.1.1  mcp-types==2.1.1  httpx2==2.12.0
pydantic==2.13.4  anyio==4.14.2

pydantic, anyio and starlette resolve to the same versions under mcp<2.0.0 as under mcp>=2.0.0, so nothing needs bumping — httpx-sse drops out, httpx2 and mcp-types come in, and chainlit's own httpx stays alongside httpx2.

The real work is narrower than the dependency list suggests, but it does touch the SSRF guard:

  • http_client= replaces the factory for streamable-http, and ownership flips — streamable_http_client only closes a client it created (if not client_provided:), so a caller-supplied client must be closed by the caller.
  • mcp 2.x dispatches with httpx2 while 1.x dispatches with httpx, so make_mcp_http_client_factory has to build from whichever module the installed SDK actually uses. Otherwise the guard in chainlit/mcp.py (follow_redirects=False plus the per-request check_destination hook) ends up attached to the wrong client type.

Proposed shape, keeping mcp>=1.28.1,<3.0.0 so neither line is dropped:

  • resolve the httpx module from the installed SDK rather than from what happens to be importable, so the guard cannot silently bind to the wrong library;
  • keep make_mcp_http_client_factory for sse_client, and add a single-client helper for streamable_http_client(http_client=...), entered into the existing AsyncExitStack so it is closed;
  • update the regression guards in TestMakeMcpHttpClientFactory — test_streamablehttp_client_accepts_httpx_client_factory_kwarg asserts a parameter that no longer exists in 2.x, so it should assert http_client on streamable_http_client instead;
  • run the backend suite against both 1.29.1 and 2.1.1.

Happy to open a PR on that shape. If you'd prefer 2.x-only, or want the deprecated alias kept for a release, let me know and I'll adjust.

aniketwaghh avatar Aug 27 '26 16:08 aniketwaghh