Repository navigation
Description
Summary
When an MCP agent answers with HTTP 401, ADCPClient reports a connection failure and tells the user to check the agent URI. It drops the status code and the WWW-Authenticate challenge, so a bad or missing token looks like a wrong URL. This happens on 8.0.0 and 8.0.0rc3.
Reproduction (adcp 8.0.0)
import asyncio
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
from adcp import ADCPClient
from adcp.types import GetProductsRequest
from adcp.types.core import AgentConfig, Protocol
class Unauthorized(BaseHTTPRequestHandler):
def do_POST(self):
body = b'{"error":"unauthenticated"}'
self.send_response(401)
self.send_header("Content-Type", "application/json")
self.send_header("WWW-Authenticate", 'Bearer realm="adcp", error="invalid_token"')
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
do_GET = do_POST
async def main():
server = HTTPServer(("127.0.0.1", 0), Unauthorized)
threading.Thread(target=server.serve_forever, daemon=True).start()
client = ADCPClient(AgentConfig(id="seller", agent_uri=f"http://127.0.0.1:{server.server_port}/mcp/",
protocol=Protocol.MCP, auth_token="wrong-token", requires_auth=True))
result = await client.get_products(GetProductsRequest(buying_mode="brief", brief="video"))
print(result.error)
asyncio.run(main())Output:
[Agent: seller] Failed to connect: Server returned an error response
URI: http://127.0.0.1:<port>/mcp/
Suggestion: Check that the agent URI is correct and the agent is running.
Try testing with: python -m adcp test --config <agent-id>
Expected
An authentication error that names the HTTP status and the WWW-Authenticate error (invalid_token), and suggests checking the token and auth header. The A2A transport already reports HTTP Error 401: Client error '401 Unauthorized', which is enough to act on.
Why it matters
I hit this while probing a seller with the wrong token: the client sent me to check a URL that was correct. Buyer agents that read result.error to choose recovery also can't tell a credential problem from an unreachable agent.
Activity
bokelley commentedon Oct 2, 2026
Triage
Classification: Bug
Bucket(s): client (no
clientlabel exists in this repo — gap noted)Status: ready-to-implement
Milestone: omitted — none named in issue
What the experts said:
_ALL_HTTP_STATUS_ERROR_TYPES(the existingisinstancetuple covering bothhttpxandhttpx2) must be used for chain-walking, not a freshhttpximport._call_mcp_tool()must explicitly catchADCPAuthenticationErrorbefore the bareexcept Exceptionand returnTaskResult(FAILED, error="Authentication failed: HTTP 401 (...)")— leaving the choice unresolved is a blocker. Tests required for both the connection and tool-call paths.WWW-Authenticatecontent (RFC 6750 public challenge, no credentials). A2A parity is the right target. Two additional fix points: short-circuit the URL discovery loop on 401/403 (don't probe alternate URL forms after an auth rejection), and apply the same fix toclose_mcp_session()which has the same string-match gap.My take: The root cause is that
_get_session()'s string-match onstr(last_error)fails because the MCP SDK surfaces "Server returned an error response" — no status code in the text — so the branch that would raiseADCPAuthenticationErroris never reached. The fix direction is clear, well-scoped, and fully non-breaking (corrects incorrect exception class; error text is diagnostic only).Implementation brief:
src/adcp/protocols/mcp.py—_get_session()(~line 662): Replace thestr(last_error).lower()string-match with an exception chain walk. Check__cause__then__context__forisinstance(exc, _ALL_HTTP_STATUS_ERROR_TYPES)(the tuple already defined at ~line 61-64, covers bothhttpxandhttpx2). Onstatus_code in (401, 403), extractWWW-Authenticatefromexc.response.headersand raiseADCPAuthenticationError(f"Authentication failed: HTTP {status_code} — {www_auth}", ...). Also break out of the URL discovery loop immediately on auth errors — probing/mcpvs/mcp/after a 401 wastes round-trips and misleads.src/adcp/protocols/mcp.py—_call_mcp_tool()(~line 943): AddADCPAuthenticationErrorto the specific re-raise guard (alongsideIdempotencyConflictError) or catch it before the bareexcept Exceptionand returnTaskResult(FAILED, error=f"Authentication failed: HTTP {status_code} (...)"). The latter matches A2A's pattern (a2a.py:616-622) and is preferred.src/adcp/protocols/mcp.py—close_mcp_session()(~line 1241): Apply the same chain-walk so 401/403 during session teardown raisesADCPAuthenticationErrorinstead ofADCPConnectionError.ADCPAuthenticationErrorto the top-level import block (currently lazily imported inside the branch)._get_session()with chainedhttpx.HTTPStatusError(401)→ADCPAuthenticationError; (b) same for thehttpx2variant; (c)_call_mcp_tool()mid-call 401 →TaskResult(FAILED)with auth-specific message string.pyteston affected tests,mypy src/,ruff check ./black --check .Non-breaking rationale: no public symbols removed or renamed; the exception class fix corrects incorrect behavior consistent with existing A2A transport behavior; error message text is diagnostic only.
Triaged by Claude Code. Session: https://claude.ai/code/session_014fEZrgJnTpaBnQXaDa5jFV
Generated by Claude Code