litellm/tests/test_litellm/proxy
YutaSaito b5133c4c7d
Feat/mcp preserve tool metadata calltoolresult (#17561)
* feat(mcp): preserve tool metadata and full CallToolResult in MCP gateway

This PR fixes two issues that prevented ChatGPT from rendering MCP UI widgets
when proxied through LiteLLM:

1. Preserve Tool Metadata in tools/list
   - Modified _create_prefixed_tools() to mutate tools in place instead of
     reconstructing them, preserving all fields including metadata/_meta
   - This ensures ChatGPT can see 'openai/outputTemplate' URIs in tools/list
     and will call resources/read to fetch widgets

2. Preserve Full CallToolResult (structuredContent + metadata)
   - Changed call_mcp_tool() and _handle_managed_mcp_tool() to return full
     CallToolResult objects instead of just content
   - Updated error handlers to return CallToolResult with isError flag
   - Wrapped local tool results in CallToolResult objects
   - This preserves structuredContent and metadata fields needed for widget rendering

Files changed:
- litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
- litellm/proxy/_experimental/mcp_server/server.py

Fixes issues where ChatGPT could not render MCP UI widgets when using
LiteLLM as an MCP gateway.

* feat(mcp): Preserve tool metadata and return full CallToolResult for ChatGPT UI widgets

- Preserve metadata and _meta fields when creating prefixed tools
- Return full CallToolResult instead of just content list
- Ensures ChatGPT can discover and render UI widgets via openai/outputTemplate
- Fixes metadata stripping that prevented widget rendering in ChatGPT

Changes:
- mcp_server_manager.py: Mutate tools in place to preserve all fields including metadata
- server.py: Return CallToolResult with structuredContent and metadata preserved
- Added test to verify metadata preservation

* fix: guard cost calculator when BaseModel lacks _hidden_params

---------

Co-authored-by: Afroz Ahmad <aahmad@Afrozs-MacBook-Pro.local>
Co-authored-by: Afroz Ahmad <aahmad@KNDMCPTMZH3.sephoraus.com>
2025-12-05 16:15:22 -08:00
..
_experimental/mcp_server Feat/mcp preserve tool metadata calltoolresult (#17561) 2025-12-05 16:15:22 -08:00
agent_endpoints [Feat] Agent Access Control - Enforce Allowed agents by key, team + add agent access groups on backend (#17502) 2025-12-04 16:31:00 -08:00
anthropic_endpoints test fixes 2025-06-25 18:42:06 -07:00
auth feat: Add /global/spend/tags to admin viewer routes (#17501) 2025-12-04 14:43:33 -08:00
client [Feat] AI Gateway Auth - Allow using JWTs for signing in with Proxy CLI (#16756) 2025-11-17 19:47:29 -08:00
common_utils Merge remote-tracking branch 'origin' into litellm_ui_callback_fix 2025-12-03 11:02:59 -08:00
db Adding tests 2025-12-04 12:36:15 -08:00
discovery_endpoints Change is_sso_configured to auto_redirect_to_sso 2025-12-03 15:48:50 -08:00
experimental/mcp_server Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
google_endpoints test google endpoints 2025-10-31 20:50:31 -07:00
guardrails fix(presidio): handle empty content and error dict responses (#17489) 2025-12-05 15:45:19 -08:00
health_endpoints Add Langfuse OTEL and SQS to health check (#16514) 2025-11-12 18:25:30 -08:00
hooks [Bug fix] Secret Managers Integration - Make email and secret manager operations independent in key management hooks (#17551) 2025-12-05 15:26:00 -08:00
image_endpoints test fix 2025-10-17 10:46:42 -07:00
management_endpoints Merge pull request #17498 from BerriAI/litellm_customer_usage_backend 2025-12-05 15:31:08 -08:00
management_helpers [MCP Gateway] Litellm mcp fixes team control (#15304) 2025-10-07 16:48:00 -07:00
middleware Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
openai_files_endpoint fix issue from pr review 2025-10-01 11:57:10 +08:00
pass_through_endpoints Add passthrough cost tracking for veo 2025-12-01 14:33:03 +05:30
prompts TestPromptVersionsEndpoint 2025-11-21 16:21:13 -08:00
public_endpoints Change provider create fields to JSON (#16985) 2025-11-23 21:57:22 -08:00
response_api_endpoints Add support for cursor BYOK with its own configuration 2025-12-05 09:34:49 +05:30
spend_tracking fix(sql): Optimize SpendLogs queries to use timestamp filtering for index usage (#17504) 2025-12-04 21:52:57 -08:00
test_configs Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
ui_crud_endpoints [Infra] Litellm Backend SSO Changes (#16029) 2025-10-30 14:32:08 -07:00
vector_store_endpoints Fix vector store configuration synchronization failure 2025-12-05 11:46:14 +05:30
__init__.py test fix 2025-10-17 10:46:42 -07:00
test_batch_metadata_none_fix.py Fix issue #13995: Handle None metadata in batch requests (#13996) 2025-08-27 14:51:09 -07:00
test_caching_routes.py [Bug Fix] Ensure /redis/info works on GCP Redis (#11732) 2025-06-14 15:35:09 -07:00
test_common_request_processing.py Revert "fix: respect guardrail mock_response during during_call to return blo…" (#17332) 2025-12-01 15:40:28 -08:00
test_custom_proxy.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_enforce_user_param.py Enforce support of enforce_user_param to openai post endpoints 2025-12-03 12:19:21 +05:30
test_fastapi_offline_routes.py [Bug Fix] - Get Routes (#13466) 2025-08-09 12:52:23 -07:00
test_health_check_functions.py Add background health checks to db 2025-12-05 14:27:37 +05:30
test_litellm_pre_call_utils.py Fix key model alias (#16896) 2025-11-20 16:05:49 -08:00
test_model_id_header_propagation.py (fix) propagate x-litellm-model-id in responses (#16986) 2025-11-24 20:40:43 -08:00
test_proxy_cli.py feature/add max requests env var 2025-09-28 19:18:56 +01:00
test_proxy_server.py V2 login route 2025-12-03 12:41:45 -08:00
test_proxy_types.py Litellm dev 06 06 2025 p1 (#11496) 2025-06-07 09:12:16 -07:00
test_proxy_utils.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_route_llm_request.py Fix create, search vector store error (#13285) 2025-08-06 11:15:17 -07:00
test_shared_health_check.py Add shared healthcheck 2025-10-09 22:18:05 +05:30
test_spend_log_cleanup.py Fix/gemini api key environment variable support (#12507) 2025-07-29 15:56:01 -07:00
test_swagger_chat_completions.py [Bug Fix] Allow using Swagger for /chat/completions (#13469) 2025-08-09 15:35:45 -07:00
test_team_member_update.py fix mapped tests (#12320) 2025-07-04 10:04:43 -07:00