litellm/tests
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
..
agent_tests [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
audio_tests
basic_proxy_startup_tests
batches_tests Merge pull request #22625 from BerriAI/litellm_azure_ai_finetune 2026-03-03 19:42:17 +05:30
code_coverage_tests Merge pull request #22752 from BerriAI/litellm_search_api_add 2026-03-04 18:29:10 +05:30
documentation_tests fix failing tests 2026-02-21 15:48:26 -08:00
enterprise fix: support list of modes in Mode.default for tag-based guardrails 2026-03-04 01:50:28 +05:30
guardrails_tests fix: bump litellm-proxy-extras to 0.4.50 and fix 3 failing tests (#22417) 2026-02-28 10:20:03 -08:00
image_gen_tests
litellm [Fix] Constrain feature_name to Literal, deduplicate runtime flags, fix silent test swallowing 2026-03-05 15:42:17 -08:00
litellm_core_utils
litellm_utils_tests Fix test_perform_health_check_filters_by_model_id 2026-02-26 10:43:05 +05:30
litellm-proxy-extras
llm_responses_api_testing Fix anthropic responses 2026-02-20 17:30:42 -08:00
llm_translation fix(gemini): handle 'minimal' reasoning_effort param for gemini-3.1-flash-lite-preview 2026-03-06 00:26:45 +05:30
load_tests
local_testing Add support for wildcards models for files api 2026-03-04 11:48:42 +05:30
logging_callback_tests Merge pull request #22180 from BerriAI/litellm_fix_vllm_test 2026-02-26 18:43:52 +05:30
mcp_tests Fix flaky MCP streaming test by properly mocking inner aresponses call 2026-03-04 11:09:24 -03:00
multi_instance_e2e_tests
ocr_tests
old_proxy_tests/tests
openai_endpoints_tests test(responses): add end-to-end test for responses API WebSocket mode 2026-03-02 17:24:39 +05:30
otel_tests
pass_through_tests Litellm stability fix v2 (#22452) 2026-02-28 15:29:45 -08:00
pass_through_unit_tests [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
proxy_admin_ui_tests security: fix critical/high CVEs in OS-level libs and NPM transitive 2026-02-24 19:40:09 +05:30
proxy_e2e_anthropic_messages_tests Fix: litellm/tests/llm_responses_api_testing/test_anthropic_responses_api.py 2026-02-20 17:30:53 -08:00
proxy_e2e_azure_batches_tests Add tenacity to e2e Azure batch CI and revert importorskip 2026-03-04 11:45:14 -03:00
proxy_security_tests
proxy_unit_tests Merge pull request #22372 from BerriAI/litellm_jwt_vkey_map 2026-03-05 06:24:49 +05:30
router_unit_tests [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
scim_tests
search_tests Add doc and tests for google search api 2026-03-04 13:55:43 +05:30
spend_tracking_tests
store_model_in_db_tests
test_litellm fix(mcp): resolve $ref params and path-level params in OpenAPI spec parsing (#22952) 2026-03-06 18:02:48 -08:00
unified_google_tests
vector_store_tests
windows_tests
__init__.py
gettysburg.wav
large_text.py
openai_batch_completions.jsonl
README.MD
test_budget_management.py
test_callbacks_on_proxy.py
test_config.py
test_debug_warning.py
test_default_encoding_non_root.py
test_end_users.py
test_entrypoint.py
test_fallbacks.py
test_gpt5_azure_temperature_support.py
test_health.py
test_keys.py
test_litellm_proxy_responses_config.py
test_logging.conf
test_models.py
test_openai_endpoints.py
test_organizations.py
test_otel_thread_leak.py
test_passthrough_endpoints.py
test_presidio_latency.py
test_proxy_server_non_root.py
test_ratelimit.py
test_resource_cleanup.py
test_service_logger_otel.py
test_spend_logs.py
test_team_logging.py
test_team_members.py
test_team.py fix(test): skip 'projects' field in team update assertion (#21777) 2026-02-21 10:24:53 -08:00
test_users.py fix(tests): update deprecated Anthropic model in test_user_model_access (#21826) 2026-02-21 14:18:24 -08:00

In total litellm runs 1000+ tests

[02/20/2025] Update:

To make it easier to contribute and map what behavior is tested,

we've started mapping the litellm directory in tests/test_litellm

This folder can only run mock tests.