Repository navigation
feat(broker): a hosted tool reaches the vendor, and a seat can see it (TASK-172 slice 3c-2) - #2005
Merged
Merged
Conversation
… its own (TASK-172)
`ToolConnection` becomes a discriminated union of a GitHub App connection and a
hosted-MCP Connection row, and `ToolDefinition` becomes a union of the matching
two members. A definition's `call` now declares the connection it can run
against, so the compiler refuses the reads that would otherwise be `undefined`
at runtime — and `providerConnection` rebuilds each member field by field,
because it used to narrow every connection to `{type, installationId, owner,
repo}`, which is exactly where a hosted connection's `entryId` would have
disappeared on its way to the provider.
`resolveHostedConnection` is the hosted half of `resolveConnection`: the row is
found by `_id` (a hosted grant's connection id IS the row's `_id` — there is no
installation id to reuse, so the TASK-148 class cannot arise by a second row
matching), it must be `connected`, its `config.entryId` must be the entry the
definition was projected from, and the TASK-148 creation-time guard runs
unchanged. It carries the row's `createdBy` as `ownerUserId` because
`resolveApprovalPodId` needs it to open the approval room for a seat-targeted
grant: without it a parked hosted write refuses `connection_mismatch` instead of
parking.
`hostedMcpToolDefinitions` builds the definitions themselves: each entry's
projection plus the `call` that resolves the row, fetches §4's credential
INSIDE the call (so listing a seat's tools never refreshes one, and a call that
never happens never spends one) and posts one JSON-RPC `tools/call` to the
entry's `resource` — the same URL RFC 8707 put in the authorization request, so
the audience the vendor validated is the audience it is presented to. Both JSON
and SSE replies are accepted, a 401/403 from the vendor is refused as
`credential_rejected` (only a new consent restores such a connection), and the
vendor's own tool-level error is returned as the result rather than thrown, so
the model reads the vendor's explanation.
Joined by NAME, not by index: `hostedMcpToolDefinitions` throws if a projection
names no pin, because an index join would silently pair a projection with the
wrong tool the first time `entryToolProjections` stops mapping one-to-one.
… (TASK-172) The broker could resolve a hosted connection but never ran a hosted tool: the seat's tool list is built from the GitHub record only, so a hosted grant projected zero tools, and the two dispatch sites looked the tool up in that same record. `allToolDefinitions` is now the one source both surfaces read — the runtime projection and `listToolsForGrant` — while `getToolDefinitions` stays the GitHub record `toolInstallables` validates a GitHub grant against, so a hosted name cannot pass a GitHub-only gate. Three arms carry the claims that a passing suite could otherwise pin wrongly: - The row's `config.entryId` must equal the entry the definition was projected from, so a grant on one vendor's row cannot run another vendor's tool. - A parked hosted write needs the row's `createdBy` as `ownerUserId`, because that is what opens the approval room for a seat-targeted grant. Without it the write cannot park, and the control arm asserts no room is requested and the vendor is never reached — the missing owner shows up as `approval_unavailable` (the park path's catch converts every failure), which is recorded as an observation rather than fixed here. - The GitHub record stays GitHub-only: `getToolDefinitions()` must NOT contain a hosted name, and `allToolDefinitions()` must. Two harness facts the arms taught, both recorded because they cost a run each: `assertGrantUsable`'s `tool` is optional (`listToolsForGrant` asserts the grant without naming one), and `findById(...).lean()` resolves to null rather than being null.
The arm asserted the code alone, and the tool's own `call` refuses the same mismatch one layer down with the same code — so a mutant that broke the broker-level guard survived the arm whose name claims it. The arm now asserts the message, which only the broker-level guard produces.
samxu01
force-pushed
the
kai/task172-catalogue
branch
from
September 29, 2026 14:01
d41b1fb to
fabf343
Compare
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.
Slice 3c-2 — the last of TASK-172's stack, cut from merged main now that #2001 and #2002 have landed. A hosted-MCP Connection could already be resolved by the broker (#1993/#1995) and minted into a grant (#2002). This is the slice where a hosted tool actually reaches the vendor, and where a seat's tool list contains it.
What changed
ToolConnectionandToolDefinitionare discriminated unions — a GitHub App connection and a hosted-MCP Connection row, with the matching two definition members. A definition'scalldeclares the connection it runs against, so the compiler refuses the reads that would otherwise beundefinedat runtime.providerConnectionrebuilds each member field by field. It used to narrow every connection to{type, installationId, owner, repo}— exactly where a hosted connection'sentryIdwould have disappeared on its way to the provider.allToolDefinitions()is the one source both surfaces read — the runtime projection (hostedBrokerToolsForRun) andlistToolsForGrant— whilegetToolDefinitions()stays the GitHub record thattoolInstallablesvalidates a GitHub grant against, so a hosted name cannot pass a GitHub-only gate.resolveHostedConnectionis the hosted half ofresolveConnection: the row is found by_id(a hosted grant's connection id is the row's_id, so the TASK-148 class cannot arise by a second row matching), it must beconnected, itsconfig.entryIdmust equal the entry the definition was projected from, and the TASK-148 creation-time guard runs unchanged. It carries the row'screatedByasownerUserId, becauseresolveApprovalPodIdneeds it to open the approval room for a seat-targeted grant.hostedMcpToolDefinitionsprojects each entry's pins: thecallresolves the row, fetches the credential inside the call (so listing a seat's tools never refreshes one, and a call that never happens never spends one) and posts one JSON-RPCtools/callto the entry'sresource— the same URL RFC 8707 put in the authorization request, so the audience the vendor validated is the audience it is presented to. Both JSON and SSE replies are accepted; a 401/403 from the vendor is refused ascredential_rejected(only a new consent restores such a connection); the vendor's own tool-level error is returned as the result rather than thrown, so the model reads the vendor's explanation.Claims the arms exist to stop pinning wrongly
config.entryIdmust equal the entry the definition was projected from, so a grant on one vendor's row cannot run another vendor's tool. The arm asserts the message, not just the code: the tool's owncallrefuses the same mismatch one layer down with the same code, so the code alone left a mutant alive in the arm whose own name claims it.createdByasownerUserId. The control arm asserts no room is requested and the vendor is never reached.getToolDefinitions()must NOT contain a hosted name;allToolDefinitions()must.hostedMcpToolDefinitionsthrows if a projection names no pin, because an index join would silently pair a projection with the wrong tool the first timeentryToolProjectionsstops mapping one-to-one.Recorded, not fixed here
connection_mismatchsurfaces asapproval_unavailable. That is how the arm above observes the missing owner; the conversion is pre-existing and outside this slice.listToolsForGrantresolves one connection per connection TYPE. Correct today — the TASK-148 unique index covers the pair, and v1 has at most one hosted row per definition — and a second hosted row for the same entry would need it revisited.Due with the FIRST vendor entry, not with this PR
HOSTED_MCP_ENTRIESis[]onmain, so no hosted row or grant can exist yet and none of this is reachable in production paths. The two preconditions @vera set for the first entry therefore stay open: (1)assertHostedMcpEntriesthrows when a read pin's own annotations carrydestructiveHint: true/readOnlyHint: false; (2) the same/^[a-z0-9-]+$/charset ontool.name. Non-blocking at the same gate:assessreturnsentryIdfrom its argument, and the in-flight promise is not cached. Carried forward from the 6g review: the cross-origin Connect XHR must send credentials, orSet-Cookieis dropped and every callback refusesinvalid_state.Evidence
(2, 30)on the rebased tree;tsc:checkexit 0--onto origin/main a7bb93a9(the branch's own three commits);range-diffshows content preservation; delta is 6 files, +1114/−42Two instrument findings, both recorded because each cost a run:
assertGrantUsable'stoolis optional, andfindById(...).lean()resolves tonullrather than beingnull. The ledger itself needed explicit occurrence selection on its anchors —resolveHostedConnectionandresolveConnectioncarry verbatim-identical nine-line guards, so a mutant aimed at the hosted copy was silently hitting the GitHub copy and reading as a survivor; selecting the occurrence and printing its match count turned it into a kill with no test change. And where a guard's shape is what makes the lines below it typecheck,if (false)is a compiler refusal, not a test gap — recorded as evidence, with a compiling sibling mutant added so the claim also has a runtime witness.