Skip to content

fix(mcp): preserve source_url in GET /v1/mcp/server list responses - #29249

Merged
mateo-berri merged 3 commits into
litellm_internal_stagingfrom
litellm_get_mcp_url
May 30, 2026
Merged

fix(mcp): preserve source_url in GET /v1/mcp/server list responses#29249
mateo-berri merged 3 commits into
litellm_internal_stagingfrom
litellm_get_mcp_url

Conversation

@shivamrawat1

@shivamrawat1 shivamrawat1 commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Resolves LIT-3425

Description
source_url was saved correctly when creating MCP servers, but GET /v1/mcp/server always returned "source_url": null. The single-server endpoint (GET /v1/mcp/server/{id}) worked because it reads directly from the database.

This PR threads source_url through the in-memory registry roundtrip used by the list endpoint.

Cause
The list endpoint builds its response from the in-memory MCP registry via:

LiteLLM_MCPServerTable → MCPServer → LiteLLM_MCPServerTable

source_url existed on the DB/API model but was never added to the runtime MCPServer model, so it was dropped when loading servers into the registry and when rebuilding list responses in _build_mcp_server_table().

Fix
Add source_url to the runtime MCPServer model
Map source_url in build_mcp_server_from_table() when loading from DB
Map source_url in _build_mcp_server_table() when building list responses
Add regression test: test_round_trip_source_url_preserved

Before:
Screenshot 2026-05-28 at 7 27 09 PM

After:
Screenshot 2026-05-28 at 7 23 45 PM

The list endpoint builds responses from the in-memory registry, but
source_url was dropped during the DB-to-registry roundtrip even though
GET /v1/mcp/server/{id} returned it correctly from the database.

Co-authored-by: Cursor <cursoragent@cursor.com>
@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes GET /v1/mcp/server always returning "source_url": null by threading the field through the in-memory registry round-trip that the list endpoint relies on, while leaving the single-server GET /v1/mcp/server/{id} path (which reads directly from the DB) untouched.

  • Adds source_url: Optional[str] = None to the runtime MCPServer model so it survives the LiteLLM_MCPServerTable → MCPServer → LiteLLM_MCPServerTable conversion chain.
  • Maps source_url in both build_mcp_server_from_table() (DB → registry load) and _build_mcp_server_table() (registry → list response), mirroring the pattern used by neighboring fields like byok_api_key_help_url.
  • Adds a focused in-memory regression test (test_round_trip_source_url_preserved) that exercises the full round-trip without real network calls.

Confidence Score: 5/5

Safe to merge — the change is a minimal, isolated field propagation fix with no side effects on other code paths.

All three touch points (type model, DB-to-registry loader, registry-to-response builder) are updated consistently, matching the pattern of every other field in those same conversion functions. The regression test covers the exact round-trip that was broken and runs entirely in-memory.

No files require special attention.

Important Files Changed

Filename Overview
litellm/types/mcp_server/mcp_server_manager.py Adds source_url: Optional[str] = None to the runtime MCPServer model, consistent with placement in _types.py.
litellm/proxy/_experimental/mcp_server/mcp_server_manager.py Threads source_url through both conversion paths: build_mcp_server_from_table() (DB → registry) and _build_mcp_server_table() (registry → list response). Fix is minimal and targeted.
tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py Adds test_round_trip_source_url_preserved — a pure in-memory regression test covering the full LiteLLM_MCPServerTable → MCPServer → LiteLLM_MCPServerTable round-trip with no real network calls.

Reviews (1): Last reviewed commit: "fix(mcp): preserve source_url in GET /v1..." | Re-trigger Greptile

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

shivamrawat1 and others added 2 commits May 30, 2026 10:12
MagicMock auto-creates source_url as a mock object, which fails MCPServer
Pydantic validation after source_url was wired through build_mcp_server_from_table.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mateo-berri
mateo-berri enabled auto-merge (squash) May 30, 2026 19:01

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks!

@mateo-berri
mateo-berri merged commit ace3c65 into litellm_internal_staging May 30, 2026
110 of 118 checks passed
@mateo-berri
mateo-berri deleted the litellm_get_mcp_url branch May 30, 2026 19:01
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…erriAI#29249)

* fix(mcp): preserve source_url in GET /v1/mcp/server list responses

The list endpoint builds responses from the in-memory registry, but
source_url was dropped during the DB-to-registry roundtrip even though
GET /v1/mcp/server/{id} returned it correctly from the database.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(tests/mcp): set source_url on MagicMock table records

MagicMock auto-creates source_url as a mock object, which fails MCPServer
Pydantic validation after source_url was wired through build_mcp_server_from_table.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants