Skip to content

External gateway: Gateway implementation, operator setup, and end-to-end test #2812

Open

Description

@ChrisJBurns

Depends on: #2728 (the Gateway interface, with tools listed over HTTP), #2538 (keys and gateway entries), #2539 (pre-approval part), #2811 (fixture on the pinned ToolHive version); the "to file" row in "Phase 3, Track: ToolHive — The remaining ToolHive changes for audit, sign-out, and schedules" (#2570) for subject mode and approval settings in run config and the CRD

Problem

Only the embedded gateway implements the gateway interface, and the broker knows of only one gateway. An external gateway's administrator has no way to get the broker's keys or setup values. Nothing shows that Mecatl works with a gateway it does not run, so external mode would first run in a customer deployment.

Implements

Scope

The Gateway implementation PR lands first.

  • Gateway: HTTP only, built from the gateway entry (MCP endpoint, vMCP resource, AS-2 issuer, token endpoint). Keys and gateway entries for the identity broker #2538's entry has no MCP endpoint field: this ticket adds it, and an optional in-cluster address if the question below settles on one. Keys and gateway entries for the identity broker #2538's token_endpoint is AS-2's advertised endpoint, never a dial address. Tool calls and listing (List gateway tools with a broker-issued token #2729) use the same code as the embedded gateway. The gateway must serve MCP 2025-11-25 (initialize), which the gateway paths pin; a gateway that serves only 2026-07-28 needs Support MCP 2026-07-28 on the gateway call and listing paths #2917.
  • Several gateways: the broker holds a list of gateway entries. Check 6 picks the gateway whose routed servers include the call's server, and server names are unique across gateways. Binding is keyed by the AS-2 issuer. Both brokers pick the same gateway and refuse a token whose resource names another one.
  • Keys: the broker client key set is given to administrators as an inline JWK set they can copy. Rotation adds and removes the key at each external gateway, and restarts the gateway if ToolHive still reads the key set only at startup.
  • Operator guide: what the gateway's administrator receives: AS-1's issuer, client mecatl and its keys, the subject claim AS-2 must also use, and single use for AS-1's issuer (recommended). What comes back: the AS-2 issuer and the vMCP resource. Also the rotation steps.
  • Helm: egress to each external gateway's AS-2 and vMCP.
  • Fixture and test: a separately deployed ToolHive gateway in kind, set up as the administrator configuration describes. It uses the approval-record subject mode, pre-approval, per-user connections, and operator-supplied broker keys (generated keys change on every restart). A second source issuer has no shared IdP. Both gateways run the pinned ToolHive version. The approval-link cases are added when Users and administrators approve Mecatl at an external gateway #2539's link part lands.

Decide before starting

Does the broker call a gateway's public token endpoint through an ingress, which needs DNS, CA trust, and hairpin routing inside the cluster? Or does the gateway entry carry an optional in-cluster address, with the issuer and aud kept public? The same choice applies to the embedded gateway after #2807.

Done when

In CI, the MCP client reaches the external fixture through the same code it uses for the embedded gateway, and tool calls and listing work against both. These cases pass: pre-approval, an unapproved user, no shared IdP, revocation, and connected calls that use only the user's own credential. A user without a connection is asked to connect, with the gateway's link, and the call continues after they connect, against an external gateway that sends the chosen signal ("Ask users to connect a provider before the call (authorization pending)" (#2592)).

Earlier notes: #2540 (closed, merged here).

Activity

  1. changed the title [-][Phase 3] External gateway implementation of the Gateway interface[/-] [+]External gateway: Gateway implementation, operator setup, and end-to-end test[/+] on Nov 18, 2026
  2. ChrisJBurns commented on Nov 18, 2026

    @ChrisJBurns
    ContributorAuthor

    Design decision for this ticket: Does a gateway entry carry an optional in-cluster address the broker dials, while the issuer and aud stay public, or does the broker always use the public token endpoint through an ingress? The same applies to the embedded gateway once it is its own deployment.

    Where it goes: mcp-gateway-modes.md: Gateway administrator configuration.

    Decide it when this ticket is picked up, and record the answer as a small design edit (reviewed by the design's author) before or with the ticket's first PR.

  3. jhrozek commented on Nov 20, 2026

    @jhrozek
    Contributor

    Notes from the review of #2887 for the external gateway work. None of these is a bug today; they become real once a gateway runs outside the Mecatl process.

    Prove that the endpoint serves the resource

    Today the gateway token can only reach the embedded vMCP: the in-process HTTP client refuses every URL except the endpoint (gatewayInProcessClient, internal/app/mcp_broker_construction.go). Once the gateway is built from a gateway entry, the endpoint and the vMCP resource are two operator-configured strings, and the startup check only compares the resource with AS-2's resource. Example: endpoint https://evil.example/mcp, resource https://gateway.example/mcp. The check passes, and every call sends a bearer token with audience https://gateway.example/mcp to evil.example.

    Proposal: at startup, fetch the gateway's RFC 9728 metadata and require its resource to equal Gateway.Resource() exactly.

    • Reuse mcp.DiscoverDirectIssuer (internal/adapter/mcp/direct_discovery.go). It already requires an exact HTTPS resource, refuses redirects on the probe, requires the metadata's resource to equal the URL exactly and to name exactly one authorization server, caps the body, and then fetches that server's metadata. So one call also checks the entry's AS-2 issuer and token endpoint.
    • ToolHive's discovery.FetchResourceMetadata (pkg/auth/discovery) is not a good fit. It only checks that resource is not empty ("For now we just check it's not empty"), allows plain HTTP for localhost, follows same-host redirects, and logs through the default slog.
    • The ToolHive vMCP already serves the metadata with the configured resource (auth.NewAuthInfoHandler), so nothing is needed on the gateway side.
    • If the gateway entry gets a separate in-cluster address (the open question in this issue), the check has to fetch through that address while verifying TLS for the resource's host. DiscoverDirectIssuer fetches from the resource's own address, so that case needs a small transport on top.

    Keep the token's resource tied to the gateway it is sent to

    There are two copies of the vMCP resource. The MCP client has mcpbroker.Gateway.Resource(), and the identity broker has identitybroker.GatewayAS2.Resource. At call time the token is requested for the identity broker's copy (identitybroker/authorize.go, IssueIDJAG and Redeem both use as2.Resource), but it is sent to the MCP client's Gateway.Endpoint() (mcpbroker/gateway_call.go). The only place the two copies are compared is checkGatewayResource in buildBundledMCPBroker. BindGatewayAS2 checks only that the fields are non-empty.

    Today both copies come from the same process.AS2, so they cannot differ. With several gateways built from gateway entries, a token for gateway A could be sent to gateway B if gateways are built or AS-2 is bound outside buildBundledMCPBroker.

    Proposal: enforce the rule where binding and gateway selection happen, not only at bundled startup. Either check inside BindGatewayAS2 against the gateway entry, or have the authorizer take the resource from the gateway the call is sent to. This is the same rule this issue states: "Both brokers pick the same gateway and refuse a token whose resource names another one."

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions