Commit graph

153 commits

Author SHA1 Message Date
michelligabriele
6a213fc3bc
fix(mcp): resolve OAuth2 'Capabilities: none' bug for upstream MCP servers (#20602)
- process_mcp_request() now falls back to OAuth2 passthrough when Authorization header contains a non-LiteLLM token (catches HTTPException and ProxyException 401/403)
- MCPClient._get_auth_headers() adds missing MCPAuth.oauth2 case
2026-02-06 15:00:35 -08:00
Krish Dholakia
58cc6248ab
Skip test_e2e_semantic_filter when OPENAI_API_KEY is not set (#20387)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-02-03 22:09:47 -08:00
Sameer Kankute
9a6bafe89e Fix litellm/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py tests 2026-02-03 15:01:10 +05:30
Ishaan Jaff
079f49ff6a
[Feat] - MCP Semantic Filtering Support (#20296)
* init: SemanticMCPToolFilter

* init: SemanticToolFilterHook

* test_e2e_semantic_filter

* mock tests: test_semantic_filter_basic_filtering

* Update litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* refactor folder/file organization

* docs fix

* fix filter

* fix: filter_tools

* fix linting tool filrer

* initialize_from_config

* fix: _expand_mcp_tools

* _initialize_semantic_tool_filter

* working: async_post_call_response_headers_hook

* clean up semantic tool filter

* add _initialize_semantic_tool_filter

* build_router_from_mcp_registry

* _get_tools_by_names

* fiix config

* async_post_call_response_headers_hook

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-02 18:28:53 -08:00
Sameer Kankute
0214cb04cd
Merge branch 'main' into litellm_oss_staging_01_26_2026 2026-01-27 17:00:58 +05:30
houdataali
29ee5aab5c
[Feat] enable progress notifications for MCP tool calls (#19809)
* enable progress notifications for MCP tool calls

* adjust mcp test
2026-01-26 14:48:22 -08:00
Alexsander Hamir
a8e72950db
Fix test_mcp_server_manager_config_integration_with_database cancellation error (#19801)
Mock _create_mcp_client to avoid network calls in health checks.
This prevents asyncio.CancelledError when the test teardown closes
the event loop while health checks are still pending.

The test focuses on conversion logic (access_groups, description)
not health check functionality, so mocking the network call is appropriate.
2026-01-26 10:52:49 -08:00
jquinter
5666c725ce
Fix/non standard mcp url pattern (#19738)
* fix(mcp): Add standard MCP URL pattern support for OAuth discovery (#17272)

  OAuth discovery endpoints now support both URL patterns:
  - Standard MCP pattern: /mcp/{server_name} (new)
  - Legacy LiteLLM pattern: /{server_name}/mcp (backward compatible)

  The standard pattern is required by MCP-compliant clients like
  mcp-inspector and VSCode Copilot, which expect resource URLs
  following the /mcp/{server_name} convention per RFC 9728.

  Changes:
  - Add _build_oauth_protected_resource_response() helper
  - Add oauth_protected_resource_mcp_standard() endpoint
  - Add oauth_authorization_server_mcp_standard() endpoint
  - Keep legacy endpoints for backward compatibility
  - Add tests for both URL patterns

  Fixes #17272

* fix(mcp): Add standard MCP URL pattern support for OAuth discovery (#17272)

  OAuth discovery endpoints now support both URL patterns:
  - Standard MCP pattern: /mcp/{server_name} (new)
  - Legacy LiteLLM pattern: /{server_name}/mcp (backward compatible)

  The standard pattern is required by MCP-compliant clients like
  mcp-inspector and VSCode Copilot, which expect resource URLs
  following the /mcp/{server_name} convention per RFC 9728.

  Changes:
  - Add _build_oauth_protected_resource_response() helper
  - Add oauth_protected_resource_mcp_standard() endpoint
  - Add oauth_authorization_server_mcp_standard() endpoint
  - Keep legacy endpoints for backward compatibility
  - Add tests for both URL patterns

  Fixes #17272

* Test was relocated

* refactor(mcp): Extract helper methods from run_with_session to fix PLR0915

Split the large run_with_session method (55 statements) into smaller
helper methods to satisfy ruff's PLR0915 rule (max 50 statements):

- _create_transport_context(): Creates transport based on type
- _execute_session_operation(): Handles session lifecycle

Also changed cleanup exception handling from Exception to BaseException
to properly catch asyncio.CancelledError (which is a BaseException subclass
in Python 3.8+).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* test(mcp): Fix flaky test by mocking health_check_server

The test_mcp_server_manager_config_integration_with_database test was
making real network calls to fake URLs which caused timeouts and
CancelledError exceptions.

Fixed by mocking health_check_server to return a proper
LiteLLM_MCPServerTable object instead of making network calls.

* test(mcp): Fix skip condition to properly detect claude model names

The skip condition for missing API keys was checking for "anthropic" in
the model name, but the test uses "claude-haiku-4-5" which doesn't match.
Updated to check for both "anthropic" and "claude" model patterns.

Also added skip condition for OpenAI models when OPENAI_API_KEY is not set.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* test(mcp): Fix skip condition to properly detect claude model names

The skip condition for missing API keys was checking for "anthropic" in
the model name, but the test uses "claude-haiku-4-5" which doesn't match.
Updated to check for both "anthropic" and "claude" model patterns.

Also added skip condition for OpenAI models when OPENAI_API_KEY is not set.

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 23:00:53 -08:00
YutaSaito
4381e7f98f
Merge pull request #19624 from BerriAI/litellm_test_responses_api_with_mcp_tools
[test] Skip anthropic model test when ANTHROPIC_API_KEY is not set
2026-01-23 15:58:19 +09:00
Yuta Saito
1ae9189ff8 test: Skip anthropic model test when ANTHROPIC_API_KEY is not set 2026-01-23 15:50:56 +09:00
Yuta Saito
6a60b3d848 test: completions mcp output test 2026-01-23 15:17:14 +09:00
Yuta Saito
ed67bf2705 feat: Add MCP tools response to chat completions 2026-01-22 15:32:04 +09:00
Yuta Saito
ab11ceff32 tests: patch MCP client mocks via module alias to avoid real network calls 2026-01-20 12:31:27 +09:00
Yuta Saito
51cf782292 chore: switch experimental client to streamable_http_client API 2026-01-20 07:37:50 +09:00
YutaSaito
bb7aad9de1
Merge pull request #19319 from BerriAI/litellm_test_mcp_integration
[test] mcp integration test
2026-01-19 14:38:02 +09:00
Yuta Saito
44a166a792 fix: ci mcp version up 2026-01-19 14:27:00 +09:00
Yuta Saito
a141aa6026 test: temporary skip 2026-01-19 13:57:40 +09:00
Yuta Saito
1fbbe0a983 test: restore global MCP server manager after access-group test 2026-01-19 12:29:37 +09:00
Yuta Saito
30c4a38179 test: const 2026-01-19 12:03:26 +09:00
Yuta Saito
20b6468222 test: refactor 2026-01-19 11:17:44 +09:00
Yuta Saito
c2b5e9c669 test: MCP E2E streamable_http 2026-01-19 11:12:36 +09:00
Yuta Saito
737fec600f test: add mcp e2e test 2026-01-19 10:49:39 +09:00
Yuta Saito
d31c609600 test: Let MCP tool-execution mock accept new kwargs for streaming tests 2026-01-19 07:00:14 +09:00
Yuta Saito
4ad78236ab test: Fail MCP streaming test when LiteLLM logs errors during follow-up calls 2026-01-19 06:46:39 +09:00
Yuta Saito
cd19039e39 test: Parametrize MCP streaming test to cover OpenAI and Anthropic models 2026-01-19 06:22:05 +09:00
Yuta Saito
1c2942d808 test: add mcp completions test 2026-01-15 15:47:45 +09:00
Yuta Saito
df37770a70 test: add permission test 2026-01-14 07:58:21 +09:00
Yuta Saito
35f9a75d55 feat: add UI support for configuring meta URLs 2026-01-02 15:07:37 +09:00
Yuta Saito
34b500c7f5 feat: support MCP stdio header env overrides 2025-12-22 12:58:31 +09:00
Yuta Saito
ed5cbdac2f feat: add support for using MCPs on /chat/completions 2025-12-10 10:55:33 +09:00
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
Ishaan Jaffer
6530749c89 test fixes 2025-11-26 11:42:12 -08:00
YutaSaito
b72b49757e
feat: add backend support for OAuth2 auth_type registration via UI (#17006) 2025-11-23 21:52:18 -08:00
YutaSaito
f0b10b854b
chore: remove unused MCP_PROTOCOL_VERSION_HEADER_NAME constant (#17008) 2025-11-23 21:51:11 -08:00
Ishaan Jaffer
0c28af8705 test MCP server 2025-11-22 10:02:15 -08:00
Ishaan Jaffer
fc0eac2d10 test_get_tools_from_mcp_servers 2025-11-22 10:02:15 -08:00
YutaSaito
93affcb732
[Feat] mcp resources support (#16800)
* feat: mcp prompts support

* feat: mcp resources support
2025-11-20 14:53:44 -08:00
YutaSaito
0b586d26fc
refactor: drop MCPClient.connect and use run_with_session lifecycle (#16696)
Surface detailed connection errors by handling HTTP failures
2025-11-15 17:54:27 -08:00
yuneng-jiang
00ecb99f3e
[Fix] UI MCP Tool Test Regression (#16695)
* Fix UI MCP testing tool regression

* Fixed linting
2025-11-15 15:31:04 -08:00
YutaSaito
f487f4e3a9
feat: add dynamic OAuth2 metadata discovery for MCP servers (#16676)
* feat: add dynamic OAuth2 metadata discovery for MCP servers

* fix: lint error
2025-11-14 18:14:43 -08:00
YutaSaito
8e0b66a814
fix: exclude unauthorized MCP servers from allowed server list (#16551)
* fix: exclude unauthorized MCP servers from allowed server list

* fix: test after resolving merge conflicts
2025-11-13 12:33:54 -08:00
YutaSaito
2843dab7fe
fix: allow tool call even when server name prefix is missing (#16425)
* fix: allow tool call even when server name prefix is missing

* fix: test

* fix: test

* fix: test
2025-11-12 13:50:52 -08:00
YutaSaito
6eb74bd62a
Feat/persist mcp credentials in db (#16308)
* feat: persist mcp credentials in db

* feat: remove Auth Value field from MCP Tool Testing Playground

* fix: test
2025-11-07 19:22:49 -08:00
YutaSaito
8e27b6c0b4
[MCP] configure static mcp header (#16179)
* feat: configure extra mcp headers in ui

* doc: static header

* build: add new migration file

* chore: add missing image file

* fix: test
2025-11-03 21:06:36 -08:00
YutaSaito
c0890e7d33
[Feat] add support for dynamic client registration (#15921) (enables Atlassian MCP to work via Oauth on LiteLLM)
* feat: add support for dynamic client registration #13856

* fix: test

* feat: return 401 when oauth2_header is missing for OAuth2-based MCP servers
2025-10-26 10:13:46 -07:00
Vinod Singh
d4aadda692
Auth Header Fix for MCP Tool Call (#15736)
* fixed the Auth header for MCP Tool Call

* Final fix for Auth header

* testcase for mcp_auth_header_extraction, insensitive_alias_matching, insensitive_servername_matching added
2025-10-21 13:58:03 -07:00
Yuta Saito
5359a0d6a6 fix: test 2025-09-30 07:25:32 +09:00
Yuta Saito
be5010a675 test: fix tests 2025-09-29 07:21:32 +09:00
Krrish Dholakia
9403efa511 test: fix tests 2025-09-28 08:54:15 -07:00
Krrish Dholakia
1256dd53d9 test: update tests 2025-09-28 08:53:11 -07:00