Skip to content

feat(mcpbroker): carry the vMCP resource on Gateway - #2887

Merged
jhrozek merged 3 commits into
mainfrom
feat/identitybroker-gateway-resource
Nov 20, 2026
Merged

jhrozek merged 3 commits into
mainfrom
feat/identitybroker-gateway-resource

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Summary

Part of #2728. Removes the "Gateway carries no vMCP resource" shortcut.

  • mcpbroker.Gateway gains Resource(): the vMCP's OAuth protected-resource identifier, the audience AS-2 issues gateway tokens for. It is kept separate from Endpoint() (where requests are sent); the embedded gateway sets both to the same URL today.
  • mcpbroker.Process.GatewayEndpoint is replaced by Process.Gateway.
  • At startup, checkGatewayResource now compares AS-2's resource with Gateway.Resource() rather than the endpoint, and returns errGatewayIsNotAS2Resource on a mismatch. Runtime.checkGateway also requires a non-empty resource.
  • The ID-JAG target is still derived before the gateway exists. The identity broker (AS-1) has to be built before the MCP broker process, because that process needs the identity broker's service and client key set. The startup checks still tie the three values together: ID-JAG target = AS-2 resource (errAS2IsNotIDJAGTarget), and AS-2 resource = gateway resource.

Tests

  • TestCheckGatewayResource: a gateway whose resource differs from AS-2's is refused. A gateway whose endpoint differs but whose resource matches is accepted. A gateway without an AS-2 is refused.
  • TestToolHiveProcessInstallsTheEmbeddedGateway: the embedded gateway's Resource() is AS-2's resource, and Process.Gateway is the installed gateway.
  • TestBuildMCPBrokerRefusesAS2OtherThanTheIDJAGTarget is unchanged and passes.
  • task lint passes.

API compatibility

No remote-observable change. The changes are to internal Go types and a startup error message. No wire, config or user-visible behaviour changes.

Local gates: task lint and the offline demo pass; the root and engine module race suites show only the failures plain origin/main shows on this machine (microVM, Helm chart, and mecatui/mecated environment tests).

Gateway gains Resource(), the vMCP's OAuth protected-resource identifier
that AS-2 issues gateway tokens for, kept separate from Endpoint (where
requests are sent). The embedded gateway sets both; they are equal today.

Process exposes the installed Gateway instead of GatewayEndpoint, and
startup now refuses a gateway whose Resource(), not its endpoint, differs
from AS-2's resource (errGatewayIsNotAS2Resource). Runtime.checkGateway
also requires a non-empty resource.

The ID-JAG target AS-1 is built with stays derived from the callback URL:
the identity broker (and so AS-1) is built before the MCP broker process
that creates the gateway, and that process needs the identity broker's
service and client key set. The existing cross-check
(errAS2IsNotIDJAGTarget) plus this one tie the ID-JAG target, AS-2's
resource and the gateway's resource together at startup.

No user-visible or wire API change.

Part of #2728

Co-authored-by: Mecatl <[email protected]>
jhrozek and others added 2 commits November 20, 2026 12:17
The embedded gateway's endpoint was still built from the issuer with a
second as2Resource(issuer) call. Take it from the resource instead, so it
is no longer built from the issuer, as #2728 asks.

The gateway's resource and AS-2's resource still come from the same
variable, so the startup check that they match cannot fail for the
embedded gateway. Record that as a Shortcut until #2812 builds the
gateway from a gateway entry with its own vMCP resource.

Co-Authored-By: mecatl <[email protected]>
checkGateway gained a non-empty Resource() check with no test. Cover it,
and the existing endpoint, HTTP client, authorizer, and credentials
checks, with one table test that expects ErrInvalidCatalogue for each
missing part.

Co-Authored-By: mecatl <[email protected]>

@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.

Hi Chris, I reviewed this while you're away and pushed two small commits on top of yours. The PR itself is good: Resource() on Gateway and the startup check against it have the shape the external gateway needs. Here is what I changed and why.

1. The embedded endpoint is now taken from the resource (5ac8396)

#2728 asks for "the vMCP resource on Gateway, so the embedded endpoint is no longer built from the issuer". The PR added Resource(), but toolhive_process.go still had endpoint := as2Resource(issuer). So the endpoint was still built from the issuer, while the Shortcut comment that recorded this was deleted.

Also, the embedded gateway's resource and AS-2's resource come from the same resource variable, so checkGatewayResource compares a value with itself and cannot fail today.

The change:

  • endpoint := resource, so the endpoint is no longer built from the issuer.
  • A Shortcut: comment at that line: the embedded gateway's resource is AS-2's resource by construction, so the startup check cannot fail; removed by #2812 (gateway built from a gateway entry with its own vMCP resource). That keeps a marker in the code until the check does real work.

I checked the stack: #2888 does not touch this file, and its listing dials Endpoint() and never reads Resource(), so it is not affected.

2. A test for the new empty-resource check (5c2859e)

Runtime.checkGateway gained Resource() == "" with no test, and its other checks had none either. TestCheckGatewayRefusesAnIncompleteGateway covers a missing endpoint, resource, HTTP client, authorizer, or credentials. I confirmed it fails when the resource clause is removed.

Notes for #2812 (no change here)

Two things become real once a gateway runs outside the Mecatl process. I will put them on #2812:

  • Nothing proves that a configured endpoint serves the configured resource, so a wrong endpoint would receive the gateway token. mcp.DiscoverDirectIssuer already does almost all of this check.
  • The token's resource comes from the identity broker's AS-2 copy, while the request goes to the MCP client's gateway. Only the startup check in buildBundledMCPBroker ties them together.

Lint on mcpbroker is clean, and the focused gateway tests in mcpbroker and app pass. #2888 will need a rebase onto this branch; it should be clean.

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