Connect an external MCP client
SupaCloud exposes a developer-facing MCP gateway at POST /api/mcp. It is a
standard Model Context Protocol Streamable-HTTP
endpoint (stateless JSON-RPC 2.0), so any conformant MCP client — a local IDE, a
coding agent, or a hand-rolled curl — can list and call a curated set of
SupaCloud tools. Auth is a scoped scmt_ management token in the Authorization
header, or an access token SupaCloud’s own OAuth authorization server issues after a
workspace owner or admin consents in the browser. A standard MCP client finds that
server from the 401 alone, see Authorization discovery.
Follow these steps to wire a client to it.
Prerequisites
Section titled “Prerequisites”- The instance must run the enterprise edition. The gateway is gated by the
mcp_gateway_externalfeature (fail-closed ininterfaces/http/external_mcp.rs); on a Community instance every request to/api/mcpreturns403. - You need permission to mint a management token for the target Workspace (the token must be workspace-scoped — a global/bootstrap token is rejected).
-
Mint a scoped
scmt_token.The gateway reuses the existing Management-API token (
scmt_…, hash-only), extended with two MCP scopes:mcp:read— the read tools (list/get/observe), includingrun.list/run.get/run.events.mcp:ops— impliesmcp:readand adds the ops + script-run tools (workflow.trigger,script.run, the wholeschedule.*group, issue/PR/ repo-sync ops). Use this when your local dev should actually run workflows and scripts, not just watch.
Create the token via the Management API. The response carries the plaintext bearer once — it is never re-readable:
Terminal window curl -sS -X POST \"$SUPACLOUD_URL/api/management/v1/workspaces/$WORKSPACE_SLUG/api-tokens" \-H "Authorization: Bearer $BOOTSTRAP_MGMT_TOKEN" \-H "Content-Type: application/json" \-d '{ "label": "local-ide-mcp", "scopes": ["mcp:ops"] }'The returned
tokenfield (startingscmt_) is your MCP bearer. Store it in$SC_MCP_TOKEN. -
Point your MCP client at the gateway.
The transport is Streamable HTTP, stateless — a single endpoint, no
Mcp-Session-Id, every request self-contained from the bearer. Most clients take an HTTP MCP server URL plus a staticAuthorizationheader. For example, a local IDE / agent MCP config:{"mcpServers": {"supacloud": {"url": "https://your-instance.example.com/api/mcp","headers": {"Authorization": "Bearer scmt_your_token_here"}}}}The gateway advertises protocol version
2025-06-18and atoolscapability in itsinitializeresult. -
List the tools your token can reach.
tools/listreturns only the tools on the external surface for your scope. A read token sees the read tier; an ops token additionally sees ops + script-run:Terminal window curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \-H "Authorization: Bearer $SC_MCP_TOKEN" \-H "Content-Type: application/json" \-d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }'{"jsonrpc": "2.0","id": 1,"result": {"tools": [{ "name": "run.list", "description": "…", "inputSchema": { … }, "outputSchema": { … } }]}} -
Call a tool.
tools/calltakes anameand an optionalargumentsobject. A read example (lists recent runs in the workspace):Terminal window curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \-H "Authorization: Bearer $SC_MCP_TOKEN" \-H "Content-Type: application/json" \-d '{"jsonrpc": "2.0","id": 2,"method": "tools/call","params": { "name": "run.list", "arguments": {} }}'A successful call returns a result whose
structuredContentis the typed tool output (thecontenttext block is the same value as a JSON string):{"jsonrpc": "2.0","id": 2,"result": {"content": [ { "type": "text", "text": "{\"runs\":[…]}" } ],"structuredContent": { "runs": [ … ] },"isError": false}}A nested result object leaves out every member whose value is
nullunless the tool’soutputSchemalists it inrequired, so a run row without a model has nomodelmember at all. Read an absent member asnull. Members of the result object itself (such astotalofbacklog.list) are always present.An ops example (requires an
mcp:opstoken) triggers a workflow:Terminal window curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \-H "Authorization: Bearer $SC_MCP_TOKEN" \-H "Content-Type: application/json" \-d '{"jsonrpc": "2.0","id": 3,"method": "tools/call","params": { "name": "workflow.trigger", "arguments": { "workflow_id": "…" } }}'
What your token can reach
Section titled “What your token can reach”The surface is a positive filter (services/mcp/external.rs::external_tool_allowed)
applied to both tools/list and tools/call, on top of the inherited tier
allowlist:
| Scope | Reachable tools |
|---|---|
mcp:read |
Read tier — run.list, run.get, run.events, workflow.list/get, project.list, issue.list/get, conversation reads, app-build/migration reads, memory.list_closeouts, and the reference reads docs.search, docs.get, spec.get, spec.validate, models.list |
mcp:ops (adds) |
Ops + ScriptRun — workflow.trigger, script.run, the whole schedule.* group (create/update/pause/resume), issue/PR/repo-sync ops |
A few read-tier tools are deliberately excluded because they need an agent
identity an M2M token doesn’t have: memory.create (profile-gated write) and
permission.list. On the ops surface, permission.grant / permission.revoke
are excluded for the same reason.
What it does NOT do (by design)
Section titled “What it does NOT do (by design)”- The Deploy tier is never reachable.
app.deploy/app.migration.applyare excluded by the surface filter and the external allowlist set, and every deploy-tier call waits for a person to approve its tool-approval gate before it runs. Deploy stays inside the agent runner. - No token pass-through. Every tool call runs through SupaCloud’s internal
services::*— which act as their own OAuth client against GitHub/Linear/etc. Yourscmt_token never leaves SupaCloud. - Its authorization server mints nothing wider than a token. An OAuth connection is
an ordinary workspace
scmt_token withmcp:read, ormcp:readandmcp:ops: never amanagement:*scope, never owner power, never another workspace.
Authorization discovery
Section titled “Authorization discovery”The gateway follows the MCP authorization specification (revisions 2025-11-25 and
2026-07-28). SupaCloud is the OAuth 2.1 resource server for /api/mcp and its own
authorization server, so a client connects with nothing configured but the URL:
-
The challenge names the metadata. A
401fromPOST /api/mcpcarriesWWW-Authenticate: Bearer resource_metadata="https://<your-instance>/.well-known/oauth-protected-resource/api/mcp", scope="mcp:read mcp:ops". -
Protected resource metadata (RFC 9728).
GET /.well-known/oauth-protected-resource/api/mcpand the root fallbackGET /.well-known/oauth-protected-resourcereturn the same document: theresource(https://<your-instance>/api/mcp),authorization_serverswith SupaCloud’s issuer (https://<your-instance>) first,scopes_supported(mcp:read,mcp:ops) andbearer_methods_supported: ["header"]. An approved agent-identity registration profile (ADR 0088) adds its issuer and scopes after SupaCloud’s;offline_accessis never listed. The document exists whenever the instance’s public URL ishttps. -
Authorization server metadata (RFC 8414).
GET /.well-known/oauth-authorization-servernames theauthorization_endpoint(/api/mcp-auth/authorize), thetoken_endpoint(/api/mcp-auth/token), theregistration_endpoint(/api/mcp-auth/register), therevocation_endpoint(/api/mcp-auth/revoke),code_challenge_methods_supported: ["S256"],token_endpoint_auth_methods_supported: ["none"],client_id_metadata_document_supported: trueandauthorization_response_iss_parameter_supported: true(RFC 9207). Every endpoint it names is served; an error is JSON, never an HTML page. -
The client identifies itself. Either its
client_idis anhttpsURL of a client ID metadata document (fetched through the egress guard: public addresses only, no redirects, 5 KiB at most,redirect_urisrequired), or it registers (RFC 7591) withclient_nameandredirect_uris. A redirect URI ishttps, orhttpon a loopback address (127.0.0.1,[::1],localhost), where any port matches (RFC 8252 §7.3); everything else must match exactly. Clients are public: no client secret. -
A person consents in the browser. The authorization request needs
response_type=code, an S256code_challengeandresource=https://<your-instance>/api/mcp(RFC 8707). The browser lands on/oauth/consent, where a signed-in workspace owner or admin sees the client name, where the browser returns to (with a warning for a loopback redirect), picks the workspace and the access levels, and allows or denies. The client redirect carriescode,stateandiss. -
The token exchange.
POST /api/mcp-auth/token(form-encoded) with the code, the sameredirect_uri, thecode_verifierand the sameresourcereturns a Bearer access token (anscmt_workspace token, valid one hour) and a refresh token (scrt_, valid 30 days, rotated on every use). The code is single-use and lives five minutes.
- The connection is a workspace token. It is listed on Settings → API tokens as
MCP connection: <client name>, created by the person who consented. Revoking it there, orPOST /api/mcp-auth/revokewith either token (RFC 7009), ends the whole connection. - Replay ends a connection. A code or refresh token presented twice, or a refresh token presented by another client, revokes every token of that connection.
- Every refresh re-checks the person. A refresh succeeds only while the consenting
person still administers the workspace and the plan still includes the external MCP
gateway; a refresh may narrow the scopes, never widen them. A refresh that names a scope
outside the connection’s grant is refused with
invalid_scopeand leaves the refresh token usable. - Storage and limits. Codes, refresh tokens and request handles are stored as hashes
only. Registration is capped at 10 new clients per hour per source address and at 500
per hour per instance. The four client endpoints (registration, authorization, token
and revocation) also share the per-address rate of the sign-in endpoints. A throttled
call answers
429 Too Many Requestswith aRetry-Afterheader in seconds and the JSON body{"error": "too_many_requests", "error_description": "…"}; wait that long, then retry. Consent and every issued token write an audit event in the same transaction as the decision or the token, so the event exists exactly when the grant does. - A static token needs none of this. A client configured with an
Authorization: Bearer scmt_…header never receives the401and never starts the OAuth flow. - POST only.
GETandDELETEon/api/mcpanswer405 Method Not AllowedwithAllow: POST. The gateway opens no standalone SSE stream and keeps no session, which is the Streamable HTTP shape of revision 2026-07-28 (and what earlier revisions allow for a server without a GET stream). A client does not need to probe them.
Rate limits
Section titled “Rate limits”The external identity is the token row, so limits key on the token, not a user:
- A per-identity in-process burst limit stops one token from flooding the gateway.
- A per-identity hourly ops cap — the external analog of the per-profile cap —
counts the token’s own ops audit rows in a rolling hour. Default 30, tunable
via
AGENT_MCP_EXTERNAL_OPS_HOURLY_LIMIT. Over the cap, an ops call returns aForbiddentool error. - An ops call also reserves a slot against the shared workspace daily ops cap.
So a single developer’s token cannot drain the workspace ops budget on its own.
Troubleshooting
Section titled “Troubleshooting”- The consent page says the request expired or was decided — a request lives ten minutes and is decided once. Start the connection again from the client.
invalid_grantat the token endpoint — the code expired, was already used, or theredirect_uri,code_verifierorresourcediffer from the authorization request. A refresh answers it once the connection was revoked or the consenting person no longer administers the workspace.401 Unauthorized— missing or emptyAuthorization: Bearerheader, or a token that does not resolve.403 Forbiddenat the transport — one of: the instance is not enterprise edition (mcp_gateway_externaldisabled); the token is global/bootstrap, not workspace-scoped; or a presentOriginheader does not match the control-plane host (the DNS-rebind guard — an absent Origin, as a server-to-server client sends, is allowed).- JSON-RPC error
-32601“tool not available on the external surface” — the tool is not on your scope’s surface. A read token calling an ops tool, or any caller hitting an excluded tool (deploy,memory.create,permission.*), lands here. Mint anmcp:opstoken if you need the ops tier. - JSON-RPC error
-32601project_credential_required— the tool acts on one project (artifact comments, forms, exports, shares), and a workspace token has no project to bind it to. The message names the project and the exact capabilities (artifacts:comment,artifacts:form, …); connect with a project credential (scpj_) that carries them, as Connect a local agent session describes. - JSON-RPC error
-32700“parse error” — the request body was not a JSON object. "isError": truein atools/callresult — the call ran but the tool failed (HTTP is still200). Server-class detail (SQL/vault/internal) is redacted to a generic message; the raw error is logged server-side.- Ops call rejected as
Forbidden— you have hit the hourly ops cap (default 30) or the workspace daily ops cap. 429from/api/mcp-auth/register— this address registered 10 clients in the last hour, or the instance reached 500. Reuse the client you registered instead of registering on every start, and retry after theRetry-Afterseconds.
When the tool list changes
Section titled “When the tool list changes”initialize answers tools.listChanged: true and issues Mcp-Session-Id. Echo that header
on every later request. When the catalog you can see changes — a new server build, or a
change of your credential’s grants — the next response is text/event-stream whose FIRST
message is notifications/tools/list_changed and whose second is your response; call
tools/list after it. A tools/list answer is itself the statement that you refreshed, so
you are not notified again for a list you already hold. If you cannot read an event stream
(no text/event-stream in Accept), you are answered in JSON and told on a later request.
The notification is bounded, not a broadcast: a workspace token’s record lives in the
gateway process, so with several replicas you may be told once per replica, and a deploy
starts empty — one extra notification after it. An enrolled identity’s record lives on its
request session row instead, so it survives both. A notification is idempotent; re-list and
carry on. AGENT_MCP_CATALOG_NOTIFY_RETRY_SECS (default 600) bounds how often an
unanswered notification repeats.
See also
Section titled “See also”server/src/interfaces/http/external_mcp.rs— thePOST /api/mcphandlerserver/src/services/mcp/external.rs— theexternal_tool_allowedsurface filter- ADR 0054 — the secure-external-MCP-exposure design