cleanup: remove mcp sse url optimization

Signed-off-by: Calum Murray <cmurray@redhat.com>
This commit is contained in:
Calum Murray 2025-07-02 10:45:31 -04:00
parent 5098d3f462
commit 8e5ab564b9
No known key found for this signature in database
GPG key ID: B67F01AEB13FE187

View file

@ -6,9 +6,7 @@
from collections.abc import AsyncGenerator from collections.abc import AsyncGenerator
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
from pathlib import PurePosixPath
from typing import Any, cast from typing import Any, cast
from urllib.parse import unquote, urlparse
import httpx import httpx
from mcp import ClientSession from mcp import ClientSession
@ -70,18 +68,12 @@ async def streamable_http_client_wrapper(endpoint: str, headers: dict[str, str])
def get_client_wrapper(endpoint: str, headers: dict[str, str]) -> _AsyncGeneratorContextManager[ClientSession, Any]: def get_client_wrapper(endpoint: str, headers: dict[str, str]) -> _AsyncGeneratorContextManager[ClientSession, Any]:
path = PurePosixPath(unquote(urlparse(endpoint).path))
if path.parts[-1] != "sse":
try: try:
return streamable_http_client_wrapper(endpoint, headers) return streamable_http_client_wrapper(endpoint, headers)
except AuthenticationRequiredError as e: except AuthenticationRequiredError as e:
raise e # since this was an authentication error, we want to surface that instead of trying with SSE raise e # since this was an authentication error, we want to surface that instead of trying with SSE
except Exception: except Exception:
return sse_client_wrapper(endpoint, headers) return sse_client_wrapper(endpoint, headers)
else:
# most SSE MCP servers are served at endpoints ending in /sse, so default to the SSE client wrapper
# if the endpoint is explicitly an SSE endpoint
return sse_client_wrapper(endpoint, headers)
async def list_mcp_tools(endpoint: str, headers: dict[str, str]) -> ListToolDefsResponse: async def list_mcp_tools(endpoint: str, headers: dict[str, str]) -> ListToolDefsResponse: