Orca Bots Webhook MCP
by XxFiEnDxX
README.md
# Orca Bots Webhook MCP
A self-hosted MCP server, deployed on Cloudflare Workers (free plan), that lets an AI assistant send JSON to your bots' webhooks. For example, ChatGPT or Claude can post a task to an Orca bot. It works with any client that supports remote MCP servers over streamable HTTP. Whether a client's mobile voice mode can call connectors depends on that client.
- Two tools: `list_bots` and `send_webhook`.
- Webhook URLs are kept in a Cloudflare secret. They never appear in code, Git or chat. The assistant only names the bot.
- Stateless and needs no database. Free plan: 100,000 requests a day. No cold start and no expiry.
```
AI assistant ──MCP──▶ Worker (/mcp?key=…) ──POST JSON──▶ bot webhook
looks up bot name in WEBHOOKS secret
```
## Tools
| Tool | Input | Returns |
|---|---|---|
| `list_bots` | none | Every configured bot, what it does, its intents and each intent's fields (from `bots.json`) |
| `send_webhook` | `bot`, `intent` (if the bot has intents), `thread` (optional), `data` (the intent's fields) | `Sent to <bot>: HTTP <status>. Thread: <thread>.`, or `Not sent. …` listing what's wrong |
| `get_updates` | `thread` (optional), `history` (optional), `limit` | New replies (all threads or one), or a thread's recent asks and replies |
| `list_docs` | `thread` (optional) | Notebook docs |
| `read_doc` | `thread`, `doc`, `section` or `since` (optional) | A short doc whole; a long one as an outline; one part; or only parts changed after a revision |
| `write_doc` | `thread`, `doc`, `section`, `text`, `mode` (replace, append, delete) | Changes one part of a doc |
The POSTed body is `{ "intent": "<intent>", "thread": "<thread>", ...data }` (no `intent` for bots without intents). `data` is checked against `bots.json` before sending: required fields, types, `enum`, `pattern`, and unknown fields.
The webhook URL is never returned. Requests to a webhook time out after 15 seconds.
## Threads and replies
Webhooks only go one way, so replies come back through the Worker. A **thread** is a name like `groove` (a project) or `groove/034` (feature 034 of it); it defaults to the bot name. Every `send_webhook` is saved in its thread, and the thread name is passed to the bot.
Whoever does the work (a bot, or Claude Code through a bot) posts back:
```sh
curl -X POST https://<worker>/reply \
-H "Authorization: Bearer <REPLY_KEY>" -H "Content-Type: application/json" \
-d '{"thread":"groove/034","from":"captain","status":"done","text":"Added 3 retries."}'
```
`status` is one of `received`, `working`, `question`, `done`, `failed`. The assistant reads replies with `get_updates`; each reply is shown as new once. Messages are stored in D1. A weekly cron deletes messages older than 30 days and notebook docs not changed for 90 days (any edit resets a doc's clock).
## Notebook
Replies stay short; long material (plans, research, findings) goes in notebook docs, shared both ways. A doc is split into parts on its `## ` headings, and each part remembers the revision it last changed in, so:
- the assistant edits one part with `write_doc`, never the whole doc;
- the assistant reads a long doc as an outline first, then one part, or only parts changed since a revision;
- the laptop side uploads a whole local file with `PUT /doc`, and only the parts whose text changed get a new revision.
`PUT /doc` takes a `base` revision and refuses (409) if the doc changed since, so edits from the other side aren't overwritten.
Laptop endpoints (`Authorization: Bearer <REPLY_KEY>`): `GET /docs?thread=`, `GET /doc?thread=&doc=[&since=]`, `PUT /doc?thread=&doc=[&base=]` with markdown as the body.
## Self-host
Needs Node.js 18+ and a free Cloudflare account (no card needed for Workers).
```sh
git clone <this repo> && cd orca-bots-webhook-mcp
npm install
cp bots.example.json bots.json # then describe your own bots
npx wrangler login # opens the browser once
npx wrangler d1 create orca-bots-webhook-mcp # paste the printed database_id into wrangler.jsonc
npx wrangler d1 migrations apply DB --remote
npx wrangler deploy # first time: pick your workers.dev subdomain
```
Set the three secrets. Each `secret put` deploys immediately; no redeploy is needed.
```sh
openssl rand -hex 32 # make an access key, save it in a password manager
npx wrangler secret put ACCESS_KEY # paste the key
npx wrangler secret put REPLY_KEY # another random key, for the laptop side: /reply and /doc
npx wrangler secret put WEBHOOKS # paste: {"router":"https://your-bot-webhook"}
```
Your MCP endpoint:
```
https://orca-bots-webhook-mcp.<your-subdomain>.workers.dev/mcp?key=<ACCESS_KEY>
```
Add that URL as a remote MCP server (streamable HTTP) in your client. If the client supports headers, you can send `Authorization: Bearer <ACCESS_KEY>` instead of `?key=`. Leave OAuth off.
Check it:
- `/mcp` with no key or a wrong key returns **404**.
- With the key, `list_bots` shows your bots.
- `npx wrangler tail` shows live logs.
## Bots and webhooks
Each bot has two parts, matched by name:
- **`bots.json`** describes what the bot does, its intents and each intent's fields. The assistant reads it through `list_bots`. It is bundled at deploy and git-ignored; `bots.example.json` shows the format, with a router bot and a free-form test bot.
- **`WEBHOOKS` secret** maps the bot name to its URL:
```json
{
"router": "https://hooks.example.com/router-bot",
"testing": "https://hooks.example.com/test-bot"
}
```
Only bots that have a URL are listed. A bot with a URL but no `bots.json` entry takes free-form JSON.
Field options in `bots.json`: `type` (`string`, `number`, `boolean`, `object`, `array`), `required`, `description`, `enum`, `pattern`. Put "when to use" rules in intent descriptions; the assistant follows them.
| Task | How | Redeploy? |
|---|---|---|
| Add a bot or change a URL | `npx wrangler secret put WEBHOOKS` with the **full** JSON, or Dashboard → Workers & Pages → Settings → Variables and Secrets | No |
| Describe a bot, add an intent or a field | edit `bots.json`, then `npx wrangler deploy` | Yes |
| Rotate the access key | `npx wrangler secret put ACCESS_KEY`, then update the URL in your clients | No |
| Change the code | edit `src/`, then `npx wrangler deploy` | Yes |
Cloudflare can't show a secret after it's set, so keep a copy of the JSON somewhere safe.
## The laptop side (Orca)
The Worker only reaches your bots over webhooks; this repo also has the pieces for the laptop end:
| Path | What it is |
|---|---|
| `router/SOUL.md` | Instructions for an Orca bot named `router`: lists and creates projects and workspaces, and hands requests to each workspace's `captain` chat |
| `bin/voice-reply` | Posts a short reply to a thread: `voice-reply myapp done "Added the banner"` |
| `bin/voice-doc` | Pushes and pulls notebook docs: `voice-doc push myapp plan plan.md`, `voice-doc pull --changed myapp plan` |
| `skills/take-work/SKILL.md` | Claude Code skill: how a captain handles a voice request and replies |
Setup: copy `bin/*` onto your PATH; put `WORKER_URL=https://...` in `~/.config/voice-router/config` and the REPLY_KEY alone in `~/.config/voice-router/reply-key` (`chmod 600` both); copy the skill to `~/.claude/skills/`; create the router bot in Orca, paste `router/SOUL.md`, and give it a webhook automation whose URL goes into `WEBHOOKS`.
## Local development
```sh
cp .dev.vars.example .dev.vars # test keys; bots point at httpbin.org
npx wrangler d1 migrations apply DB --local
npm run dev # http://localhost:8787/mcp?key=local-test-key
npm run typecheck
```
Try it with the MCP Inspector (`npx @modelcontextprotocol/inspector`) or curl:
```sh
curl -X POST 'http://localhost:8787/mcp?key=local-test-key' \
-H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"send_webhook","arguments":{"bot":"testing","data":{"hello":"world"}}}}'
```
## Files
| File | Purpose |
|---|---|
| `src/index.ts` | Worker entry: `/reply`, key check, MCP handler, daily cleanup |
| `src/reply.ts` | The `/reply` endpoint |
| `src/threads.ts` | D1 reads and writes for threads |
| `src/format.ts` | Turns messages into short lines |
| `src/docs/` | Notebook: split into parts, storage, reading, MCP tools, laptop endpoints |
| `migrations/` | D1 tables |
| `src/auth.ts` | Reads `?key=` or a Bearer header; constant-time compare |
| `src/server.ts` | The MCP server and its two tools |
| `src/catalog.ts` | Types for `bots.json` and loads it |
| `src/bots.ts` | Joins `bots.json` with the bots that have a URL |
| `src/validate.ts` | Checks intent and fields before sending |
| `src/webhooks.ts` | Parses `WEBHOOKS`, POSTs to a bot |
| `bots.example.json` | Example bot catalog |
| `router/`, `bin/`, `skills/` | Laptop side, see above |
| `wrangler.jsonc` | Worker settings (no secrets) |
## Security notes
- Anyone with the full URL, including the key, can trigger your webhooks. Treat it like a password.
- A missing or wrong key gets a plain 404.
- With `observability` on, Cloudflare logs record request URLs, including `?key=`. Use the Bearer header, or turn `observability` off, if that matters to you.
- Until `ACCESS_KEY` is set, every request gets a 404.
- Keep `workers_dev: true` in `wrangler.jsonc`, or the workers.dev URL is switched off on the next deploy.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues