- Node.js 18+
- A Cloudflare account (free tier is sufficient)
- A GitHub account
cd second-brain-vault
npm installnpx wrangler loginThis opens a browser to authorize wrangler.
npx wrangler kv namespace create "OAUTH_KV"Copy the returned ID and replace <YOUR_KV_NAMESPACE_ID> in wrangler.jsonc.
- Go to https://github.com/settings/developers
- Click "New OAuth App"
- Fill in:
- Application name:
MCP Vault (local) - Homepage URL:
http://localhost:8788 - Authorization callback URL:
http://localhost:8788/callback
- Application name:
- Create a
.envfile at the project root:
GITHUB_CLIENT_ID="your-client-id"
GITHUB_CLIENT_SECRET="your-client-secret"
COOKIE_ENCRYPTION_KEY="a-random-32-char-string"To generate the encryption key:
openssl rand -hex 32npm run devThe server runs on http://localhost:8788/mcp.
To test with MCP Inspector:
npx @modelcontextprotocol/inspector@latestOpen http://localhost:5173, enter http://localhost:8788/mcp, click OAuth Settings > Quick OAuth Flow, authorize on GitHub, then Connect > List Tools.
You should see the "alive" tool.
- Return to https://github.com/settings/developers
- New OAuth App:
- Application name:
MCP Vault (prod) - Homepage URL:
https://your-worker-name.your-domain.workers.dev - Authorization callback URL:
https://your-worker-name.your-domain.workers.dev/callback
- Application name:
npx wrangler secret put GITHUB_CLIENT_ID
npx wrangler secret put GITHUB_CLIENT_SECRET
npx wrangler secret put COOKIE_ENCRYPTION_KEY
npx wrangler secret put R2_ACCESS_KEY_ID
npx wrangler secret put R2_SECRET_ACCESS_KEY
npx wrangler secret put CF_ACCOUNT_ID
npx wrangler secret put ALLOWED_GITHUB_ID
npx wrangler secret put ALLOWED_GITHUB_LOGIN(Wrangler prompts you interactively for each secret value)
npm run deployYour MCP is live on https://your-worker-name.your-domain.workers.dev/mcp
Add to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"vault": {
"command": "npx",
"args": [
"mcp-remote",
"https://your-worker-name.your-domain.workers.dev/mcp"
]
}
}
}Restart Claude Desktop. On first use, a GitHub authorization window opens.
Then ask Claude: "List my vault files" and you should see the tools in action.
second-brain-vault/
src/
index.ts # Entry point: OAuthProvider + MCP server + tools
github-handler.ts # GitHub OAuth flow (authorize, callback)
types.ts # Env type definitions
constants.ts # Configuration constants
utils/ # Helper functions
tools/ # MCP tools (one file per tool)
package.json
wrangler.jsonc # Cloudflare Workers config + bindings
tsconfig.json
.env # Secrets for local dev (do not commit)
.env.example # Template for .env
Once "alive" works, you can:
- Add an R2 binding in
wrangler.jsoncfor a vault bucket - Add more tools in the
src/tools/directory (store_entry, list_entries, etc.) - Read the GitHub token in tools to identify the user
- Integrate with rclone for local file sync
See ARCHITECTURE-VAULT.md and GUIDE-MCP-WORKER-OAUTH.md for more details.