opschain mcp serve
Included from Basic tier
opschain mcp serve [--http <addr>] [--auth-token <token>]
opschain mcp serve --as-agent <code> [--dir <state>] [--token <registration token>] [--http <addr>]
Serves OpsChain's curated tool vocabulary to a Model Context Protocol
client. The command speaks MCP (JSON-RPC 2.0) to the assistant on one
side and the OpsChain API to the targeted server (--server,
OPSCHAIN_SERVER or the active context) on the other. It holds no
enforcement logic of its own: every tool call is an API call under the
configured credential, so a change an assistant raises still queues
behind its approval policy, a denied read answers not found, and every
invocation lands in the server's request log and audit trail with the
tool name carried in the client identification.
Transports
- stdio (default) — for local assistants and IDEs: the client
launches this command as a child process and exchanges one JSON-RPC
message per line on stdin/stdout. Logs go to stderr (or
--log-file), never stdout. - streamable HTTP (
--http <addr>) — for hosted clients: JSON-RPC messages POST to/mcpand each answers a single JSON response. This server does not offer SSE streaming — a client asking for the stream (HTTP GET) is refused politely, and every response fits one JSON body. TLS termination is the operator's reverse-proxy concern, as for any sidecar.
The handshake negotiates the protocol revision (2025-06-18 preferred;
older clients are accepted per the protocol's negotiation rule) and
advertises the toolset. Sampling and elicitation requests — a server
asking the client's model or user for input — are refused by name.
Authentication
The credential decides the principal: --auth-token wins, the stored
login for the targeted server otherwise. For unattended assistant use,
configure a service-account token enrolled for that purpose so calls are
attributed to a governed identity; a personal login is appropriate when
the assistant acts as you. The server enforces exactly what that
principal may see and do — tools whose underlying surface the licence
does not entitle are omitted from the tool listing, and an authorisation
refusal surfaces to the assistant verbatim as a tool error.
When the estate mandates agent identity
An administrator can require that assistants reach the estate only as
registered agents: the global setting
agents.mcp_requires_agent_identity (default false; see
opschain docs settings-reference). While it is true, a session on
your own login or API token is refused by name when it starts, before
any protocol traffic, with exit code 2:
this estate reaches its assistants only as registered agents — run `opschain mcp serve --as-agent <code> --token <registration token>`; ask an administrator for an agent code
The server enforces the same refusal on every call such a session makes,
so it holds even against a session that started before the setting was
turned on (within 30 seconds of the change). An --as-agent session is
never affected, and the lever is not an API control: it governs the OpsChain MCP server lane, recognised by the client identification every opschain mcp serve request carries, while a person's token still works for ordinary CLI and API use and for any other client built on it. A server on the SQLite store holds no global settings
document, so the setting cannot be turned on there.
As an agent (--as-agent)
With --as-agent <code> the session is a registered OpsChain agent, not
a person. The first run redeems a registration token (--token, minted
for the agent's code with opschain admin agent-token create — see
opschain docs cli/admin-agent-token-create) and keeps the agent's keypair in the state directory (--dir, default
<opschain home>/mcp-agents/<code>); later runs reuse it and need no
token. The command then holds the agent's channel open (the five minimum
surfaces, so the agent is on the fleet and posture pages and a halt
severs it) and sends every tool call over the agent channel as the
agent's service account:
- Owned by you, for accountability. Your own login on the server
(
opschain login, or--auth-token, used only to identify you) is declared as the agent's owner at enrolment; on the server the owner is accountability only — it grants nothing. The state directory records your principal id, and the command refuses by name a session whose login is not that owner, a--dirholding another agent, or an agent not enrolled there with no--token. That ownership check is a courtesy made by the command on your machine, not a server control. - The state directory is the credential. The keypair the command
writes there (directory
0700, files0600) is what authenticates the agent — protect it like a private key. Anyone who holds a copy can act as the agent; the server attributes what they do to the agent's principal, with you as its owner. Revoke the agent (opschain admin agent revoke) if the directory is exposed. - On the SQLite store there are no logins, so the agent enrols without an owner; its trust grants decide its tier as on PostgreSQL, and with no grant the agent's run is refused by name.
- The tier is the server's. The agent's trust grant decides what a
mutating call becomes: under SUPERVISED a run is created with the
injected approval gate and the tool returns its state without waiting;
with no grant it is refused by name. The approval verbs
(
answer_approval,list_my_approvals) are not offered, and a call to one is refused by name; the server refuses every human verb to an agent anyway. - A change record where policy requires one. Before a run is created
the command asks the server whether an approval policy carrying
require_change_recordcovers the target (policy_coverage, the policies' own patterns, never a path's name); if one does, the call is refused by name unless it names an approved change record inchange_record. A target no such policy covers behaves as today; an answer that cannot be confirmed refuses the write. - One correlation id per unit of work. A tool call may carry
correlation_id(a UUID — pass one id for every call of one task); without one, an id is minted for the call. It reaches the server with the call, is recorded on the agent's request event, and is stamped on the run the call creates (opschain.correlation_idin its provenance). - Masked results. Every tool result and refusal is masked before it
leaves the process: secret-shaped fields (
password,token,secret,api_key,credential…) at any depth, including JSON held in a*_jsonfield, bearer values, the registration token and everyOPSCHAIN_*TOKEN*value in the environment read******. A secret reference prints as the reference.
--as-agent needs the packs:agents entitlement (enrolment is refused
by name without it) and a server; the local lane is refused as below.
Flags
| Flag | Meaning |
|---|---|
--http <addr> | Serve the streamable HTTP transport on this listen address (e.g. 127.0.0.1:8137) instead of stdio. |
--auth-token <token> | API token to authenticate with (default: the stored login for the targeted server); with --as-agent it only identifies the agent's owner. |
--as-agent <code> | Serve as this registered agent (its code, or its id once enrolled), owned by the person running the session. |
--dir <state> | The agent's state directory (default: <opschain home>/mcp-agents/<agent>). Needs --as-agent. |
--token <registration token> | Agent registration token, redeemed when the state directory holds no enrolment yet. Needs --as-agent. |
Exit codes
0 after a clean shutdown (stdin closed on stdio, interrupt on HTTP);
2 for a usage error (no server targeted, --dir or --token without
--as-agent) or a session the estate's agent-identity mandate refuses; 1 when the transport fails or an agent session is refused
(not enrolled, not owned, enrolment refused).
See also
opschain docs integrations-mcp— connecting Claude Desktop, an IDE or a hosted client, with configuration samples.opschain docs cli/login— storing the credential the default lane uses.