Skip to main content
Glama
Second Brain MCP

Second Brain MCP

by MihaiBarascu

second-brain-mcp

An MCP server that lets ChatGPT, Claude and other MCP clients list, search, read and append notes in an Obsidian vault stored in a GitHub repository.

The vault stays a normal Git repository: you keep editing it in Obsidian and syncing it with Git. The server is a small Cloudflare Worker that reads and writes files through the GitHub REST API, so every change made by an AI client is an ordinary commit you can review or revert.

Architecture

MCP client (ChatGPT, Claude, Claude Code, Cursor, ...)
   │  Streamable HTTP + OAuth 2.1 bearer token
   ▼
Cloudflare Worker
   ├─ @cloudflare/workers-oauth-provider   OAuth 2.1 authorization server (tokens stored in Workers KV)
   │     └─ /authorize → consent page → Google sign-in → email allowlist
   └─ Hono + @hono/mcp                     MCP endpoint at /mcp
         │  GitHub REST API (fine-grained token)
         ▼
GitHub repository with the Obsidian vault  (source of truth)
  • Cloudflare Worker: stateless. It stores OAuth grants and tokens in a KV namespace and nothing else.

  • Hono + @hono/mcp: the MCP server (@modelcontextprotocol/sdk) is exposed through the Streamable HTTP transport on /mcp.

  • OAuth: workers-oauth-provider implements the authorization server side (metadata discovery, dynamic client registration, client ID metadata documents, token endpoint, PKCE). The app only handles /authorize: it shows a consent page, sends the user to Google, checks that the returned email is in GOOGLE_ALLOWED_EMAILS and then completes the authorization for the MCP client.

  • GitHub REST API: the list of notes comes from the Git tree API; reads and writes use the contents API. There is no cache or local copy.

The server is in src/index.ts; the consent screen and browser binding are in src/consent.ts.

Related MCP server: vault-mcp

Tools

Tool

Arguments

What it does

Writes

list_notes

none

Lists every .md file in the repository

no

read_note

path

Returns the full content of one note

no

search_notes

query

Case-insensitive text search over all notes; returns matching files with up to 3 matching lines each

no

add_to_inbox

text

Appends a dated checkbox line to the inbox note (INBOX_PATH)

yes, inbox note only

write_note

path, content, message?, allow_anywhere?

Creates or replaces a note

yes, inbox folder only unless allow_anywhere: true

Write safety

  • add_to_inbox is the default way to save something. It only appends a line to one file, and it sends the file's current SHA to GitHub, so a concurrent change makes the commit fail instead of being overwritten.

  • write_note accepts only paths inside the inbox folder (the folder of INBOX_PATH). Writing anywhere else requires allow_anywhere: true; the tool description tells the model to set it only when the user explicitly asked. Paths must end in .md and cannot contain ...

  • Every write is one commit on the configured branch, with a message, so it shows up in the Git history and can be reverted.

  • The GitHub token should be a fine-grained token limited to the vault repository with Contents: Read and write.

The allow_anywhere flag is a convention that depends on the client and the model following the tool description; it is not an access control. Access control is the Google allowlist plus the scope of the GitHub token.

Sign-in security

Client registration is open (any MCP client can register itself, as the MCP spec expects), so a registered client is not trusted by itself. Without extra checks, someone could register a client with their own redirect URI, send you a crafted /authorize link and receive a token for your vault as soon as you sign in with Google. The sign-in flow closes that gap:

  1. Consent screen. GET /authorize validates the request, then shows a page with the client's name, client ID, website, the scopes (read and write to the vault) and, most prominently, the exact redirect URI that will receive the token. Every client-supplied string is HTML-escaped; the page loads no external assets and cannot be framed. It is shown for every client, including well-known ones; nothing is auto-approved.

  2. CSRF protection. The Approve / Deny form carries a random token that must equal a __Host- cookie (HttpOnly, Secure, SameSite=Lax, 10 minutes) and the token stored with the pending request in KV. Comparisons are constant-time. The pending request lives server-side under a one-time id.

  3. Browser-bound state. On Approve, the Worker creates the Google state, stores the request under it in KV (one-time, 10 minutes) and sets a second __Host- cookie with that state. The Google callback is accepted only if the cookie matches state, so a Google sign-in link started in someone else's browser cannot complete in yours. Both KV entries are deleted on use and the cookies are cleared at the end.

  4. Deny redirects back to the client with error=access_denied and the client's state, as OAuth requires.

  5. Identity is read only from the ID token in Google's token-endpoint response (server to server over TLS), then checked against GOOGLE_ALLOWED_EMAILS.

Before pressing Approve, check that you started the connection yourself and that you recognise the redirect address (for example claude.ai, chatgpt.com or localhost for a local client).

Why OAuth instead of a Cloudflare Access service token

An earlier version put the Worker behind Cloudflare Access and required a service token (CF-Access-Client-Id / CF-Access-Client-Secret headers). That works for clients where you can configure custom headers (Claude Desktop config, Claude Code, Codex, VS Code), but not for clients that only accept a server URL, such as ChatGPT and Claude on the web.

Those clients follow the MCP authorization spec instead: they discover the authorization server from /.well-known/oauth-protected-resource, register themselves, and open a browser window where the user signs in. With OAuth on the Worker, every client connects with only the URL, and access is still limited to the Google accounts in the allowlist.

Setup

Requirements: Node.js 20 or newer, a Cloudflare account (the Workers free plan is enough), a Google Cloud project for the OAuth client, and a GitHub repository with your vault.

  1. Install dependencies:

    npm install
  2. Create the KV namespace for OAuth state and put its id in wrangler.jsonc:

    npx wrangler kv namespace create OAUTH_KV
  3. Edit the vars in wrangler.jsonc:

    Variable

    Meaning

    OWNER

    GitHub user or organization that owns the vault repository

    REPO

    Vault repository name

    BRANCH

    Branch to read and commit to (default main)

    INBOX_PATH

    Inbox note used by add_to_inbox; its folder is the default write area (default 00-INBOX/Inbox.md)

    GOOGLE_ALLOWED_EMAILS

    Comma-separated Google accounts that may sign in

  4. Create a Google OAuth client (Google Cloud Console → APIs & Services → Credentials → OAuth client ID, type "Web application") with the redirect URI https://<your-worker-host>/oauth/google/callback. For local development also add http://localhost:8787/oauth/google/callback.

  5. Create a fine-grained GitHub token for the vault repository with Contents: Read and write.

Run locally

cp .dev.vars.example .dev.vars   # fill in GITHUB_TOKEN, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
npm run dev                      # http://localhost:8787, MCP endpoint at /mcp
npm run typecheck
npm test                         # unit tests for the consent flow (Node 22.6+)

You can test it with the MCP Inspector (npx @modelcontextprotocol/inspector) pointed at http://localhost:8787/mcp.

Deploy

npx wrangler login
npx wrangler secret put GITHUB_TOKEN
npx wrangler secret put GOOGLE_CLIENT_ID
npx wrangler secret put GOOGLE_CLIENT_SECRET
npm run deploy

The MCP endpoint is https://<your-worker-host>/mcp.

Connecting clients

All clients use the same URL and sign in through the browser on first use.

  • ChatGPT: Settings → Apps & Connectors → add a custom connector (developer mode) with the /mcp URL.

  • Claude (web and desktop): Settings → Connectors → Add custom connector with the /mcp URL.

  • Claude Code: claude mcp add --transport http brain https://<your-worker-host>/mcp, then /mcp to sign in.

  • Other clients (Cursor, VS Code, Codex): add a Streamable HTTP server with the /mcp URL; clients that support MCP OAuth start the sign-in themselves.

The exact menu names change between client versions.

Limitations

  • search_notes reads every note through the GitHub API on each call. It is fine for a vault of a few hundred notes; larger vaults will be slow and can hit the GitHub rate limit (5,000 requests per hour for a token). The contents API also does not return files larger than 1 MB.

  • There is no delete, move or rename tool.

  • write_note replaces the whole file and does not check for concurrent edits.

  • Every allowed user gets both read and write access; the mcp:read / mcp:write scopes are declared but not enforced per tool.

  • The MCP transport runs in stateless mode; there are no server-initiated notifications.

  • Only Google is supported as the identity provider.

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Remote MCP server that exposes a personal git repository of markdown notes to Claude, enabling reading, writing, searching, and running scripts with automatic git commits and GitHub OAuth authentication.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Authenticated remote MCP server that exposes a private GitHub-hosted Obsidian vault to Claude, enabling list, read, write, and search operations on notes.
      9
      MIT