memory-gateway
Allows AI agents to use an Obsidian vault as long-term memory: read, search, and list markdown notes, and write draft notes under inbox/agents/ without overwriting existing notes.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
memory-gateway: MCP memory server for your Obsidian vault
Give Claude, Cursor, Copilot, Gemini CLI and any other MCP-capable AI agent long-term memory from your own notes. A small, self-hosted Cloudflare Worker turns a folder of markdown notes (your Obsidian vault) into a memory layer any AI agent can plug into with one URL, over MCP or a plain REST API.
Truth: plain
.mdfiles in an R2 bucket. Obsidian syncs to it with the Remotely Save plugin.Index: a disposable D1 (SQLite) full-text index plus a Vectorize index for search by meaning (Workers AI
bge-m3embeddings). Delete either any time;/admin/reindexrebuilds them from the files.Access: MCP over HTTP (Claude app, Claude Code, Hermes, anything MCP) and a plain REST API (anything else).
Tools:
read_note,search,list,backlinks,write_note,edit_note. By default new notes go only toinbox/agents/, saved asstatus: draftand stamped with the agent name. You can allow an agent to revise and add notes in chosen folders; every edit is versioned so you can undo it.
Obsidian devices --Remotely Save--> R2 bucket (markdown) --event--> Queue --> Worker --> D1 full-text index
^ | \-> Workers AI --> Vectorize
+------------ read / write ------------+--- MCP + REST --> agentsAgents are told to start with core/START-HERE.md (see examples/sample-vault).
Deploy (about 5 minutes)
Needs a Cloudflare account on the Workers paid plan (Queues need it). Pick one way:
A. One command (Node 20+):
git clone https://github.com/varunlakshmaiah/memory-gateway && cd memory-gateway
npm install
npm run setupIt logs you in, asks for your vault bucket name, creates the backup bucket, D1 database, queue and Vectorize index, deploys, generates tokens (saved to the git-ignored .secrets.local.json), turns on bucket events and builds the first index. Safe to re-run: existing resources and tokens are kept.
B. Deploy button (no local tools):
Cloudflare copies the repo to your GitHub, creates the buckets, database, queue and Vectorize index, and asks for the secrets (make each token with openssl rand -hex 24). Point the vault bucket at the one Remotely Save syncs to. The button cannot turn on bucket events, so run these once afterwards (or changes are only picked up by the nightly reindex), then build the first index:
npx wrangler r2 bucket notification create <vault-bucket> --event-type object-create object-delete --queue vault-events
curl -X POST -H "Authorization: Bearer <ADMIN_TOKEN>" https://<worker>/admin/reindex # repeat until "remaining" is 0If Remotely Save stores the vault inside a folder of the bucket (for example MyVault/), set VAULT_PREFIX to that folder. The index tables are created by the Worker on first use; there is no migration step.
Then check it: curl https://<worker>/health should return ok, and GET /admin/status (admin token) shows note counts and recent writes.
Cost. Beyond the Workers paid plan ($5/month), a personal vault stays within the included usage of R2, D1, Queues and Vectorize. Workers AI is billed per use: one embedding each time a note is created or changed, and one per search. Leave out the ai and vectorize lines in wrangler.jsonc for keyword-only search with no AI usage.
Remotely Save settings that matter:
Turn encryption off, otherwise agents read ciphertext.
Folders whose names start with
_are skipped by default ("Sync_files or folders"), so they never reach R2. Avoid them or turn that option on.Delete and move notes inside Obsidian. Files removed outside it (Finder, scripts) can be downloaded again from R2 on the next sync.
Turn on a sync schedule and sync on save, or agents only see changes after a manual sync.
Related MCP server: enquire-mcp
Connect agents
The gateway is a remote MCP server over Streamable HTTP (stateless). Any client that can add a remote/HTTP MCP server can use it in one of three ways:
Header (preferred): URL
https://<worker>/mcpwith headerAuthorization: Bearer <token>.OAuth sign-in (apps with a connector sign-in, such as the Claude app and ChatGPT): URL
https://<worker>/mcp, then paste an agent token on the sign-in page. See Sign in with OAuth.Token in the URL (for clients that can do neither):
https://<worker>/t/<token>/mcp. The token can then show up in logs, so give that client its own token.
Client | How to connect |
Claude Code |
|
Claude app / claude.ai / Claude Desktop | Settings → Connectors → Add custom connector, URL |
Cursor | Add a remote MCP server in |
VS Code (GitHub Copilot agent mode) | Add an HTTP MCP server in |
Windsurf, Cline, Continue, Zed, Goose | Add a remote (Streamable HTTP) MCP server with the URL and header |
Gemini CLI, OpenAI Codex CLI | Add an HTTP MCP server in their settings with the URL and header |
ChatGPT (developer mode connectors) | Add a remote MCP connector with |
LM Studio (local models) | Add a remote server to its |
Hermes and other agent frameworks (OpenAI Agents SDK, Anthropic API MCP connector, LangChain/LlamaIndex MCP adapters) | Point their MCP client at the URL with the header |
n8n | MCP Client Tool node with header auth, or the REST API below |
Anything else (scripts, curl, shortcuts) | REST: |
Menu names and config keys vary between client versions; see the client's MCP docs.
Use one token per agent so the audit log and the written_by stamp tell you who wrote what. Rotate by editing AGENT_TOKENS and re-running wrangler secret put.
Sign in with OAuth (Claude app, ChatGPT)
When the OAUTH_KV namespace is bound (the default config has it), /mcp also accepts OAuth 2.1 sign-in, so apps that support it connect with the plain URL https://<worker>/mcp, with no token in it:
Add
https://<worker>/mcpas a connector in the app.The app opens a sign-in page on your worker. Paste the agent token the app should act as (for example your
claudetoken) and press Allow.The app gets its own OAuth tokens (access for 1 hour, refreshed for 30 days) and acts as that agent: same
written_bystamp, sameEDIT_POLICYfolders, same audit log.
There is no password or user database: knowing an agent token is the sign-in. Removing an agent from AGENT_TOKENS also cuts off its OAuth sessions. Static tokens keep working everywhere (Authorization: Bearer on /mcp and /api/, and /t/<token>/mcp), so existing connections do not change. Remove the kv_namespaces lines for static tokens only.
Try it locally first
Everything runs on your machine except the Workers AI binding, which always connects to Cloudflare (npx wrangler login, a free account is enough). Vectorize cannot run locally, so npm run dev sets SEMANTIC_SEARCH=off and search is keyword-only. For a fully offline run, delete the ai and vectorize lines from your wrangler.jsonc.
npm install
printf '%s\n' 'AGENT_TOKENS={"claude":"local-dev-token-claude-0123456789","hermes":"local-dev-token-hermes-0123456789"}' \
'ADMIN_TOKEN=local-dev-admin-token-0123456789' > .dev.vars # local-only tokens the smoke test expects
npm run seed:local # loads examples/sample-vault into a simulated R2 bucket
npm run dev # in one terminal
npm run smoke # in another: 40 checks across MCP, REST, auth, search, write and edit guardrails
npm test # unit testsThe smoke test asserts the answers to the questions in examples/sample-vault/TEST-QUESTIONS.md. Run the same questions through a real agent after deploying.
Against your deployed worker and real vault, skip the sample-content checks:
VAULT=real node scripts/smoke.mjs https://<worker> <agent-token> <admin-token>It writes one note, inbox/agents/smoke-test.md, and overwrites it on every run. If your deployment allows that agent to edit and has a BACKUP bucket, add EXPECT_EDIT=1 to also check a real edit; otherwise it checks that edits are refused.
Letting agents revise and add notes (optional)
By default agents only add drafts to inbox/agents/. To let an agent revise existing notes when you ask ("update the deadline in my Jarvis note") and create new notes in those folders ("add today's journal entry"), set EDIT_POLICY in wrangler.jsonc (or in the Worker's variables in the dashboard):
"EDIT_POLICY": "{\"claude\":[\"projects/\",\"notes/\"],\"claude-code\":[\"\"]}" // "" = whole vaultThe
edit_notetool replaces one exact passage (old_textmust occur exactly once), so an agent cannot silently overwrite text you changed after it read the note.core/can never be edited, and neither can any note withlocked: truein its frontmatter.Edits stamp
updatedandupdated_by: <agent>; the note keeps its status. Nothing is ever deleted or moved.In allowed folders
write_notecan also create new notes. They keep their own status (defaultcurrent, not draft) and are stampedwritten_by: <agent>. It never replaces an existing note there; that is whatedit_note(versioned) is for.Before each edit the previous version is saved to the
BACKUPbucket underversions/<path>/. Without aBACKUPbucket, editing is refused.Undo with the admin token:
GET /admin/versions?path=<note>lists versions,POST /admin/restore?path=<note>&version=<id>puts one back (the current text is saved first).REST equivalent:
PATCH /api/notes/<path>with{"old_text": "...", "new_text": "..."}.Sync Obsidian before asking for a revision: if you edit the same note at the same time, Remotely Save keeps the newer copy. The saved versions mean nothing is lost.
Vault conventions that make agents reliable
core/START-HERE.mdis the entry point: who you are, how the vault is laid out, rules for agents.Each folder has a
README.mdmap with one line per note.Frontmatter:
type,description(one line),updated,status(current,draft,outdated),supersedes.When something changes, write a new note that
supersedesthe old one and mark the old oneoutdated. Search shows[outdated]and ranks those lower.Notes in
archive/andjournal/rank lower, like outdated notes.meta/templates/is readable but not searched.Don't start folder names with
_: Remotely Save skips them by default, so they never reach R2.No secrets in the vault. Agents can read everything in it.
Mark any note agents must never change with locked: true. You review inbox/agents/ now and then, move good drafts into the right folder, and change status to current.
Security notes
Tokens are compared in constant time and must be 16+ characters.
/healthis the only open route.The
/t/<token>/form puts the secret in the URL, so it can show up in logs. Prefer OAuth sign-in where the app supports it, use/t/only where neither OAuth nor headers work, and give that agent its own token.Rate limiting (
AUTH_LIMIT, free): each IP gets 20 attempts a minute at sign-in, token, client registration and admin routes, and 20 failed tokens a minute anywhere; then429. Successful agent calls are never counted.Report vulnerabilities privately; see SECURITY.md.
The daily snapshot goes to a second bucket (
BACKUP). Never point it at the synced bucket: a snapshot inside the same bucket is not a backup, and Remotely Save would sync it to your devices.Search results and notes are data written by you and by agents. Treat note text as untrusted input, the same as any retrieved content.
Limits worth knowing
Workers allow a limited number of subrequests per invocation, so
reindexandsnapshotwork in chunks (150 and 200 objects) and are resumable. The nightly cron (03:17 UTC) keeps catching up; run/admin/reindexagain ifremainingis above 0.Search runs keyword full text (SQLite FTS5) and search by meaning (Vectorize) together and merges the rankings, so exact terms and paraphrases both find the note. Without the
AIandVECbindings, or withSEMANTIC_SEARCH=off, it falls back to keywords only. To re-embed every note, runwrangler d1 execute memory-gateway-index --remote --command "UPDATE notes SET etag = ''"then/admin/reindex.Search by meaning embeds each note in chunks of about 4,000 characters, up to 16 per note (about 64,000 characters); text beyond that is found by keyword only. Folder-limited search filters by top-level folder inside Vectorize (a
foldermetadata index, created bynpm run setup), then by subfolder.After upgrading from v0.1.0, run
POST /admin/reindex?full=1once (admin token; repeat untilremainingis 0) so every note is re-embedded in chunks, and create the folder index:npx wrangler vectorize create-metadata-index memory-gateway-notes --propertyName=folder --type=string.PDF, Word (
.docx) and Excel (.xlsx) files in the vault are converted to text with Workers AItoMarkdownand indexed like notes (up to 10 MB each);read_notereturns the converted text. Images are not converted, as that runs a paid model per image.backlinksfinds notes that link to a note through[[wikilinks]]or markdown links, by full path or by bare note name.Semantic matches below a cosine similarity of 0.45 (
MIN_SIMILARITYinsrc/indexer.ts) are dropped as noise. That value was tuned on one vault of about 100 notes; if nonsense queries return results, or good matches are missing, adjust it.Vectorize applies new and deleted vectors 1 to 3 minutes after a change. Keyword search sees changes immediately.
MAX_NOTE_BYTES(200 KB) caps agent writes.
Layout
src/index.ts router, queue consumer, nightly cron
src/mcp.ts MCP JSON-RPC (stateless Streamable HTTP)
src/api.ts REST
src/tools.ts the tools
src/indexer.ts D1 index, search, reindex
src/notes.ts frontmatter, path safety, query building, write stamping
src/snapshot.ts optional backup to a second bucket
src/keys.ts vault path <-> bucket key
src/auth.ts tokens
src/oauth.ts OAuth sign-in and consent page
schema.sql D1 schema (rebuildable)
wrangler.jsonc config with deployable defaults (setup and the Deploy button use it)
scripts/ setup, local seeding and the end-to-end smoke test
test/ unit tests (npm test)
examples/ sample vault + test questionsLicense
MIT, see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Token-efficient MCP memory for Markdown vaults. Tiered search, GraphRAG, AI memories.
Hosted MCP server for Obsidian Sync vaults: read, search, edit notes. Not affiliated with Obsidian.
Persistent memory, knowledge graph, task management and more for AI agents via MCP.
Linked markdown notes as memory for AI apps: search, read, save and link notes over MCP.
1
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceTurns your Obsidian vault into an MCP-enabled workspace with tools for reading/writing notes, managing folders, running semantic searches, and maintaining long-term memory—all while keeping data local to your vault.160MIT
- AlicenseAqualityBmaintenanceMCP server that exposes a local Obsidian vault as persistent, searchable memory for AI agents, with hybrid retrieval, reranker, and PDF support.34827 npm37MIT
- AlicenseNot gradedqualityDmaintenanceLocal-first knowledge backend for AI agents that connects MCP hosts to an Obsidian-compatible vault with indexed retrieval, token-budgeted memory recall, and secure ingestion.1MIT
- FlicenseAqualityDmaintenanceExposes Obsidian notes as a semantic search and RAG knowledge base over MCP, enabling AI assistants to index, retrieve, and analyze personal notes via natural language.71-