MCP servers
An MCP client sends tools/call requests to an MCP server. With OC Agent, each
call carries an action the agent signed under a delegation from a Bitcoin
address, and the server checks it before it runs the tool. This page is the
whole loop: the grant, the client, the server.
The grantLink to this section
The principal grants one scope per tool:
mcp:invoke(server=https://example.com/mcp,tool=search)
mcp:invoke(server=https://example.com/mcp,tool=save_note)
serveris the endpoint URL the client calls, exactly. It is compared byte for byte: case, path and a trailing slash all count, and only surrounding whitespace is trimmed. A URL with?,%or~needs a quoted value (scope grammar).- A grant without
tooladmits every tool on that server. max_invocationsis a number the agent declares in its own exercised scope. Nothing counts calls; a server that wants a limit counts them itself. A grant that carries it refuses an exercised scope that does not, which includes the default onestampInvocationbuilds.
Issue the delegation in code (quickstart) or at
agent.ochk.io/app/compose/delegation (opens in a new tab).
Register it with the server when you set the client up: the action names it by
delegation_id.
The clientLink to this section
import type { DelegationEnvelope } from '@orangecheck/agent-core';
import { ACTION_META_KEY, invokeWithStamp } from '@orangecheck/agent-mcp';
import { signMessage } from '@orangecheck/bip322';
declare const AGENT_ADDRESS: string, AGENT_PRIVATE_KEY: string; // the agent's own key
declare const delegation: DelegationEnvelope; // the one the server registered
declare const mcp: {
request(method: string, params: object): Promise<unknown>;
}; // your MCP client
const agent = {
address: AGENT_ADDRESS,
signMessage: async (msg: string) =>
signMessage(AGENT_ADDRESS, msg, AGENT_PRIVATE_KEY),
};
const { result } = await invokeWithStamp({
agent,
delegation,
invocation: {
server: 'https://example.com/mcp',
tool: 'search',
arguments: { q: 'bitcoin' },
},
// Stamped first; the action rides in the request.
call: (inv, action) =>
mcp.request('tools/call', {
name: inv.tool,
arguments: inv.arguments,
_meta: { [ACTION_META_KEY]: action },
}),
});
- The action goes in
params._meta["io.ochk/agent-action"](ACTION_META_KEY). MCP reserves_metafor metadata and allows prefixed keys there, so a server that does not check actions ignores it. - The action's content is the SHA-256 of the RFC 8785 JSON
{"arguments":…,"server":…,"tool":…}followed by one LF, with mimeapplication/vnd.oc-agent.mcp-invocation+json.canonicalizeInvocationbuilds those bytes. - An off-the-shelf client (Claude Desktop, Cursor) signs nothing itself. Run a
small local MCP server between it and the remote one: it holds the agent key,
forwards every message, and stamps each
tools/callas above.
The serverLink to this section
Check the action after parsing the request and before calling the tool:
import type {
ActionEnvelope,
DelegationEnvelope,
RevocationEnvelope,
Scope,
} from '@orangecheck/agent-core';
import {
createReplayGuard,
isSubScope,
parseScope,
verifyAction,
} from '@orangecheck/agent-core';
import {
ACTION_META_KEY,
canonicalizeInvocation,
} from '@orangecheck/agent-mcp';
import { verifySignature } from '@orangecheck/bip322';
declare const ENDPOINT: string; // this server's public URL
declare const registered: Map<string | undefined, DelegationEnvelope>; // by delegation_id
declare function lookUpRevocations(
delegationId: string
): Promise<{ answered: boolean; revocations: RevocationEnvelope[] }>;
type ToolCall = {
name: string;
arguments: Record<string, unknown>;
_meta?: { [ACTION_META_KEY]?: ActionEnvelope };
};
const seen = createReplayGuard(); // one process; across instances, the same record in a shared store
async function admit(params: ToolCall) {
const action = params._meta?.[ACTION_META_KEY];
const delegation = registered.get(action?.delegation_id);
if (!action || !delegation) return 'unsigned';
// Kind 30085 with "#t": [delegation.id], each relay paged until a page comes back short.
// answered: at least max(1, asked - 2 + 1) relays asked answered in full, none cut off.
const { answered, revocations } = await lookUpRevocations(delegation.id);
if (!answered) return 'unchecked'; // never "not revoked"
const r = await verifyAction({
action,
delegation,
revocations,
verifyBip322: async (m, s, a) => verifySignature(a, m, s),
content: canonicalizeInvocation({
server: ENDPOINT,
tool: params.name,
arguments: params.arguments,
}),
});
if (!r.ok) return r.code;
// The tool name is the caller's text: pin it as a value, never as scope
// syntax, so a call named "*" is the tool called "*", not every tool.
const here: Scope = {
product: 'mcp',
verb: 'invoke',
constraints: [
{ key: 'server', op: '=', value: ENDPOINT, quoted: true },
{ key: 'tool', op: '=', value: params.name, quoted: true },
],
};
if (!isSubScope(parseScope(action.scope_exercised), here))
return 'E_SCOPE_DENIED';
if (!seen.firstUse(action)) return 'already used';
return 'ok';
}
What each check stops:
| Check | Refuses |
|---|---|
verifyAction (live) | A delegation not in force now (E_), a revocation in effect now (E_), signed_ more than 120 seconds from your clock (E_), a bad signature, a scope outside the grant |
content | An action stamped over other arguments, another tool or another server (E_) |
| Scope pinned to this server and tool | Authority granted for another tool or server, spent here |
createReplayGuard | The same signed call sent twice |
| Revocation read below the floor | A call whose revocation status is unknown |
The relays the family reads and publishes to are listed on
relay infrastructure. "No revocation" needs at least
the read floor of the relays asked (the number asked, less 2, plus 1, and never
fewer than one) to have answered in full, each read paged with until until a
page came back short, and no relay cut off. Otherwise the call is unchecked,
never unrevoked
(OC Agent SPEC §10.4 (opens in a new tab)).
As
OC Lock §3.5 (opens in a new tab)
puts it, a cut-off read is not an answer. Each relay event is verified under
NIP-01 before the relays' answers are merged, and every revocation whose signed
bytes verify is kept, never one per stated id. A clear result may be cached
for a short time, a minute for example, and only when it met that rule.
Checking calls laterLink to this section
A log of past calls is an audit. verifyActionAsOfSignedAt checks each action
as of its own signed_at and says, in asOf.anchored, whether that time is
fixed by a verified OTS anchor or is only the agent's claim. The command line
does the same with
npx @orangecheck/agent-cli verify pair.json --as-of-signed-at --revocations revs.json,
where pair.json is [delegation, action]; it does not check the content
binding, which needs the invocation.
A working pair to fork:
mcp-wrap (opens in a new tab)
(client) and
verifying-mcp-server (opens in a new tab)
(server). They differ from this page in two ways: mcp-wrap calls
stampInvocation and reads the agent's signature back on stdin, and the pair
sends the delegation and the action together in an _oc_agent field of the
request rather than in params._meta.