Skip to content

Conversation

uc4w6c
Copy link
Contributor

@uc4w6c uc4w6c commented Oct 3, 2025

Title

Feat/mcp tools list debug improvement

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
✅ Test

Changes

Previously, errors in the mcp /tools/list call were ignored.
With this change, errors are now raised and returned as error messages, making it easier to identify the root cause of MCP connection errors.

https://www.loom.com/share/e582249d61714eacb2443572a1543d74?sid=3a5578c8-6e9f-497d-92ed-b5baeb2909d2

Not included in this PR

This change does not modify the behavior when calling
/mcp/{mcp_server_name}/tools/list directly as an MCP endpoint.
In that case, error messages are still not returned.

Copy link

vercel bot commented Oct 3, 2025

@uc4w6c is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@uc4w6c
Copy link
Contributor Author

uc4w6c commented Oct 3, 2025

The failure in test_mcp_server.py appears to be caused by #15153 and does not seem related to this PR.

Fixed this in #15183.

verbose_logger.warning(
f"Client operation cancelled for {server_name}: {str(e)}"
)
raise asyncio.CancelledError(
Copy link
Contributor

Choose a reason for hiding this comment

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

can we raise the raw error instead? @uc4w6c

this will make it easier to debug on the UI why the call is failing. instead of requiring the user to get access to server logs to see what's going on. e.g. a malformed header to the mcp server.

Copy link
Contributor Author

@uc4w6c uc4w6c Oct 4, 2025

Choose a reason for hiding this comment

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

@krrishdholakia
When connecting to the MCP server, a CancelledError is raised inside the aenter call, which overwrites the original exception.
As a result, the error message becomes meaningless (as shown in this capture), so I handled it this way instead.

If you know a way to fix this, I’d appreciate your advice.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

ack - let me see how i can raise this

@krrishdholakia
Copy link
Contributor

so i setup a fake mcp server, and raised an error on list - i can see in a lot of places we were swallowing the error. This seems like it was initially done to ensure list calls always seemed like they worked, but after some trial-and-error, i think this has led to more support tickets from users confused why their mcp servers aren't connecting to litellm.

so the change is to just re-raise the exception to the client, for easier debugging

Screenshot 2025-10-04 at 6 17 21 PM

PR: #15214

@uc4w6c
Copy link
Contributor Author

uc4w6c commented Oct 5, 2025

@krrishdholakia
I've tried your branch, but the API response returns an Internal Server Error and is not in JSON format.
This is why I wrap CancelledError with an Exception.
https://github.com/BerriAI/litellm/pull/15180/files#diff-b796034e2600989069e48bcd502fbd04ea7a424340d5338540f149bc5e2f9ad1R551

image image

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