First-party MCP servers on the dev stack (beta-dev)
How upsquad-memory-mcp and upsquad-knowledge-mcp become reachable as
first-party upstreams of the team gateway (/mcp/team/{unit}) on the dev
compose stack, which is what beta-dev runs. Introduced by #4204. The issuer and
audience cutover (#4210) is in the same PR and is described at the end.
What has to be true
A team-gateway tools/call reaches a first-party server with a platform bearer
that server accepts only when ALL of these hold:
| # | Fact | Where it lives | Who sets it |
|---|---|---|---|
| 1 | The server's TOKEN_AUDIENCE equals what FirstPartyMinter signs: <base>/mcp/upsquad-memory / <base>/mcp/upsquad-knowledge | docker-compose.dev.yml, derived from MCP_GATEWAY_PUBLIC_BASE_URL, which defaults to PLATFORM_ISSUER | compose (tracked) |
| 2 | The server's TOKEN_ISSUER equals the iss the orchestrator and context-engine stamp | same file, ${PLATFORM_ISSUER} | compose (tracked) |
| 3 | context-engine's MCP_BUILTIN_*_ENDPOINT byte-equals the registered mcp_servers.url | same file; dotted *.mcp.internal aliases | compose (tracked) |
| 4 | An mcp_builtin_registrations row maps that server to its target | database | operator, once: this runbook |
| 5 | The team's binding is approved and private-pinned. The server is in the team's effective MCP membership (orgunit.Store.EffectiveMCPServerIDsForUnit, the gateway's own seam): no soft-deleted or non-grant binding, and no withhold at the team or any ancestor. A live allow_private egress row exists for the host | database | the seed (new onboarding), or already present |
| 6 | The stored tool_schema lists the server's tools. The team gateway advertises ONLY the stored schema (PgTeamResolver then Aggregate), so an unprobed row exposes no tool, and no tools/call can select it | database | the seed's egress-guarded probe |
Facts 1 to 3 are in git and are asserted on the rendered config (test/lint/dev_compose_platform_origin_4210_test.go and the repo-source render proofs). Facts 4 to 6 are an operator step by design. A builtin registration is an explicit inventory item that carries an actor and a change reference (migration 282, mcpserver.BuiltinConversion), and the app role can only SELECT it. On beta-dev today the memory row exists with no mapping and an empty tool_schema, and there is no knowledge row.
The tool
cmd/tools/first-party-seed is a thin CLI over mcpserver.FirstPartySeed. It is tested against a migrated schema in test/integration/context/first_party_seed_4204_test.go, and the tests observe the result through the gateway's own aggregation path. scripts/dev-seed-first-party-mcp.sh runs it the only way it can work on this stack:
- Inside context-engine's network namespace (
docker run --network container:upsquad-context-engine, using the context-engine image, with a freshly built static binary as entrypoint). The*.mcp.internalendpoints are compose aliases that resolve only there. The probe dials through the same egress guard context-engine's prober uses (allow-list, DNS pinning to the row's CIDR, never-overridable floor). So a captured schema proves context-engine can reach the server. - Against ONE database target,
SEED_DATABASE_URL(defaultpostgres://upsquad:upsquad@postgres:5432/upsquad, resolved inside that namespace). The tool uses one pool for discovery, writes and verification. The wrapper reads no database. - With endpoints read from the running context-engine. Every mode except the plan refuses until context-engine carries
MCP_BUILTIN_*_ENDPOINT, because a registration must equal what the live selector compares.
Seeding
Run this from the shared checkout, after the reconcile that ships #4204:
cd /opt/upsquad/upsquad-core
bash scripts/dev-seed-first-party-mcp.sh # plan: read-only, prints convert/onboard/registered per target
bash scripts/dev-seed-first-party-mcp.sh --apply # write, capture schemas, verify; prints and writes a receipt
bash scripts/dev-seed-first-party-mcp.sh --verify # read-only: facts 4-6 for both targets, through the real selector
What --apply does for each target:
- registered (the mapping already exists). Re-runs the sanctioned validation (
RegisterBuiltinTx: endpoint, approved private-pinned binding for THIS team, mapping target) and checks the team's effective membership. A missing, denied, soft-deleted or withheld (at the team or an ancestor) binding fails the seed. Nothing is restored, re-granted or re-approved; fix the binding through the Manager flow. - convert (a live row, no mapping; the memory row on beta-dev). Writes the mapping through the same validation.
- onboard (no row; knowledge on beta-dev). Writes the registry row, approved binding, private pin, mapping and
allow_privateegress row, all in one transaction. The pin is the subnet of the one network on which the service carries the alias and context-engine is attached, read live. - Then, for every target whose stored schema lacks its expected tools (
mcpserver.FirstPartyExpectedTools), it probes and stores the schema. A probe that returns none of them fails the seed. It finishes with--verify's checks.
The receipt (/opt/upsquad/ops/first-party-seed/<UTC>-first-party-seed.json, overridable with SEED_RECEIPT_DIR) is claimed before the database is touched, so an existing path is refused with nothing written. It is rewritten right after the commit and after each schema capture. It names the org and change reference, and lists exactly the rows the invocation created: mappings, server, binding and egress rows, plus the prior values of any pre-existing egress row the private-upstream seeder upserted in place. The org, unit and actor default to the one approved binding of the memory server. Override them with SEED_ORG, SEED_UNIT and SEED_ACTOR.
Proving it (cutover evidence)
tools/list is not evidence: the gateway answers it from the stored aggregate without touching FirstPartyMinter or the server's identity check. The smoke makes real calls:
cd /opt/upsquad/upsquad-core
AGENT="$(docker exec upsquad-postgres psql -U upsquad -d upsquad -Atc \
"select id from agents where org_id='00000000-0000-0000-0000-000000000001' and team_id='23735ba8-af25-4064-a3f2-273091ef87b2' and deleted_at is null limit 1")"
bash scripts/dev-seed-first-party-mcp.sh --smoke "$AGENT"
It mints a team token with the live issuer key and the running context-engine's PLATFORM_ISSUER / MCP_GATEWAY_PUBLIC_BASE_URL. It reads the exposed {server}__{tool} names from the gateway's own tools/list, then requires all four of these, printing one table row each:
| case | must |
|---|---|
tools/call <memory>__recall_memory through /mcp/team/{unit} | HTTP 200 and a JSON-RPC 2.0 response with this request's id, no error, and a result object carrying a content array with isError not true. An empty 200, {} or result:null fails |
tools/call <knowledge>__search_knowledge through /mcp/team/{unit} | same |
| the same call with a token minted for ANOTHER unit's audience | the terminator's audience refusal exactly: HTTP 401 with a Bearer resource_metadata= challenge. A 403 (consent) or any JSON-RPC error fails |
recall_memory sent DIRECTLY to the memory server with the team token (audience is not <base>/mcp/upsquad-memory) | mcpidentity's refusal exactly: HTTP 401 with JSON-RPC code -32001. Any other error (e.g. -32603) fails |
Exit 0 only when all four pass. Paste the table on #4204 and #4210. #4204 closes on that memory tools/call row.
Rollback
bash scripts/dev-seed-first-party-mcp.sh --rollback /opt/upsquad/ops/first-party-seed/<receipt>.json
Rollback runs in one transaction. Every statement carries the receipt's org and the specific row id. It deletes the mappings this run created, revokes the egress rows it created, soft-deletes the server and binding it created, and restores the prior values of egress rows it upserted. It never touches another tenant or a row that predates the run, and running it a second time changes nothing. Captured tool schemas are not reverted, because they describe the server and grant nothing. These are database rows, so the 15-minute reconciler neither reverts nor re-applies them.
Measured on this change (scratch stack, wrapper run shape, 2026-10-20): a fresh apply onboarded both targets and captured recall_memory,remember and get_context,get_document,get_repo_map,list_repos,report_knowledge_issue,search_knowledge through the guarded probe, and --verify exited 0. The convert path (mapping deleted, schema emptied) wrote one mapping plus a schema. Both rollbacks returned the row counts to 0/0/0/0. An apply onto an existing receipt path was refused with zero rows written. A pin that did not cover the alias IP was refused by the egress guard (reason=private_ip).
The issuer and audience cutover (#4210)
docker-compose.dev.yml derives MCP_AUTHORIZATION_SERVER,
MCP_GATEWAY_PUBLIC_BASE_URL, and through them every aud and every first-party
TOKEN_ISSUER/TOKEN_AUDIENCE, from one variable: PLATFORM_ISSUER. The
tenant compose and the mnet overlay already have this shape. The tracked default
stays http://context-engine:8080, so CI and laptops are unchanged. On beta-dev,
the public cutover is one .env line:
PLATFORM_ISSUER=https://auth-beta.upsquad.ai
followed by one reconcile. That moves iss and every aud together, which
invalidates every token minted before it. Internal agent tokens are minted per
step and recover on the next step. External clients must re-mint. Rollback is
setting the line back to http://context-engine:8080 (or deleting it) and
reconciling again. A .env line survives the deploy's git reset --hard, and the
reconciler applies it.
scripts/dev-secrets/gen-platform-signing-key.sh no longer rewrites
PLATFORM_ISSUER unless you pass it, so a key rotation cannot silently undo the
cutover.
Publishing the hostname (DNS, tunnel ingress, Envoy vhost) is documented in
infra/edge/README.md.
The Envoy vhost is already in the repo and live.