litellm/tests/test_litellm/proxy/_experimental/mcp_server
Ishaan Jaff bb52b0b6b0
fix(mcp): resolve $ref params and path-level params in OpenAPI spec parsing (#22952)
* fix(mcp): resolve \$ref params and merge path-level params in OpenAPI tool registration

Real-world OpenAPI specs (e.g. GitHub's 11.8 MB official spec) use two
patterns that crashed tool registration:

1. \$ref parameters: params defined as {"$ref": "#/components/parameters/foo"}
   instead of inline objects. Accessing param["name"] on a $ref raises KeyError.
   Fix: resolve each param against components/parameters before processing.

2. Path-level parameters: params defined on the path object apply to all
   HTTP methods on that path, but the operation object doesn't include them.
   GitHub's spec uses this for owner/repo/etc. path params.
   Fix: merge path-level params with operation-level params (op-level wins
   when the same name+in combination appears in both).

With this fix the full GitHub REST API spec loads successfully:
720 paths → 1079 tools, all with correct parameter schemas.

* fix(mcp): resolve \$ref params in OpenAPI preview endpoint (test/tools/list)

The _preview_openapi_tools function (called by the UI add-server form to show
connection status and available tools) had the same bug as _register_openapi_tools:
it accessed param["name"] directly without resolving \$ref parameters or merging
path-level parameters from the path item.

This caused "Failed to load OpenAPI spec: 'name'" for any spec that uses
component-level parameter references (e.g. GitHub's official REST API spec).

Apply the same fix: resolve \$ref against components/parameters and merge
path-level params (with operation-level taking priority) before building schemas.

* refactor(openapi-mcp): extract resolve_operation_params, add tests

- Hoist _resolve_ref and _resolve_param_list to module level in
  openapi_to_mcp_generator.py (were being redefined on every loop iteration)
- _resolve_ref now returns None for unresolvable $refs instead of
  the stub dict, preventing (None, None) from poisoning deduplication
- Add resolve_operation_params() as a shared helper that handles both
  $ref resolution and path-level param merging
- Replace duplicated inline logic in mcp_server_manager.py and
  rest_endpoints.py with calls to resolve_operation_params()
- Add TestResolveRef, TestResolveParamList, TestResolveOperationParams
  test classes covering $ref resolution, path-level merging, collision
  semantics, unresolvable ref filtering, and a GitHub-style spec fixture
2026-03-06 18:02:48 -08:00
..
auth fix: include mcp_tool_permissions server ids in allowed mcp servers (#22311) 2026-03-02 19:21:11 +05:30
guardrail_translation fix(tests): Add missing mocks for MCP IP filtering and updated APIs (#20652) 2026-02-07 11:30:49 -08:00
test_byok_oauth_endpoints.py feat(proxy): client-side provider API key precedence for Anthropic /v1/messages 2026-03-06 18:20:46 +05:30
test_discoverable_endpoints.py fix: Missing OAuth session state. Please retry 2026-02-24 14:22:38 +05:30
test_jwt_mcp_enforcement.py fix(tests): update MCP tests broken by user permissions commit (#21462) 2026-02-19 02:09:11 -03:00
test_jwt_mcp_simple.py [Bug] Ensure MCP permissions are enforced when using JWT Auth (#20383) 2026-02-03 19:13:13 -08:00
test_mcp_cost_calculator.py [Feat] Add MCP Cost Tracking (#12385) 2025-07-07 21:08:10 -07:00
test_mcp_custom_fields.py feat: add UI support for configuring meta URLs 2026-01-02 15:07:37 +09:00
test_mcp_debug.py fix(tests): resolve MCP test isolation failures in parallel execution 2026-02-18 14:08:48 -03:00
test_mcp_discovery.py feat: MCP server discovery UI (#21079) 2026-02-12 17:59:21 -08:00
test_mcp_metadata_preservation.py Feat/mcp preserve tool metadata calltoolresult (#17561) 2025-12-05 16:15:22 -08:00
test_mcp_server.py feat(mcp): allow admins to override tool name and description per MCP server (#22828) 2026-03-04 17:58:05 -08:00
test_mcp_server_manager.py fix mcp server created_at and updated_at timestamps being overwritten with current time 2026-03-03 09:41:45 -08:00
test_mcp_stale_session.py Return 200 response for stale dlete requests from client 2026-02-12 19:21:14 +05:30
test_oauth2_token_cache.py [Feat] MCP Oauth2 Fixes - Add support for MCP M2M Oauth2 support (#20788) 2026-02-09 17:35:11 -08:00
test_openapi_to_mcp_generator.py fix(mcp): resolve $ref params and path-level params in OpenAPI spec parsing (#22952) 2026-03-06 18:02:48 -08:00
test_rest_endpoints.py MCP fixes 2026-02-11 18:07:24 -08:00
test_semantic_tool_filter.py Fix litellm/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py tests 2026-02-03 15:01:10 +05:30
test_ui_session_utils.py fix: mcp deepcopy error 2025-12-16 07:02:07 +09:00