Skip to content

[Bug]: Remote streamable-http MCP servers (e.g. GitHub MCP) fail on startup with cancel scope RuntimeError #26700

@renne

Description

@renne

Description

When adding a remote streamable-http MCP server to config.yaml (e.g. GitHub's hosted MCP at https://api.githubcopilot.com/mcp/), LiteLLM crashes during startup with:

RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

This prevents the server from initializing MCP tool discovery and the tools are never registered.

Config

mcp_servers:
  github:
    url: https://api.githubcopilot.com/mcp/
    transport: sse   # also tried: http
    allow_all_keys: true
    headers:
      Authorization: "Bearer os.environ/GITHUB_PAT"

Error (from docker compose logs)

LiteLLM:WARNING: client.py:385 - MCP client list_tools was cancelled
LiteLLM:WARNING: mcp_server_manager.py:1610 - Task cancelled while listing tools from github

File "/usr/lib/python3.13/site-packages/mcp/server/streamable_http_manager.py", line 117, in run
    yield  # Let the application run
    ^^^^^
GeneratorExit

...

RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

Root Cause

This is an upstream bug in the MCP Python SDK. AnyIO requires cancel scopes to be entered and exited in the same task. ClientSessionGroup attempts concurrent teardown of session exit stacks from a different task context, violating this constraint.

Upstream tracking:

Environment

  • LiteLLM image: ghcr.io/berriai/litellm:main-stable
  • Python: 3.13
  • Transport tried: sse, http
  • Remote server: https://api.githubcopilot.com/mcp/

Request

Track upstream PR modelcontextprotocol/python-sdk #2443 and update the mcp SDK dependency once the fix is merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions