Capsid
A Cloudflare-native MCP server for a consolidated knowledge base, enabling CRUD operations, search, and namespace management with versioning and audit logs.
README
Capsid
Capsid is a single-user, Cloudflare-native MCP server that serves a consolidated knowledge base from D1 and R2. It speaks MCP over Streamable HTTP and exposes a small, purposeful tool set: list, read, write, delete, move, find, search (FTS5), and namespaces.
All access is gated. Human clients (claude.ai, MCP Inspector) authenticate via GitHub OAuth, and only the configured admin GitHub account is admitted. Headless agents and cron use a separate operator-key endpoint. Every write snapshots the prior version into document_versions and appends to audit_log, so you get history and rollback for free.
Stack
- Cloudflare Worker (TypeScript), stateless MCP via
createMcpHandlerfrom the Agents SDK - workers-oauth-provider wrapping the MCP handler: OAuth 2.1 with PKCE, dynamic client registration, and token storage in KV
- GitHub as the identity provider, locked to a single admin account
- D1 for documents, versions, namespaces, and audit log, with FTS5 full text search
- R2 (
MEDIAbinding) for media - KV (
APP_KVbinding) for app state, plus anOAUTH_KVbinding for OAuth tokens
Endpoints
POST /mcpMCP over Streamable HTTP, requires an OAuth access token (admin only)POST /ops/mcpMCP over Streamable HTTP for headless agents, requires the operator key asAuthorization: Bearer <key>POST /ops/backupruns a backup on demand, requires the operator key, returns a JSON summaryGET /authorize,POST /authorize,GET /callbackGitHub OAuth flowPOST /token,POST /registerOAuth token exchange and dynamic client registration (served by the library)GET /.well-known/oauth-authorization-serverandGET /.well-known/oauth-protected-resourceOAuth discovery metadata (served by the library)GET /healthreturnsok, no auth
Auth model
Two parallel paths, both fully gated:
- OAuth (
/mcp) for human clients. The client discovers the server via the.well-knownendpoints, registers itself dynamically, and is sent through/authorize. After a one-time approval screen, the browser goes to GitHub. On return, the GitHub user is checked againstADMIN_GITHUB_LOGIN: set it to your GitHub username, or to your immutable numeric GitHub user id (find it athttps://api.github.com/users/<login>). Any other GitHub account gets a 403. The admin check runs again on every/mcprequest as defense in depth. - Operator key (
/ops/mcp) for agents and cron. Same tools, same server, gated by the existing sha256-hashed bearer key (OPERATOR_KEY_HASH). The OAuth library never sees this route, so the two paths cannot interfere. Note: this path moved from/mcpto/ops/mcp; update any headless client configs.
Destructive writes need confirmation
delete, and any write that would overwrite an existing document, ask for confirmation first. When the connected client supports MCP elicitation, the server sends an elicitation request and proceeds only on an explicit accept. Most Streamable HTTP clients run stateless and cannot answer server-initiated requests, so the fallback applies: the tool rejects with a clear message and you re-run it with confirm: true. Creating a brand new document never needs confirmation.
Deletes are never unrecoverable at the data layer: every delete (and every overwrite) snapshots the prior row into document_versions first, so recovery exists regardless of how the confirmation went.
Backups
D1 Time Travel already provides 30-day point-in-time recovery, so backups here are for longer retention and portability, not short-term recovery.
A daily Cron Trigger (09:00 UTC) exports the whole database to the MEDIA R2 bucket:
backups/json/<timestamp>.jsona full JSON dump of all four tables (documents, namespaces, document_versions, audit_log). The 14 most recent dumps are kept; older ones are pruned automatically.backups/markdown/<namespace>/<path>a plain-markdown mirror of every document body, verbatim, one file per document. This mirror tracks the current state (files for deleted documents are pruned), so the knowledge base stays readable and portable with no Capsid dependency.
Run one on demand with the operator key:
curl -X POST https://capsid.<your-subdomain>.workers.dev/ops/backup -H "Authorization: Bearer <key>"
The response is a summary: the JSON dump key, document count, markdown files written and pruned, and how many JSON dumps were kept and pruned.
Clone setup
-
Install dependencies:
npm install -
Create your own Cloudflare resources:
npx wrangler d1 create capsid npx wrangler kv namespace create APP_KV npx wrangler r2 bucket create capsid-media -
Copy the config template and fill in your IDs from step 2. The
OAUTH_KVbinding can reuse the same KV namespace id asAPP_KV(the OAuth library prefixes all of its keys), or point at a dedicated namespace if you prefer:cp wrangler.jsonc.example wrangler.jsoncThe real
wrangler.jsoncis gitignored on purpose. Never commit it. -
Apply the migration:
npx wrangler d1 migrations apply capsid --remoteNote: the migration is idempotent (IF NOT EXISTS everywhere). Applying it against an already-migrated database, including the original capsid D1, is a no-op. Cloners must run it once.
-
Generate an operator key and store its hash as a secret. Keep the raw key somewhere safe; it is what headless MCP clients send as the bearer token on
/ops/mcp.npx wrangler secret put OPERATOR_KEY_HASHThe value must be the lowercase hex sha256 of your raw key. Never store the raw key anywhere in the repo.
-
Create a GitHub OAuth App at https://github.com/settings/developers with:
- Homepage URL:
https://capsid.<your-subdomain>.workers.dev - Authorization callback URL:
https://capsid.<your-subdomain>.workers.dev/callback
Then set the OAuth secrets (none of these ever go in the repo):
npx wrangler secret put GITHUB_CLIENT_ID npx wrangler secret put GITHUB_CLIENT_SECRET npx wrangler secret put COOKIE_ENCRYPTION_KEY # openssl rand -hex 32 npx wrangler secret put ADMIN_GITHUB_LOGIN # your GitHub username, or your numeric GitHub user idFor local dev with
wrangler dev, create a second GitHub OAuth App with callbackhttp://localhost:8787/callbackand put the four values in.dev.vars(gitignored). - Homepage URL:
-
Type check and deploy:
npx tsc --noEmit npx wrangler deploy -
Connect claude.ai: Settings, Connectors, Add custom connector, URL
https://capsid.<your-subdomain>.workers.dev/mcp. The connector registers itself via dynamic client registration and walks you through the GitHub login. Only theADMIN_GITHUB_LOGINaccount gets in. -
Or test the flow first with the MCP Inspector:
npx @modelcontextprotocol/inspectorSet transport to Streamable HTTP, URL to
https://capsid.<your-subdomain>.workers.dev/mcp, open the Auth tab, and run Quick OAuth Flow.
Auth roadmap
- Phase 1 (done): single service token, bearer key checked against
OPERATOR_KEY_HASH. Now served at/ops/mcp. - Phase 2 (done): GitHub OAuth via workers-oauth-provider on
/mcp, locked to a single admin account. This is what claude.ai and other OAuth-only clients use. - Phase 3 (deferred): first-class service tokens for agents and cron, issued and revocable per client, replacing the single shared operator key.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。