Cloudflare Workers Deployment
Overview
- This project’s Node server listens on a port, which works in environments like Smithery.
- Cloudflare Workers require a `fetch` handler, not a long‑running `npm start` process.
- Use the Worker entry at `worker/worker.ts` with `wrangler.toml` for deployment.
What’s included
- `worker/worker.ts`: Minimal JSON‑RPC handler for MCP endpoints:
- `initialize`
- `tools/list` (exposes `vibe_check`, `vibe_learn`, `update_constitution`, `reset_constitution`, `check_constitution`)
- `tools/call` (`vibe_check`, `vibe_learn`, `update_constitution`, `reset_constitution`, `check_constitution`)
- `wrangler.toml`: Worker config with `main = "worker/worker.ts"`.
Limitations on Workers
- No filesystem: history is disabled by default (no `fs`). `vibe_learn` uses KV for persistence.
- `openrouter` provider uses native `fetch`; prefer `gemini` or `openai` if you hit issues.
Setup
1) Install deps locally (optional if deploying via Cloudflare Git):
npm install
2) Configure secrets for the Worker:
wrangler secret put GEMINI_API_KEY
wrangler secret put OPENAI_API_KEY
wrangler secret put OPENROUTER_API_KEY
3) Optional defaults (non‑secret) in `wrangler.toml` under `[vars]`:
- `DEFAULT_LLM_PROVIDER` (e.g., `gemini` or `openai`)
- `DEFAULT_MODEL` (e.g., `gemini-2.5-pro`)
4) Create KV namespaces for `vibe_learn` and constitution:
wrangler kv:namespace create VIBE_LEARN
wrangler kv:namespace create VIBE_CONSTITUTION
# Add the generated IDs to wrangler.toml under [[kv_namespaces]] for both bindings.
5) Publish:
wrangler publish
Endpoints
- POST `/mcp` (JSON‑RPC 2.0)
- Methods:
- `initialize` → basic server info and capabilities
- `tools/list` → lists available tools (`vibe_check`, `vibe_learn`, `update_constitution`, `reset_constitution`, `check_constitution`)
- `tools/call` →
- `{ name: "vibe_check", arguments: { goal, plan, ... } }`
- `{ name: "vibe_learn", arguments: { mistake, category, solution?, type? } }`
- `{ name: "update_constitution", arguments: { sessionId, rule } }`
- `{ name: "reset_constitution", arguments: { sessionId, rules: string[] } }`
- `{ name: "check_constitution", arguments: { sessionId } }`
- GET `/healthz` → `{ status: "ok" }`
Example request
curl -s -X POST "$WORKER_URL/mcp" \
-H 'content-type: application/json' \
-d '{
"jsonrpc":"2.0",
"id":1,
"method":"tools/call",
"params":{
"name":"vibe_check",
"arguments":{
"goal":"Ship release",
"plan":"1) Tests 2) Refactor 3) Canary",
"userPrompt":"Deploy to Cloudflare",
"sessionId":"demo-1"
}
}
}'
Troubleshooting
- If deploy logs show `npm start` runs and times out, you are using Pages build configs. Switch to Workers with this `wrangler.toml` or remove the Pages build command.
- If `openrouter` is selected and requests fail, switch `DEFAULT_LLM_PROVIDER` to `gemini` or `openai`.