litellm/litellm
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
..
a2a_protocol Merge pull request #22888 from BerriAI/litellm_a2a-custom-headers 2026-03-06 18:24:21 +05:30
anthropic_interface
assistants
batch_completion
batches fix(mypy): resolve type errors across 9 files 2026-03-05 06:58:20 -03:00
caching fix(caching): check REDIS_CLUSTER_NODES env var in Cache and Router class selection (#22790) 2026-03-06 17:31:30 -08:00
completion_extras Merge remote-tracking branch 'upstream/main' into pr-22553 2026-03-03 09:48:39 +00:00
containers
endpoints/speech/speech_to_completion_bridge
evals
experimental_mcp_client added configurable env for mcp timeouts (#22287) 2026-03-02 13:13:41 -08:00
files Merge pull request #22765 from BerriAI/main 2026-03-04 17:40:42 +05:30
fine_tuning Update litellm/fine_tuning/main.py 2026-03-05 06:45:31 -03:00
google_genai
images
integrations fix: downgrade WebSearch logs from info to debug to reduce production noise 2026-03-05 18:58:40 +01:00
interactions
litellm_core_utils Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
llms Merge pull request #22981 from BerriAI/litellm_reasoning-effort-dict-normalization 2026-03-07 00:37:07 +05:30
ocr
passthrough fix(passthrough): propagate Azure 429/5xx errors in async streaming instead of silent HTTP 200 (#22913) 2026-03-05 10:12:43 -08:00
proxy fix(mcp): resolve $ref params and path-level params in OpenAPI spec parsing (#22952) 2026-03-06 18:02:48 -08:00
proxy_auth
rag
realtime_api fix(azure): forward realtime_protocol from config and relax api_version check for GA path (#22369) 2026-03-02 19:21:27 +05:30
rerank_api
responses fix(lint): resolve PLR0915 too-many-statements in 4 files 2026-03-04 20:34:15 -03:00
router_strategy fix: complexity_router crashes on list-format message content (OpenAI multi-part messages) (#22761) 2026-03-04 16:18:49 -08:00
router_utils Fix encrypted content streaming affinity issue 2026-03-03 18:37:22 +05:30
search
secret_managers feat: Hashicorp Vault config override backend endpoints 2026-03-05 16:57:08 -08:00
skills
types Merge pull request #22939 from BerriAI/litellm_hashicorp_vault_backend 2026-03-06 17:59:46 -08:00
vector_store_files
vector_stores
videos
__init__.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
_lazy_imports_registry.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
_lazy_imports.py
_logging.py
_redis.py
_service_logger.py
_uuid.py
_version.py
anthropic_beta_headers_config.json
anthropic_beta_headers_manager.py
blog_posts.json
budget_manager.py
constants.py feat(spend-logs): add truncation note when error logs are truncated for DB storage (#22936) 2026-03-05 16:58:46 -08:00
cost_calculator.py feat(azure_ai): add router flat cost when response contains actual model 2026-03-06 18:18:06 +05:30
cost.json
exceptions.py
main.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
model_prices_and_context_window_backup.json Add flex pricing 2026-03-07 01:02:18 +05:30
mypy.ini
policy_templates_backup.json
provider_endpoints_support_backup.json
py.typed
router.py fix(caching): check REDIS_CLUSTER_NODES env var in Cache and Router class selection (#22790) 2026-03-06 17:31:30 -08:00
scheduler.py
timeout.py
utils.py feat(openai): add 272K tier pricing for GPT-5.4/5.4-pro 2026-03-06 22:26:14 +05:30