Repository navigation
feat(mcpbroker): carry the vMCP resource on Gateway - #2887
Conversation
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]>
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
left a comment
There was a problem hiding this comment.
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.DiscoverDirectIssueralready 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
buildBundledMCPBrokerties 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.
Summary
Part of #2728. Removes the "Gateway carries no vMCP resource" shortcut.
mcpbroker.GatewaygainsResource(): the vMCP's OAuth protected-resource identifier, the audience AS-2 issues gateway tokens for. It is kept separate fromEndpoint()(where requests are sent); the embedded gateway sets both to the same URL today.mcpbroker.Process.GatewayEndpointis replaced byProcess.Gateway.checkGatewayResourcenow compares AS-2's resource withGateway.Resource()rather than the endpoint, and returnserrGatewayIsNotAS2Resourceon a mismatch.Runtime.checkGatewayalso requires a non-empty 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'sResource()is AS-2's resource, andProcess.Gatewayis the installed gateway.TestBuildMCPBrokerRefusesAS2OtherThanTheIDJAGTargetis unchanged and passes.task lintpasses.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 lintand the offline demo pass; the root and engine module race suites show only the failures plainorigin/mainshows on this machine (microVM, Helm chart, and mecatui/mecated environment tests).