Repository navigation
feat(gateway): MCP gateway and Connect route for apps on hearth - #85
Merged
Merged
Conversation
lodge reads an app's hearth manifest and tool catalog (app.json `hearth` and `tools`), serves its RPCs to its frame at /app/<id>/connect/, and gives agents 1 MCP endpoint, /gateway/mcp, on lodge's OAuth server: each principal sees <id>_<tool> for what its grant holds, asks for more with request_access, and gets notifications/tools/list_changed when the owner approves or narrows the grant. Each call reads the grant again and sends a Connect call with Lodge-Principal and Lodge-Grant. ADR-0024; docs/specs/lodge-http.md (The MCP gateway, App calls); docs/specs/app-contract.md (Apps on hearth); docs/specs/oauth.md.
…ollow reloads The MCP SDK runs tool handlers on the session's context, so each call now registers its own context under its client, with a deadline at its token's expiry; a set of revoked clients closes the race between lodge's check and the registration. Calls to apps take connections from the routes' pool, so that 1 limit covers both. A handler's hash covers its operation, and a call resolves the current operation by its tool. 1 sync at a time spans its snapshot and its application. The MCP Inspector end-to-end test now reads the notification in Inspector's own transport (dev/mcp-e2e/tap.mjs) and checks that its session stays the same.
bketelsen
approved these changes
Nov 16, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agents reach apps on hearth through 1 MCP endpoint of lodge's,
/gateway/mcp, on lodge's OAuth server (ADR-0024, Proposed). The frame of an app on hearth calls its RPCs at/app/<id>/connect/.app.jsonaccepts"hearth": "manifest.json"and"tools": "tools.json"(the catalog in the shape of an MCPtools/listresult). lodge reads the manifest's operations and checks the catalog against them. An unknown hearth format major disables the app with a reason that names both versions.gatewayis a reserved app ID. An app on hearth is 404 on/mcp/<id>./gateway/mcp(internal/mcpgw, the only package that imports the Go MCP SDK v1.8.0): 1 MCP serverlodgeper principal, stateful sessions bound to the OAuth client,tools.listChanged: true. A principal sees<id>_<tool>for each agent operation whose permission its grant holds, plusrequest_access. Hints come from the operation's effect.Lodge-Caller: principal,Lodge-PrincipalandLodge-Grant. A call outside the grant (listed or not) is the tool errorinsufficient_scope: …, and the app sees nothing.request_access(app, items)queues a consent request and returns its link. An approval, the grants page's new per-item Remove, or a reload re-computes the tools; open sessions getnotifications/tools/list_changedand stay open. A revocation ends the client's requests and streams.resource_metadata. A live token without scopemcp: 403 witherror="insufficient_scope"(oauth.ErrScope).internal/hearthtestruns hearth v0.1.0's example app (notes-lite, copied: the example is its own module) for the Go tests and the development build (dev/hearthapp).make mcp-e2e(nsl) drives the gateway with pi-mcp 1.5.2 (the MCP client of Pi Pocket's mcp module) and with MCP Inspector 2.15.0'smcpdo, both pinned: sign-in,request_access, approval,list_changed, calls.Specs: lodge-http.md (The MCP gateway; App calls), app-contract.md (Apps on hearth), oauth.md; roadmap Phase 8; site guide
configure.md.Risk tier
Risk tier: 3 —
risk:high: new auth surfaces. Matched paths, and why each change is safe:internal/mcpgw/**(new, L1): lodge's checks run before it (Host, no Origin, method, peer identity, OAuth token with scopemcp, no upgrade); it trusts only the caller lodge put in the context. Sessions are bound to the client (TokenInfo.UserID): another client's token on a session is 403 (test). Every call reads the grant again, so a narrowed grant refuses the next call (tests).internal/gateway/{gateway,kinds,proxy,connect}.go(L1):/gateway/mcpand/app/<id>/connect/are new routes with their own ordered checks (Origin is lodge's,Sec-Fetch-Sitesame-origin, POST only, every identity check, operations exposed touionly, content type, a login with@, 4 MiB body). The proxy deletes every clientLodge-*header (test)./mcp/<id>only gets stricter (404 for an app on hearth).internal/oauth/**(L1):Checknow reports a missing scope asErrScope(wasErrInvalid; both refuse) and returns the expiry;RemoveGrantItemnarrows a grant in 1 transaction, from the grants page with its CSRF token (403 without), admin only as before.internal/apps/apps.go(L1): reads and bounds the operations and the tool catalog (1 MiB, 128 tools, names, schemas of type object); any break disables only that app.kit/manifest/**(L1): additive:toolsmember and the reserved IDgateway.cmd/lodge/main.go(L1): wires the gateway and the OAuth hooks; no admission change.internal/repocheck/**(L2): new import-boundary tests (MCP SDK only ininternal/mcpgw; hearth only ininternal/hearthtestanddev/hearthapp).Makefile(L2):e2e-buildbuildslodge-hearthapp; newmcp-e2etarget (not in a gate: it needs the network)..github/risk-paths.json(L2): addsinternal/mcpgw/**(L1) andconnect.go.Docs housekeeping
TEMPLATE.md(ADR-0024)docs/README.mdVerification
make cigreen on the host and nsl (verify, race, cross, client-check, ui-check, shell-check)make vulncheck: No vulnerabilities found (both modules)make mcp-e2e(nsl): pi-mcp — 401 with resource metadata, sign-in,request_accessonly, approval,list_changedon the same session, new tools, calls, a folder outside the grant refused by the app; Inspector — sign-in,listChangedcapability, the change on the open session (lodge'smcp tools changed … sessions=1), new tools, a callkit/manifestchange is additive (a new optional member and 1 more reserved ID)Cross-review
Reviewer
openai/gpt-6.1-sol; codersdeepseek/deepseek-flash(Go code and tests) andanthropic/claude-opus-5-5(docs,dev/mcp-e2e/). Base16b6ff6e2d2b1d1bad9ab3c56207a25e1c224073.d476b58b028cc3ab7bebe621d4d0e38bce956a08, in 5 batches (gateway/mcpgw/oauth/wiring; loaders, scripts and governance; the 2 gateway test files; the other tests; docs). Excluded from line-by-line review:dev/mcp-e2e/pnpm-lock.yaml,go.sum, and the notes-lite copy ininternal/hearthtest/notelite/(compared read-only with hearth v0.1.0). Not ready, 5 blocking: (1) a revocation or a token expiry did not cancel a tool call in flight (the SDK runs handlers on the session context); (2) MCP calls had their own app pool, past the 128-connection limit; (3) a reload that kept a tool's bytes kept a handler with the old operation; (4) an older sync snapshot could be applied after a newer one; (5) the Inspector test read lodge's log, not what Inspector received.c5ed735and47e8832: per-call context registered under the client with a revoked-client set; 1 shared app transport (gateway.NewAppTransport,Config.Transport,mcpgw.Options.Transport); the definition hash covers the operation and a call resolves the current one; a per-server sync lock;dev/mcp-e2e/tap.mjsrecords the messages in Inspector's own transport, and the test asserts the notification on Inspector's session and the same session afterwards.47e8832: findings 1–5 fixed; 1 new blocking (6): the late-revocation 401 lacked the challenge andConnection: close. Fixed in5fbe8fc(Caller.Refuse, lodge's own 401).5fbe8fc3a1207619adc349ae53f47611febdc699: Ready, Blocking: none.Correction records:
.memory/corrections/2026-11-16-pr-85-gateway-calls-follow-revocation-and-reloads.json,.memory/corrections/2026-11-16-pr-85-late-revocation-answers-as-lodge.json.Revert tests
In a scratch worktree from the PR head, with the tests kept, each fix reverted alone:
srv.AddReceivingMiddleware(s.unlistedCall))TestMCPGatewayGrantNarrowing,TestMCPGatewayUngrantedToolByName:unknown tool "notelite_create_note"g.callContextincall)TestMCPGatewayRevokeEndsACall,TestMCPGatewayExpiryEndsACall: the app's request context did not ends.syncMu)TestSyncNewestWins: final tools lacknotelite_create_notedefinitionHashTestMCPGatewayToolFollowsItsOperation: no re-registration after the reloadgateway.NewusingConfig.TransportTestAppTransportIsShared: the third call reached the app pastMaxConnsPerHostCaller.RefusecallTestMCPGatewayRevokedAfterTheCheck: no challenge, connection keptOnGranthook (cmd/lodge/main.go), withmake mcp-e2enotifications/tools/list_changed: nothing within 10000 ms; Inspector:Inspector received no notifications/tools/list_changed on session … within 10000 msCommand form:
go test -count=1 ./internal/gateway/ -run '<test>'(and./internal/mcpgw/); for the last row, the revertedbuild/lodge-e2ewithdev/mcp-e2e/run.shin nsl.