Skip to content

mcp: support http(s) URLs for spec_path in OpenAPI MCP loader - #20753

Merged
10 commits merged into
BerriAI:litellm_oss_staging_02_09_2026from
moophlo:main
Feb 10, 2026
Merged

mcp: support http(s) URLs for spec_path in OpenAPI MCP loader#20753
10 commits merged into
BerriAI:litellm_oss_staging_02_09_2026from
moophlo:main

Conversation

@moophlo

@moophlo moophlo commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes documentation/implementation mismatch where spec_path is documented as supporting URLs, but the loader only supported local filesystem paths.

Type

🐛 Bug Fix

Changes

  • Fix spec_path handling in MCP OpenAPI loader to support both:
    • local filesystem paths
    • http(s) URLs
  • Align implementation with documented behavior (spec_path: path or URL)
  • Add unit test covering OpenAPI spec loading from an HTTP URL
  • No behavior change for existing file-based configs

Pre-submission checklist

Test results

Ran MCP unit tests successfully (excluding two tests that are unrelated to this change and currently fail due to import/runtime environment requirements):

poetry run pytest tests/mcp_tests -x -vv -n 4 \
  --ignore=tests/mcp_tests/test_mcp_hooks.py \
  --ignore=tests/mcp_tests/test_proxy_mcp_e2e.py

Result: 89 passed, 5 skipped

Note: Local test run emits asyncio warnings (Task was destroyed but it is pending!) originating from background tasks in MCPServerManager. These warnings are pre-existing and not introduced by this change.

@vercel

vercel Bot commented Feb 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 9, 2026 2:39pm

Request Review

@CLAassistant

CLAassistant commented Feb 9, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 4 committers have signed the CLA.

✅ Sameerlite
✅ emerzon
✅ CAFxX
❌ Andrea Odorisio


Andrea Odorisio seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR aligns the MCP OpenAPI loader’s documented spec_path behavior with implementation by allowing spec_path to be either a local file path or an http(s) URL. It does this by updating load_openapi_spec() to detect URL schemes and fetch the spec over HTTP, and adds a unit test that monkeypatches httpx.get to validate URL loading.

Main integration concern: URL loading currently uses httpx.get directly rather than the project’s configured/custom httpx client path used elsewhere in the MCP tooling, which can cause URL-based specs to fail in environments depending on that configuration (proxy/TLS/auth/instrumentation).

Confidence Score: 4/5

  • Mostly safe to merge, but URL spec loading should use the project’s configured HTTP client to avoid deployment-specific failures.
  • The change is small and covered by a unit test, but it introduces a separate HTTP code path (httpx.get directly) that bypasses existing httpx client configuration used elsewhere in the module, which is a common source of real-world breakage when proxies/TLS/auth are required.
  • litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py Adds URL support to load_openapi_spec() via direct httpx.get; main concern is it bypasses the project’s custom httpx client/config used elsewhere in this module.
tests/mcp_tests/test_openapi_spec_path_url.py Adds a unit test that monkeypatches httpx.get to validate load_openapi_spec() can load an OpenAPI spec from an http URL.

Sequence Diagram

sequenceDiagram
    participant Caller as MCP OpenAPI Loader
    participant Loader as openapi_to_mcp_generator.load_openapi_spec
    participant URLParse as urllib.parse.urlparse
    participant FS as Local filesystem
    participant Httpx as httpx.get

    Caller->>Loader: load_openapi_spec(spec_path)
    Loader->>URLParse: urlparse(spec_path)
    alt spec_path scheme is http/https
        Loader->>Httpx: GET spec_path (timeout=30s)
        Httpx-->>Loader: Response (json)
        Loader-->>Caller: dict spec
    else local path
        Loader->>FS: open(spec_path)
        FS-->>Loader: file contents
        Loader-->>Caller: json.load(file)
    end
    Caller->>Caller: get_base_url(spec)
    Caller->>Caller: register_tools_from_openapi(spec, base_url)
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 49 to +56
def load_openapi_spec(filepath: str) -> Dict[str, Any]:
"""Load OpenAPI specification from JSON file."""
with open(filepath, "r") as f:
"""Load OpenAPI specification from JSON file or URL."""
parsed = urlparse(filepath)
if parsed.scheme in ("http", "https"):
# fetch spec from URL
r = httpx.get(filepath, timeout=30.0)
r.raise_for_status()
return r.json()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bypasses configured HTTP client

load_openapi_spec() now fetches URL specs via httpx.get(...) directly, but the rest of this module uses get_async_httpx_client(..., llm_provider=httpxSpecialProvider.MCP) to ensure the project’s custom httpx configuration (proxies, TLS settings, auth headers, instrumentation, etc.) is applied. As-is, loading specs from URLs will ignore those settings and can fail in deployments that require them. Prefer using the same shared/custom httpx client path for URL loads as well.

Ensure URL-based OpenAPI loading honors LiteLLM’s custom httpx configuration, add missing imports, and harden tests to prevent regressions or accidental direct httpx usage.
@ghost
ghost changed the base branch from main to litellm_oss_staging_02_09_2026 February 10, 2026 03:01
@ghost
ghost merged commit 26893ab into BerriAI:litellm_oss_staging_02_09_2026 Feb 10, 2026
5 of 8 checks passed
Sameerlite added a commit that referenced this pull request Feb 10, 2026
* fix(responses): preserve streamed tool deltas when id is omitted

* fix(responses): guard ambiguous tool-call index reuse

* add missing indexes on VerificationToken table

* mcp: support http(s) URLs for spec_path in OpenAPI MCP loader

* test(mcp): add unit test for OpenAPI spec_path URL support

* Fix OpenAPI spec URL loading to use shared MCP httpx client

Ensure URL-based OpenAPI loading honors LiteLLM’s custom httpx configuration, add missing imports, and harden tests to prevent regressions or accidental direct httpx usage.

* removed unused import urlparse

* removed unsupported timeout argument

---------

Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
Co-authored-by: Carlo Alberto Ferraris <cafxx@mercari.com>
Co-authored-by: Andrea Odorisio <Andrea@BR-FHH9MWDQ2PMAC.local>
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…I#20753)

* fix(responses): preserve streamed tool deltas when id is omitted

* fix(responses): guard ambiguous tool-call index reuse

* add missing indexes on VerificationToken table

* mcp: support http(s) URLs for spec_path in OpenAPI MCP loader

* test(mcp): add unit test for OpenAPI spec_path URL support

* Fix OpenAPI spec URL loading to use shared MCP httpx client

Ensure URL-based OpenAPI loading honors LiteLLM’s custom httpx configuration, add missing imports, and harden tests to prevent regressions or accidental direct httpx usage.

* removed unused import urlparse

* removed unsupported timeout argument

---------

Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
Co-authored-by: Carlo Alberto Ferraris <cafxx@mercari.com>
Co-authored-by: Andrea Odorisio <Andrea@BR-FHH9MWDQ2PMAC.local>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants