Skip to content

fix(mcpbroker): address the gateway call review follow-ups - #2831

Merged
ChrisJBurns merged 5 commits into
mainfrom
fix/gateway-call-review-followups
Nov 17, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
fix/gateway-call-review-followups

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2818, from Jakub's review there. Refs #2536.

Summary

  • Connect link (internal/adapter/mcp/gatewaycall.go): the link from a -32042 answer reaches the model, and a backend could add words to it through a space or a Unicode format character such as a bidi override. It is now kept only if it holds just the characters RFC 3986 allows and is unchanged when parsed again. The origin rule stays with Connect provider accounts at the embedded gateway #2537.
  • already_sent text: no longer says the outcome is unknown, because the call may still be in flight or have completed.
  • Credential renewal (internal/agentcredential): the shared renewal runs apart from the lookup that started it, bounded by its own timeout. One run's cancellation no longer fails another run's call, and every lookup still stops waiting when its own context ends.
  • Slow registration: a registration is checked against the time it returns, so a credential that expired during a slow registration is refused, at run entry and on renewal.
  • Cancellation wait: a call that returned before its context ended no longer waits five seconds for a cancellation notice the SDK won't send.
  • Send-once key (internal/adapter/mcpbroker/sendonce.go): claims are keyed by operation, holding the argument hash they were claimed with. Before, a resumed call whose arguments a hook rewrote was a new claim and was sent again; the design ("Pauses and restart") never sends a recorded operation again. It gets already_sent instead.
  • Claim order: a gateway call is claimed before it is authorized, so a duplicate is refused without a gateway token being issued, and an ID-JAG and decision recorded, for it. A call refused authorization was not sent and its claim is released. The design requires the claim before the first dispatch and doesn't order it against authorization; MCP broker authorizes gateway calls and sends them to the configured gateway #2536 stated the old order.

Deferred: the delete-then-reattach race in the send-once cleanup is now a requirement on #2730.

Testing

  • New tests, each failing without its fix:
    • connect links with a space, injected words, a bidi override and non-ASCII are refused;
    • a renewal outlives the first lookup's cancellation and answers the waiting lookup;
    • a registration that expired while it ran is refused;
    • a resumed call with the same or rewritten arguments is refused before authorization, and the gateway sees one tools/call;
    • the record refuses an operation claimed with other arguments, and only the claim's own arguments release it.
  • The cancellation-wait guard has no test: the window between the reply and the cancellation can't be hit deterministically.
  • task lint: 0 issues.
  • Race tests pass for mcp, mcpbroker, agentcredential and adapter/server, and the cmd/mecak8s identity broker slice test passes.
  • task test:race: everything passes except two tests that also fail on origin/main in this environment: a unix socket path too long in cmd/mecated, and no bash in environment/microvm/gitexec.
  • go run ./cmd/mecademo shows the tool call, the permission ask and approval, and the result.

API compatibility

Assessment: compatible, no major bump, no feature identifier. The changes are reachable only on gateway routes, which production doesn't configure until #2533. There, one model-visible tool-error text changes (already_sent, same code), a resumed call with rewritten arguments now gets already_sent instead of being sent, and a connect link with characters outside RFC 3986 is dropped from the connection_required text. No wire schema, request-level error or stored data changes. Upgrade implications: none.

ChrisJBurns and others added 3 commits November 17, 2026 15:26
- A connect link reaches the model only if it holds just the characters
  RFC 3986 allows and is unchanged when parsed again, so a backend cannot
  add words to it through a space or a Unicode format character.
- The already_sent text no longer claims the outcome is unknown: the call
  may be in flight or have completed.
- A credential renewal runs apart from the lookup that started it, bounded
  by its own timeout, so one run's cancellation no longer fails another
  run's call; every lookup still stops waiting when its own context ends.
- A registration is checked against the time it returns, so a credential
  that expired during a slow registration is refused.
- A call that returned before its context ended no longer waits five
  seconds for a cancellation notice the SDK will not send.

Co-authored-by: Mecatl <[email protected]>
The send-once record keyed claims by operation and argument hash, so a
resumed call whose arguments a hook rewrote was a new claim and was sent
again; the design never sends a recorded operation again. Claims are now
keyed by operation, holding the hash they were claimed with, and an operation
claimed with any arguments refuses another claim.

A gateway call is now claimed before it is authorized, so a duplicate is
refused without a gateway token being issued and recorded for it. A call
refused authorization was not sent and its claim is released.

Co-authored-by: Mecatl <[email protected]>
Comment thread internal/adapter/mcp/gatewaycall.go Resolved
The SDK sends notifications/cancelled exactly when CallTool returns the
context's error. A gateway error or closed connection followed by a late
cancel sends nothing, so waiting for the notice then timed out.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns enabled auto-merge (squash) November 17, 2026 21:43
@ChrisJBurns
ChrisJBurns merged commit e056c29 into main Nov 17, 2026
43 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/gateway-call-review-followups branch November 17, 2026 22:44
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

2 participants