Skip to content

feat(mcpbroker): list gateway tools over HTTP, per server, failing closed - #2888

Merged
jhrozek merged 1 commit into
mainfrom
feat/identitybroker-gateway-listing
Nov 20, 2026
Merged

jhrozek merged 1 commit into
mainfrom
feat/identitybroker-gateway-listing

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Summary

PR 2 of #2728, stacked on PR 1 (feat(mcpbroker): carry the vMCP resource on Gateway).

mecak8s's MCP client now lists the gateway's tools one server at a time, and the catalogue fails closed when a configured server's listing fails or is empty.

  • Gateway.ListTools(ctx, server, credential oauth2.TokenSource) ([]GatewayTool, error) (internal/adapter/mcpbroker/gateway.go). It returns the tools the gateway routes to server, under their names on that server, with description, input schema, and read-only hint. The credential is a parameter so List gateway tools with a broker-issued token #2729 can swap the workspace-enrollment credential for a broker-issued token.
  • mcp.ListGatewayTools (internal/adapter/mcp/gatewaylist.go) runs an MCP tools/list (every page) over its own session. It sets the bearer only in Authorization, follows no redirects, and returns ErrGatewayList without the gateway's answer.
  • embeddedGateway.ListTools filters the vMCP's aggregate listing by its {workload}. routed-name prefix. This is a marked shortcut that List gateway tools with a broker-issued token #2729 removes (toolhive#7062). Name parsing stays inside the embedded gateway.
  • Runtime.discoverBackend (authenticated_discovery.go) is used by both the enrollment freeze and the lazy bundle refresh:
    • For a gateway route (gateway installed and backend in GatewayCalls.Servers), it calls Gateway.ListTools with the enrollment credential.
    • Otherwise it calls the existing in-process QueryAuthenticatedCapabilities, unchanged.
    • Gateway results go through the existing neutralCapabilities / neutralToolDefinition / containsPrivate* checks, scrubbing for the exact bearer sent.
    • A listing error aborts the freeze with errGatewayListingFailed, and an empty listing with errGatewayListedNoTools. Both wrap ErrAuthenticatedDiscovery. The per-backend diagnostic reason is discovery_failed or no_tools, keyed by backend_index with no name and no token.

Tests

  • TestEmbeddedGatewayListsOnlyTheServersTools uses a real ToolHive process and vMCP, reached in process, with two anonymous backends. Each server's listing returns only its own tools, unprefixed, with schema and read-only hint. A protected backend with no upstream credential lists nothing, and a token the vMCP refuses returns ErrGatewayList.
  • TestFreezeListsGatewayRoutesThroughTheGateway: the gateway route is listed through the gateway with the enrollment credential, and the non-gateway backend still goes through the in-process query. The route is broker-routed and maps back through Route.
  • TestFreezeFailsClosedOnAGatewayListing covers a listing error, no tools, a duplicate, a private string in the description, a private string in the schema, an invalid name, invalid UTF-8, and a missing schema. In each case the freeze fails, nothing is published, and the diagnostic reason is right.
  • TestGatewayListingNeverLeaksTheBearer uses gateways that echo the bearer in a 401 body, a 500 body, and a tool description. Neither the freeze error, the ListTools error, nor the diagnostics carry it. Positive control: the gateway received it in Authorization.
  • The existing discovery and catalogue tests pass unchanged.

Run:

  • go test ./internal/adapter/mcpbroker/... ./internal/adapter/mcp/... -count=1
  • go test ./internal/app/ -run 'MCPBroker|IdentityBroker|Gateway|AS2|IDJAG' -count=1
  • go test ./internal/adapter/server/ -run MCPBroker -count=1
  • go test ./cmd/mecak8s/ -run Gateway -count=1
  • go test -race on the new tests
  • go vet on the touched packages
  • task lint

API compatibility

Assessment: no wire change, and no major or feature change.

  • Where it applies: only identity-broker-on gateway routes, which are backends listed in GatewayCalls.Servers. The only source of those servers is app.Config.IdentityBrokerGatewayServers, which is test-only; no production path or settings key sets it (internal/app/build.go).
  • Flag off: behaviour is unchanged. Without a gateway, or for a backend that isn't a gateway route, catalogue discovery takes exactly the existing in-process path and returns the same errors and diagnostics.
  • Flag on: the catalogue a session sees has the same shape (mcp__<server>__<tool>). Only where the tool metadata comes from changes, and the freeze now fails rather than freezing without the server. An enrollment failure still surfaces as the existing failed enrollment status, with no new error text on the wire.
  • Go source: the Gateway interface gains ListTools. Its only implementations are internal (embeddedGateway and test doubles).
  • Stored data: unaffected.
  • Upgrade implications: none.

The per-server, fail-closed listing rule is being recorded in the agent identity design in a separate docs PR.

@jhrozek
jhrozek force-pushed the feat/identitybroker-gateway-listing branch from 7425a51 to 6fd8e1b Compare November 20, 2026 11:44
Base automatically changed from feat/identitybroker-gateway-resource to main November 20, 2026 12:24
…osed

With a gateway installed (identity broker on, gateway servers configured),
the authenticated catalogue no longer discovers a gateway route's tools in
process. It asks the gateway for one server's tools at a time through the new
Gateway.ListTools, which takes the bearer as a parameter so #2729 can pass a
broker-issued token in place of the workspace-enrollment credential used today.

The embedded gateway sends an MCP tools/list to the vMCP over its HTTP client
(every page, redirects refused) and keeps only the tools the vMCP routes to
the server, under their names on that server. Filtering by the vMCP's
`{workload}.` prefix is a marked shortcut, removed by #2729.

Listing fails closed: an error, or no tools, for a configured gateway server
aborts the catalogue freeze, rather than freezing without that server. Every
listed tool passes the same admission checks as in-process discovery
(attribution, duplicates, names, UTF-8, size, object schema, and the bearer
scrub). Listing errors never carry the bearer or the gateway's answer.

Non-gateway routes, and every route with the flag off, keep the in-process
discovery path unchanged.

Part of #2728

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the feat/identitybroker-gateway-listing branch from 6fd8e1b to f9d5c17 Compare November 20, 2026 12:27

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving so this can land while you're away. The design is right: listing behind Gateway.ListTools over HTTP, one server at a time, failing closed.

We'll send a follow-up PR with fixes we found in review, rather than pushing to your branch:

  • Bound the gateway tools/list: it followed nextCursor with no repeated-cursor check, no page, tool, or byte cap, and no overall deadline (the embedded in-process client has no timeout). The fix reuses the bounded loop and CandidateListBudget the ordinary MCP listing already uses, adds one timeout for the whole listing, and makes the limits tunable through GatewayCalls.ListLimits.
  • Keep a gateway tool's output schema in GatewayTool, which #2728's result check will need.
  • Gateway.ListTools takes an identitybroker.Token instead of an oauth2.TokenSource, so the bearer sent is the one checked for, as on the call path.
  • Direct tests for ListGatewayTools: every page, the limits, the bearer on every request, and no redirects.
  • The comment on gatewayProtocolVersion now gives the real reason for the pin: on 2026-07-28 the vMCP answers a call needing URL elicitation with an input_required result, which classify would read as completed. A tracking issue for moving the gateway paths to 2026-07-28 will follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants