Skip to content

feat(mcp): trigger lazy auth on JSON-RPC body errors - #3

Merged
lorem-dev merged 7 commits into
developfrom
feat/json-rpc-lazy-auth
May 15, 2026
Merged

lorem-dev merged 7 commits into
developfrom
feat/json-rpc-lazy-auth

Conversation

@lorem-dev

@lorem-dev lorem-dev commented May 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Extends lazy auth-header resolution in locksmith mcp run --url to fire on JSON-RPC body errors (response.error or result.isError: true), not only on HTTP 401/403.
  • One resolve attempt per session, shared between transport (HTTP status) and proxy (body) triggers via a new authState. If retry also fails, the response is forwarded to the AI client unchanged.
  • Detection looks only at structural fields - no keyword matching against result.content[].text. Notifications and id:null responses never trigger.

Implementation

  • internal/mcp/jsonrpc_error.go - inspectResponse / extractID helpers
  • internal/mcp/auth_state.go - shared authState with resolveOnce
  • internal/mcp/transport_http.go / transport_sse.go - route auth retry through shared state
  • internal/mcp/proxy.go - proxyState id-map + body-level retry handshake (with concurrent in-flight support)

Test plan

  • TestInspectResponse + TestExtractID table-driven coverage
  • TestAuthState_ResolveOnce_* (single, concurrent, resolver-fails, nil-resolver)
  • TestStreamableHTTP_BodyResolveThen401_NoSecondResolve - cross-layer guarantee
  • 8 new TestProxy_* scenarios in proxy_retry_test.go (success, resolve fail, send fail, retry-also-errors, concurrent ids, only-first-error, after-attempted no-parse, notification not tracked)
  • All existing MCP tests adapted to new authState constructor and passing under -race
  • make verify green

@lorem-dev
lorem-dev merged commit 6becdfc into develop May 15, 2026
3 checks passed
@lorem-dev
lorem-dev deleted the feat/json-rpc-lazy-auth branch May 15, 2026 20:50
@lorem-dev
lorem-dev restored the feat/json-rpc-lazy-auth branch May 22, 2026 22:30
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.

1 participant