Skip to content

fix(client): route getAgentInfo() through connectMCPWithFallback (#1233, #1234) - #1244

Closed
bokelley wants to merge 2 commits into
mainfrom
bokelley/fastmcp-streamable-init
Closed

bokelley wants to merge 2 commits into
mainfrom
bokelley/fastmcp-streamable-init

Conversation

@bokelley

@bokelley bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Closes getAgentInfo() lacks SSE fallback that every other code path has #1233: SingleAgentClient.getAgentInfo() now uses connectMCPWithFallback instead of connectMCP, gaining the same StreamableHTTP-retry / SSE-fallback semantics that every other code path (callMCPTool, mcp-tasks) already has. connectMCPWithFallback learns an optional authProvider parameter, forwarded to both StreamableHTTP and SSE transports so OAuth-protected agents still work through the fallback.
  • Closes discoverMCPEndpoint error should hint at wrong-path registration #1234: discoverMCPEndpoint's "Failed to discover MCP endpoint" error message now appends a hint that the most common cause is agent_uri pointing at the host root while the MCP endpoint lives at a non-standard path (e.g. /api/mcp, /adcp/mcp).

Background

Discovered while investigating #1231 (closed as not-a-bug). Root cause at adcp.bidmachine.io was registration mismatch — the MCP endpoint is at /adcp/mcp and requires bearer auth, but the AAO probe registered the host root. Two real-but-separate gaps split out of that triage:

  1. getAgentInfo() was the only normal-path call without fallback — measurably more brittle than every other code path against the same server.
  2. The discovery error message doesn't surface the most common operator mistake (wrong-path registration).

Test plan

  • npm run test:lib — 5681/5688 pass, 7 skipped, 0 failed
  • npm run typecheck — clean
  • New regression test (test/lib/get-agent-info-fallback.test.js) pins both fixes:
    • StreamableHTTP retry path: server fails the second initialize with 400; without the fix getAgentInfo propagates the error, with the fix it retries and succeeds (verified by stash/restore round-trip).
    • Discovery hint: server 404s every path; error message contains the wrong-path hint with /api/mcp / /adcp/mcp examples.

bokelley and others added 2 commits May 1, 2026 18:16
`SingleAgentClient.getAgentInfo()` previously routed its post-discovery
listTools connection through `connectMCP`, which has no retry on
`StreamableHTTPError` and no SSE fallback. Every other production path
(`callMCPTool`, `mcp-tasks`) goes through `connectMCPWithFallback`,
which retries once on transient session errors and falls back to
`SSEClientTransport` for non-401 failures. The asymmetry surfaced as
`getAgentInfo()` failing on flaky StreamableHTTP servers where the
comply suite kept working.

- Extend `connectMCPWithFallback` with an optional `authProvider`
  parameter, forwarded to both StreamableHTTP and SSE transports so
  OAuth-protected agents still work through the fallback.
- Rewire `getAgentInfo()` to use `connectMCPWithFallback` for both
  bearer-token and saved-OAuth-token cases.
- `discoverMCPEndpoint`'s "Failed to discover MCP endpoint" error now
  includes a hint that the most common cause is `agent_uri` pointing
  at the host root when the MCP endpoint lives at a non-standard path.

Closes #1233, #1234.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Convergence findings from parallel review (protocol + code + security):

- Add SSE-fallback regression test (`connectMCPWithFallback` against a
  public-shaped URL with mocked global fetch). The original test only
  exercised the StreamableHTTP retry path; the headline SSE-fallback
  behavior was untested because 127.0.0.1 short-circuits the fallback
  path via the isPrivateAddress gate.
- Add a paired test pinning that the isPrivateAddress gate is preserved
  for loopback addresses (no SSE fallback fires).
- Drop `/adcp/mcp` from the discovery-hint examples; replace with
  `/v1/mcp` (more conventional in the wild).
- Loosen `initCount` assertion in the retry test to `>= 2` so the test
  doesn't couple to discovery probe-order internals.

Single-reviewer items addressed:

- JSDoc note on `connectMCPWithFallback`: unlike `connectMCP`, this helper
  does not attach `transport`/`client` to a thrown `UnauthorizedError`,
  so callers that need `transport.finishAuth(code)` should use
  `connectMCP` directly. Non-interactive providers work fine.
- Comment at `connectionCacheKey` flagging that any future caller threading
  `authProvider` through `withCachedConnection` must add an OAuth-identity
  dimension to the cache key to prevent cross-tenant collisions.
- Tighten changeset prose: the retry predicate is `StreamableHTTPError`
  specifically (not generic transient errors).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
let postCount = 0;
let getCount = 0;
globalThis.fetch = async (input, init) => {
const url = typeof input === 'string' ? input : input?.url ?? input?.toString();
@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing without merge after stepping back. The PR addresses a theoretical asymmetry (getAgentInfo lacks fallback) that no user has reported biting them, and the SSE-fallback test ended up mocked enough that it pins the wiring rather than real behavior.

Splitting the actually-useful pieces:

  • discoverMCPEndpoint error should hint at wrong-path registration #1234 (wrong-path discovery hint) — pulling into a smaller PR. Five lines, zero risk, real operator value when discovery fails on a host-root URL.
  • Retry-predicate widening (caught by the protocol reviewer here) — filing as a separate issue. instanceof StreamableHTTPError is too narrow; widening it would help every caller, not just getAgentInfo. That's a real reliability gap.
  • The asymmetry argument itself — closing getAgentInfo() lacks SSE fallback that every other code path has #1233 as won't-fix. connectMCP failing fast on transient StreamableHTTP errors is arguably correct behavior; "symmetry" alone doesn't justify adding fallback for a failure mode I couldn't reproduce.

Per @adcp project guidance: don't add error handling for scenarios that can't happen.

@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Acknowledged — clean decomposition. The discovery hint (#1234) and retry-predicate widening (separate issue) are both trackable independently now. Nothing further needed from triage here.


Generated by Claude Code

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.

discoverMCPEndpoint error should hint at wrong-path registration getAgentInfo() lacks SSE fallback that every other code path has

1 participant