-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
mcp: support http(s) URLs for spec_path in OpenAPI MCP loader #20753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
68d788c
fix(responses): preserve streamed tool deltas when id is omitted
emerzon cf17a44
fix(responses): guard ambiguous tool-call index reuse
emerzon aaa48f8
Merge pull request #20712 from emerzon/fix/responses-tool-call-delta-…
Sameerlite 248fe65
add missing indexes on VerificationToken table
CAFxX a924a07
Merge pull request #20736 from CAFxX/verificationtoken-index
Sameerlite 94c3aca
mcp: support http(s) URLs for spec_path in OpenAPI MCP loader
ccfb8a4
test(mcp): add unit test for OpenAPI spec_path URL support
ffa09a2
Fix OpenAPI spec URL loading to use shared MCP httpx client
c5f71cd
removed unused import urlparse
d40105f
removed unsupported timeout argument
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...itellm_proxy_extras/migrations/20260209085821_add_verificationtoken_indexes/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- CreateIndex | ||
| CREATE INDEX "LiteLLM_VerificationToken_user_id_team_id_idx" ON "LiteLLM_VerificationToken"("user_id", "team_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "LiteLLM_VerificationToken_team_id_idx" ON "LiteLLM_VerificationToken"("team_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "LiteLLM_VerificationToken_budget_reset_at_expires_idx" ON "LiteLLM_VerificationToken"("budget_reset_at", "expires"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Dict | ||
|
|
||
| import httpx | ||
| import pytest | ||
|
|
||
| from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator as gen | ||
|
|
||
|
|
||
| class _FakeAsyncHTTPHandler: | ||
| """ | ||
| Minimal stand-in for the object returned by get_async_httpx_client(). | ||
| openapi_to_mcp_generator.load_openapi_spec_async() calls: | ||
|
|
||
| client = get_async_httpx_client(...) | ||
| r = await client.get(url, timeout=30.0) | ||
|
|
||
| So we must implement async get(). | ||
| """ | ||
|
|
||
| def __init__(self, response: httpx.Response, expected_url: str): | ||
| self._response = response | ||
| self._expected_url = expected_url | ||
| self.calls = 0 | ||
|
|
||
| async def get(self, request_url: str, timeout: float = 30.0): | ||
| self.calls += 1 | ||
| assert request_url == self._expected_url | ||
| assert timeout == 30.0 | ||
| return self._response | ||
|
|
||
|
|
||
| def test_load_openapi_spec_supports_http_url(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| url = "http://example.local/openapi.json" | ||
| expected: Dict[str, Any] = { | ||
| "openapi": "3.0.0", | ||
| "info": {"title": "Test API", "version": "1.0.0"}, | ||
| "paths": {}, | ||
| } | ||
|
|
||
| # httpx.Response must include a Request for raise_for_status() to work. | ||
| req = httpx.Request("GET", url) | ||
| resp = httpx.Response(status_code=200, json=expected, request=req) | ||
|
|
||
| calls = {"get_async_httpx_client": 0} | ||
| handler_holder: Dict[str, Any] = {} | ||
|
|
||
| def fake_get_async_httpx_client(*args, **kwargs): | ||
| calls["get_async_httpx_client"] += 1 | ||
| h = _FakeAsyncHTTPHandler(resp, expected_url=url) | ||
| handler_holder["handler"] = h | ||
| return h | ||
|
|
||
| # Ensure shared/custom client path is used | ||
| monkeypatch.setattr(gen, "get_async_httpx_client", fake_get_async_httpx_client) | ||
|
|
||
| # Fail loudly if someone reintroduces direct httpx.get() | ||
| def boom(*args, **kwargs): | ||
| raise AssertionError("Direct httpx.get() must not be used for URL spec loading") | ||
|
|
||
| monkeypatch.setattr(httpx, "get", boom) | ||
|
|
||
| spec = gen.load_openapi_spec(url) | ||
|
|
||
| assert spec == expected | ||
| assert calls["get_async_httpx_client"] == 1 | ||
| assert handler_holder["handler"].calls == 1 | ||
|
|
||
|
|
||
| def test_load_openapi_spec_supports_local_file_path(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| expected: Dict[str, Any] = { | ||
| "openapi": "3.0.0", | ||
| "info": {"title": "Local API", "version": "1.0.0"}, | ||
| "paths": {}, | ||
| } | ||
|
|
||
| p = tmp_path / "openapi.json" | ||
| p.write_text( | ||
| '{"openapi":"3.0.0","info":{"title":"Local API","version":"1.0.0"},"paths":{}}', | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| # For local files, shared client must NOT be used. | ||
| def boom_client(*args, **kwargs): | ||
| raise AssertionError("get_async_httpx_client() must not be called for local file paths") | ||
|
|
||
| monkeypatch.setattr(gen, "get_async_httpx_client", boom_client) | ||
|
|
||
| spec = gen.load_openapi_spec(str(p)) | ||
| assert spec == expected | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 viahttpx.get(...)directly, but the rest of this module usesget_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.