The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp-oauth): avoid consuming MCP resource SSE as OAuth metadata
Mathias Huque1fd7ff0f5c0d
diff --git a/tests/tools/test_mcp_oauth_issuer_origin.py b/tests/tools/test_mcp_oauth_issuer_origin.pyindex d1d5e6fd7dc..e34d69f2453 100644--- a/tests/tools/test_mcp_oauth_issuer_origin.py+++ b/tests/tools/test_mcp_oauth_issuer_origin.py@@ -10,6 +10,7 @@ rejected.from __future__ import annotationsimport json+from types import SimpleNamespacefrom urllib.parse import parse_qs, urlsplitimport pytest@@ -22,6 +23,23 @@ ADVERTISED = f"{AS_ORIGIN}/mcp-issuer"PATH_DOC = "/.well-known/oauth-authorization-server/mcp-issuer"+async def test_origin_issued_metadata_shim_does_not_read_mcp_resource_response():+ from tools.mcp_oauth_provider import HermesProviderMixin++ class ResourceResponse:+ status_code = 200+ request = SimpleNamespace(url=RESOURCE)++ async def aread(self):+ raise AssertionError("normal MCP resource response must not be consumed as OAuth metadata")++ provider = HermesProviderMixin.__new__(HermesProviderMixin)+ response = ResourceResponse()++ assert await provider._hermes_accept_origin_issued_metadata(response) is response++def _asm(issuer):return {"issuer": issuer, "authorization_endpoint": f"{AS_ORIGIN}/authorize", "token_endpoint": f"{AS_ORIGIN}/token","registration_endpoint": f"{AS_ORIGIN}/register", "response_types_supported": ["code"],diff --git a/tools/mcp_oauth_provider.py b/tools/mcp_oauth_provider.pyindex 2d8e230154d..18f62a1d416 100644--- a/tools/mcp_oauth_provider.py+++ b/tools/mcp_oauth_provider.py@@ -164,6 +164,15 @@ class HermesProviderMixin:untouched, so the SEP-2352 credential binding still uses the advertised identifier (stable acrossruns), while the RFC 9207 ``iss`` check and Hermes' refresh-token binding use the document's issuer.Every other response goes back to the SDK unchanged, including its issuer check."""+ # This compatibility shim is only for authorization-server metadata+ # responses. Never consume arbitrary 200 responses here: MCP resource+ # responses may be long-lived SSE streams (for example GET /v2/mcp),+ # and response.aread() would wait for that stream to end while holding+ # the OAuth state semaphore.+ req = getattr(response, "request", None)+ if req is None or not any(path in str(req.url) for path in _ASM_DISCOVERY_PATHS):+ return response+from mcp.shared.auth import OAuthMetadatafrom pydantic import ValidationErrortry: