MCP server (Connected agents)
External agents (Claude Code, Cursor, and similar) connect over MCP and act as a signed-in Brilliant user in one tenant: list workspaces, build with prompts, screenshot previews, read app data, publish, roll back.
This is not MCP exposed by generated apps.
Code: apps/control-plane/src/mcp/
Plan (living): docs/plans/mcp-server.md
Flag: none — MCP is always on (#982, merged). Optional secret MCP_DISABLED=true is the incident kill switch (refuses /oauth/authorize and every tool call). The old mcp_server Flagship gate is gone.
Consent page (/oauth/authorize)
What Claude Code / Cursor open in the browser for OAuth consent.
- Look: Studio chrome via
@brilliant/design-tokens, the same Inter stylesheet other server-rendered pages use (integration connect, published-app login), brand glyph, card layout. On narrow viewports buttons stack full-width with Allow nearest the thumb. - Refusal pages (
MCP_DISABLED, impersonation /actsession, not a member) share the same card. - Implementation:
apps/control-plane/src/mcp/authorize.ts(merged in #131).
CSP gotcha (do not regress)
Pages carry no script. Framing stays denied (consent helper’s own frame-ancestors).
Allowed extras for fonts only:
style-srcincludeshttps://fonts.googleapis.comfont-srcincludeshttps://fonts.gstatic.com
Never add form-action to the consent CSP. Chrome applies form-action to the redirect after the POST, which would block the hand-off to the client’s loopback callback (e.g. http://localhost:…/callback?code=…). Tests in apps/control-plane/test/mcp-oauth-authorize.test.ts pin this.
Workspace IDs
Workspaces expose two id forms:
| Form | Meaning | Typical shape |
|---|---|---|
| Row id | Workspace DB row UUID — what list_workspaces returns | UUID |
| Container id | Sandbox/container workspace id | s9-… |
- Every MCP tool that takes
workspace_idaccepts both. - Returned
workspace_idfromcreate_appandlist_workspacesis the row id, so agents can compare ids across tools. preview_url(create_app,send_prompt,get_turn) also uses the row id — the same form as the studio’s/w/links.
Contract pin: #138 (create_app previously returned the container id).
Auth model (MVP)
| Concern | Choice |
|---|---|
| Principal | Acting as a user (OAuth). No machine/service tokens in the MVP. |
| Placement | Inside the control-plane worker (@cloudflare/workers-oauth-provider); /mcp via Streamable HTTP handler. Auth0 is only the login behind /oauth/authorize. |
| Grant | Pinned to one tenant (picked on consent). Scopes read, write, data:read. Tenant / role / seat re-read from the DB on every call. A tenant that is not active (suspended or pending deletion) is refused on every tool call (#639 — details, merged). |
| Conductor | MCP token never reaches the conductor; each call mints a ws: capability token as POST /tokens does. |
| Impersonation | /oauth/authorize refuses act sessions. |
Settings › Connected agents: server URL, client snippets, grant list, revoke.
App data tools (data_schema / query_data)
Same access as the studio Data tab (#139, merged): builder seat + app creator, or org owner/admin. See Control plane — Data tab access.
Publish / rollback outcome observability
Landed in #141. MCP publish / rollback must not lose the outcome when the client drops a long call.
Problem: A real agent called publish on staging; the run went past the client timeout, went to background, the transport dropped — the response was lost and the agent could not tell whether production changed.
Behaviour
| Phase | What happens |
|---|---|
| Start | publish / rollback kick off on the conductor with ?background=1 (see Conductor). |
| Poll | MCP polls GET /w/:id/deploy-state every 3s for up to 20s, surfacing progress. |
| Finished | Returns today's success shape (or an error if the run failed). Success only when observed (@cc publish-outcome-never-guessed). |
| Still running | { status: "publishing", kind, started_at, note } when the wait window ends while the run continues. |
| Already busy | 409 deploy_in_progress → same publishing shape for the caller that started the deploy (retry never starts a second one). A different op that hits a running deploy/rollback answers { busy, started: false, running: … } — it does not report the other operation's progress as its own. |
get_app exposes publish: { state, deploying?, last_result?, live_version? } and turn: { running, turn_id? } so agents can recover after a timeout or dropped connection.
After publishing, timeout, or drop
Check get_app / list_versions. Never publish twice "to make sure." The app is marked live by existing deployment ingest (conductor → control plane at the end of every deploy), including background publishes.
Client timeout ceilings (field-proven)
Clients drop any MCP tool call that holds ~30s+. No tool call is designed to hold longer than 20s.
| Tool / path | Ceiling |
|---|---|
publish / rollback wait window | 20s → then publishing (poll deploy-state) |
get_turn | default 20s, max 25s (clamped) |
create_app / send_prompt cold boot | returns starting rather than holding |
| Cold-workspace reads | capped |
| Screenshot wake budget | 15s (wake_ms; studio default unchanged) |
Instructions wait_seconds | 20 |
Other MCP contract notes from #141
rollbackaccepts the version row id or the worker version id.list_versionsreturnsversion_id,worker_version_id,commit_sha,published_at,label,is_live,published_by, plusworkspace_idin thelist_workspacesform (studio route shape unchanged).send_promptbusy →running_turn_id(notturn_id).- Screenshot
full_page: clips to 8000×4000 CSS px withclipped: trueinstead of failing.
Gotchas
- MCP
publish/rollbackalso need thereadscope (they poll deploy-state). - Rollback over MCP is audited when the conductor accepts it (202), not when it finishes.
- If conductor deployment ingest fails, a background publish can leave the app shown as draft (the sync path had a control-plane fallback).
- If the WorkspaceDO is evicted mid-run, the run dies and
get_appshowsidlewith the previouslast_result.
Code: apps/control-plane/src/mcp/publish-wait.ts; conductor deploy/ops under services/conductor; GOTCHAS updates in the PR.
get_turn on a finished turn: stored outcome (#578, merged)
Fixes #573. Once a turn has ended, get_turn has no live run end to listen for, so it used to guess the outcome from the entries. A prompt with no answer read as error: The run ended without a response whether the user pressed Stop before the first token or the run faulted.
Since #578 (merged 2026-10-07 14:50 IDT, merge 92a5a77c) the session carries Pi's own settled status for each prompt:
AgentPromptMeta.outcome(packages/rpc, typeAgentPromptOutcome):{ status: "done" }, or{ status: "unanswered", reason, detail? }with Pi's reason (abortedfor a Stop,model_error,faulted,no_model, ...) and, when Pi gave a string message (a fault's cause, the model's error), that message verbatim asdetail. It is absent while the prompt is still placed in a run.- Where it comes from: the conductor reads
status,reasonanddetailstraight from Pi'spi_submissionsrecord in the query that already joins it (services/conductor/src/coding-agent/pi/checkpoints.ts). Nothing new is stored. - Contract
prompt-outcome-mirrors-pi-submission(@ccowner yoni-monday, label architecture):outcomemust be Pi's own status (withdetailonly when Pi gave a string) and never inferred from entries, becauseget_turntrusts it to tell a Stop from a fault after the fact.
How get_turn decides (apps/control-plane/src/lib/turn-digest.ts):
| Order | Source | Result |
|---|---|---|
| 1 | Live end from the stream (submission done/unanswered, or run_end) | Used as is |
| 2 | Stored outcome | done is done; unanswered/aborted is interrupted; any other reason is error |
| 3 | The entries (only for an older conductor without outcome) | Same rules as before |
Live and stored reads go through the same mapping (unansweredSettlement), so a turn reports the same result while it is watched and on every read after. For an error, the message is picked in one order on every path: Pi's detail (for example container lost for a fault), then the model's own error message on the last response (an assistant entry with stopReason: "error", so an overloaded model reads error: overloaded, not model_error), then Pi's bare reason, then what the entries say, then The turn failed. The contract turn-settles-only-on-run-end is updated to include the stored outcome.
Verified in the PR: bun run verify green; services/conductor/test/pi/prompt-outcome.test.ts (done after an answer, absent mid-run, unanswered/aborted after a Stop, Pi's message carried for a failed run) and apps/control-plane/test/operations-conversation-digest.test.ts; live on side env pi, a finished turn reads done and a turn stopped 300 ms in reads interrupted instead of an error.
Suspended tenants are refused on every call (#639, merged)
Fixes #280. Opened 2026-10-08 15:09 IDT by Brilliant Fixer; merged 2026-10-08 15:15 IDT by yoni-monday (merge a153b350).
The gap: bearer /mcp calls skip sessionMiddleware, so the tool gate never saw tenant.status. gate() only checked that the user, tenant and membership rows exist, so a grant issued before staff suspended a tenant kept working for every tool, including query_collection, run_script, send_prompt, create_app and publish.
The change: gate() in apps/control-plane/src/mcp/tool-call.ts now refuses with forbidden: this account is not active whenever the principal's tenant status is anything other than active (so suspended and pending_deletion both stop), after the membership check and before the mcp_server flag check. The BI tool-call event carries error_code: tenant_inactive, and nothing reaches the conductor. Status is re-read on every call (same as tenant, role and seat in the auth model), so resuming the tenant restores the grant with no reconnect.
Changed in review: the first version checked === "suspended" and returned this account is suspended / tenant_suspended (the PR body still says that). Review asked for !== "active" to match routes/app-access.ts, since tenant status is an untyped string and a status added later would slip past a suspended-only check. The merged code uses the not-active check, and the gate order (membership, active tenant, mcp_server flag, grant scopes, rate limits) is now written in the module header of tool-call.ts as the gate's contract.
Decision: grants are not revoked on suspend. The per-call check already closes the gap, and revoking would force every member to reconnect after a resume.
Verified in the PR: a new test in apps/control-plane/test/mcp-tools.test.ts suspends the tenant, gets the refusal from list_apps, create_app, send_prompt, publish, query_collection and run_script with no conductor requests and only tenant_inactive in BI, checks pending_deletion is refused too, then resumes and list_apps works again (fails on main). Control-plane tsc clean and bun test 1528 pass. Side env sec-batch passed e2e.ts and e2e-smoke.ts, but a real MCP call from a suspended tenant was not exercised live (no MCP e2e harness; it needs an OAuth grant plus the mcp_server flag).
Related suspend behaviour elsewhere: session routes recheck membership (#371, #461) and suspended tenants stop sharing templates (#462).
MCP always on — mcp_server removed (#982, merged)
#982 (merged 2026-10-16 05:47 IDT by yoni-monday, merge 94410daa, head cfa4986b; opened 2026-10-15 22:26 IDT, branch posthog-6-feature-flags) removed the mcp_server feature flag.
What landed:
- All
mcp_servergates are gone (authorize page, tool-call check, studio nav/page gates, off-state tests and copy). MCP is always on for every tenant. - The consent page (
/oauth/authorize) lists every tenant membership that is not suspended. With none: "You have no active organization to connect." - Optional secret
MCP_DISABLED=trueis the incident kill switch: refuses/oauth/authorizeand every tool call. studio_admin_banner_testwas also removed from the catalog (unrelated to MCP, same PR).
See PostHog — Step 6 and Admin Feature Flags.
Related
- Conductor — background deploy / deploy-state · Control plane & studio · Architecture overview · ADR index (
docs/plans/mcp-server.md)