OpenClaw
OpenClaw is a personal assistant gateway that connects chat channels to agents. chamvi's integration contract is "MCP in, hooks out".
MCP in
Each chamvi app serves an MCP endpoint at /mcp (Streamable HTTP, from @chamvi/http). OpenClaw lists it among its MCP servers and gets:
- one
run_<agent>tool per agent with anhttp.on()subscription, which starts a run (channelmcp) and returns the run id (or, withwaitSeconds, waits up to a minute and returns the output or the pending approval), get_runandlist_runsfor status,approve_run, which needschamvi_agent_approve: OpenClaw's principal should not hold it (see below), so for OpenClaw it always fails.
The endpoint uses the same bearer-token authentication as the REST API; give OpenClaw a principal with chamvi_agent_run for the agent, which also lets it read the runs it starts. Never give it chamvi_agent_approve: the owner answers approvals in the chamvi UI, signed in as a principal of their own. This is how the owner says "what's relevant in my mail today?" in a chat and gets a run started.
Hooks out
Messages and approval requests flow back through the OpenClaw channel, @chamvi/channel-openclaw: POST <openclaw><hooks.path>/agent with OpenClaw's hooks token as bearer token, the message key as Idempotency-Key header and the delivery target (channel and recipient). The channel is out only:
const openclaw = openclawChannel({
// the OpenClaw gateway, reachable from the app
baseUrl: 'http://openclaw:18789',
// OpenClaw's hooks.token, not the gateway token
hooksToken: process.env.OPENCLAW_HOOKS_TOKEN ?? '',
// placeholders: the channel and recipient of your OpenClaw setup
deliver: { channel: '<channel>', to: '<recipient>' },
// optional: a link to the approval in the UI; a message never carries the token
approvalUrl: ({ runId, approvalId }) => `https://chamvi.example/ui/approvals?run=${encodeURIComponent(runId)}&approval=${encodeURIComponent(approvalId)}`,
});
// runs, steps, checkpoints, effects, artifacts and state in memory, gone with the process: @chamvi/app keeps them in PostgreSQL
const registry = new MemoryRegistry();
const runs = new MemoryRunRepository({ registry });
const locks = new MemoryLockRepository({ registry });
const engine = new Engine({
runService: new RunService({ repository: runs, clock: systemClock }),
stepService: new StepService({ repository: new MemoryStepRepository({ registry }) }),
checkpointService: new CheckpointService({ repository: new MemoryCheckpointRepository({ registry }) }),
effectService: new EffectService({ repository: new MemoryEffectRepository({ registry }) }),
agentRevisionService: new AgentRevisionService({ repository: new MemoryAgentRevisionRepository({ registry }) }),
artifactService: new ArtifactService({ repository: new MemoryArtifactRepository({ registry }) }),
stateService: new StateService({
repository: new MemoryStateRepository({ registry }),
documentRepository: new MemoryStateDocumentRepository({ registry }),
}),
lockService: new LockService({ repository: locks, clock: systemClock }),
idempotencyService: new IdempotencyService({ repository: new MemoryIdempotencyRepository({ registry }), clock: systemClock }),
agents,
// tools reach it with ctx.channels.findOneOrFail('openclaw')
channels: [openclaw],
});A tool sends through it with ctx.channels.findOne('openclaw'): emit() for a message, approve() to pause the call until the owner answers. The address is the recipient; without one the call sends to deliver.to, the channel's defaultAddress:
export const deploy = defineTool({
description: 'Deploy the current release.',
inputSchema: z.object({ env: z.enum(['staging', 'prod']) }),
execute: async ({ env }, { context }) => {
const openclaw = context.channels.findOneOrFail('openclaw');
// without an address both go to deliver.to (the channel's defaultAddress)
const { approved } = await openclaw.approve({ title: `Deploy to ${env}?` });
if (!approved) {
return 'the owner said no';
}
await openclaw.emit({ body: `Deployed to ${env}.` });
return `deployed to ${env}`;
},
});In the OpenClaw configuration:
| Key | Value |
|---|---|
hooks.enabled | true (hooks are off by default) |
hooks.token | A dedicated token, passed as hooksToken; not the gateway token |
hooks.path | /hooks (the default hooksPath), or the same value on both sides |
hooks.allowedAgentIds | Lists the agentId you pass, if any |
mcp.servers | The app's /mcp endpoint with a token of a principal holding chamvi_agent_run, never chamvi_agent_approve |
deliver.channel and deliver.to must name a concrete destination of your OpenClaw setup (OpenClaw refuses channel: 'last' and a partial destination for hooks); the examples use placeholders. deliver.to is the channel's defaultAddress, which the outbound gate exempts: a run tainted by untrusted content can still send to it without approval, so pick a recipient that may receive what any such run produces (see untrusted content and outbound tools).
For approvals the message includes how to answer: the approvalUrl link when configured, e.g. https://<app>/ui/approvals?run=<runId>&approval=<approvalId>, which opens the run's approval in the UI, where the signed-in owner answers it through POST /runs/:id/approve (the owner's principal needs chamvi_agent_approve to answer and, for the UI to show the run's approval, chamvi_run_read or chamvi_agent_run for a public agent and chamvi_agent_read for a private one); else a line saying to answer in the chamvi UI or through POST /runs/:id/approve.
The OpenClaw agent cannot approve
The approval's title and body are what the tool wrote and may repeat untrusted text (an issue body, a mail). OpenClaw wraps hook content as external, but that does not take tools away. The message carries no token, so a relay agent whose principal holds only chamvi_agent_run cannot approve, whatever an injected instruction says: only the owner, signed in to the UI, approves.
Caveats
- OpenClaw runs an agent turn on the message (it does not post raw text) and treats it as external content; the message asks that agent to keep every link and id verbatim.
- OpenClaw's idempotency replay is in memory and lasts 5 minutes after completion; a restart clears it. chamvi's records (the emit effect, the approval's
waiting.notifiedAtand its per-approval lock) are the primary dedupe, the key covers a response lost within those minutes. - A misconfigured hook (400, 401, 404) fails on every send: an
emit()is a tool error, an approval message reachesonErroron every poll. - Keys over 256 characters (which OpenClaw ignores) or with characters outside visible ASCII are sent as
sha256:<hex>.
In the cluster
OpenClaw runs elsewhere in the cluster. It reaches each app at http://<service>/mcp, and the app reaches OpenClaw's hooks endpoint. Neither needs to be public.