Skip to main content
Glama

Memory Gate

One authoritative vault. Many assistants. Scoped reads. Human-approved writes.

What it is

Memory Gate puts a wall around a folder of Markdown notes that several AI assistants share. It is an MCP server plus six small command-line tools, written in Python on top of Postgres. Each assistant reads only the part of the vault its scope allows. No assistant can change a note: it can only propose text. A person approves or rejects each proposal, and one writer appends the approved text to the vault.

Related MCP server: wikicore

The problem

You run several assistants over one knowledge base: a chat app with an MCP connector, a coding agent, perhaps a scheduled job. As soon as they share a memory, three questions come up:

  • Who may read what? Some notes are for every assistant, some for one of them only.

  • Who may change it? An assistant can be wrong, or can be talked into writing something by a page it read. What it writes, the others read as fact.

  • How do you know what a machine wrote? Months later, which lines came from which assistant, and who let them in?

Memory Gate answers each question with a mechanism you can test, not with a prompt.

How it works

flowchart LR
    vault[("Vault folder: Markdown notes, git")]
    sync["memory-gate-sync"]
    db[("Postgres: notes by scope, proposals, decisions")]
    server["memory-gate (MCP server)"]
    a1["Assistant A, scopes: public, finance"]
    a2["Assistant B, scope: public"]
    person["Person with memory-gate-review"]
    writer["memory-gate-writer"]

    vault -->|"1 copy"| sync
    sync --> db
    db -->|"2 only the caller's scopes"| server
    server --> a1
    server --> a2
    a1 -.->|"3 propose"| server
    a2 -.->|"3 propose"| server
    server -.-> db
    db -.->|"4 pending proposals"| person
    person -.->|"5 approve or reject"| db
    db -.->|"6 approved proposals"| writer
    writer -.->|"7 append a block, one git commit"| vault

Solid arrows are the read path, dotted arrows the write path.

Reading

  1. memory-gate-sync copies the vault folder into Postgres. Each note gets a scope from its path (for example everything under Finance/ is finance, the rest public).

  2. An assistant calls search, fetch or recent on the MCP server with its own bearer token. The server connects to Postgres as that assistant's own database role, and the database returns only notes of the scopes that role is a member of. A note in another scope answers not found, exactly like a note that does not exist.

Writing

  1. An assistant calls propose with a text and a target note. Nothing is written. The proposal is stored, immutable, under the assistant's name.

  2. A person lists the pending proposals with memory-gate-review and reads one in full. Hidden characters and terminal escape sequences are shown as visible escapes.

  3. The person approves or rejects it, naming the revision they saw.

  4. memory-gate-writer takes the approved proposals and appends each one to its note as a marked block, without touching the existing text.

  5. Each write is one git commit in the vault. The next sync makes the block readable. Every step leaves a row in an append-only history.

More in docs/architecture.md.

What you get

Piece

What it does

Reference

memory-gate

the MCP server (streamable HTTP, or local stdio for one consumer). Five tools: search, fetch, recent, propose, my_proposals

docs/server.md

memory-gate-admin

sets a database up as its owner, one command per step: applies the schema shipped in the package, registers scopes, creates each consumer's and each tool's login role with a random password and token written to a file of mode 600 (never shown), sets the path policy

docs/operations.md

memory-gate-sync

copies a folder of Markdown notes into Postgres, with a scope per path prefix

docs/sync.md

memory-gate-review

the approver's terminal tool: list, show, approve, reject, unwritten, requeue, release

docs/review-and-writer.md

memory-gate-writer

the one writer: appends approved proposals to the vault, append-only, one git commit each

docs/review-and-writer.md

memory-gate-pending

tells a scheduled job whether proposals wait: one line and an exit code (0 none, 10 some); delivery is your own tool

docs/review-and-writer.md

memory-gate-verify

a read-only check that a live database still enforces the wall: roles, grants, triggers, and probes as each consumer

docs/verify.md

schema/

four SQL files: roles, the scoped view, proposals, outcomes, history

schema/README.md

kit/

what a person needs around it: kit/VAULT_SCHEMA.md and a policy template, guard hooks for coding agents (kit/hooks/), a vault linter (kit/lint/vault_lint.py), a database backup with a restore test (kit/backup/)

kit/README.md

demo/

all of it in Docker, with a vault of invented notes

docs/demo.md

Demo in 5 minutes

You need Docker with Compose v2 and Python 3. From the repository root:

demo/setup.sh
docker compose -f demo/docker-compose.yml --env-file demo/.env up -d --build
python3 demo/try.py
python3 demo/loop.py

setup.sh writes random secrets to demo/.env (mode 600) and prints none of them. Compose starts Postgres, applies the schema, creates two consumers, copies demo/vault/ into a volume, syncs it and starts the server on 127.0.0.1:8000. alice reads the scopes public and finance; bob reads public only.

try.py calls the server as both. Abridged:

1. search "budget" (a word that appears only in Finance/)
   alice  2 result(s): Finance/budget.md, Finance/savings-plan.md
   bob    0 result(s)

2. fetch Finance/budget.md, then a note that does not exist
   bob    Finance/budget.md: error: Error executing tool fetch: not found
          Finance/no-such-note.md: error: Error executing tool fetch: not found
   bob's two answers are identical: bob cannot tell a hidden note from a missing one.

4. propose a change (nothing is written: a person approves first)
   alice  proposal 1: decision=pending execution=none

loop.py runs the write loop: propose, an approval with an outdated revision that is refused, the approval, the writer, the sync, and the note with its new block. Abridged:

$ review approve 3 --revision 1   (exit 0)
   proposal 3 approved (revision now 2): it is queued for the writer
$ writer   (exit 0)
   writer finished: written=1 (already_present=0) failed=0 skipped=0 resumed=0 errors=0 written_ids=3

5. alice fetches Projects/garden-planner.md: the approved text is there, marked with its proposal
   <!-- memory-gate:proposal=3 -->
   ## Added via Memory Gate (2026-11-29 UTC, proposal 3, from alice)

   Weather log: water early in the morning when the forecast says above 28 degrees.
   <!-- /memory-gate:proposal=3 -->

Check the wall, then remove everything:

docker compose -f demo/docker-compose.yml --env-file demo/.env run --rm verify
docker compose -f demo/docker-compose.yml --env-file demo/.env --profile tools down -v --rmi local
rm -rf demo/.env demo/backups

The verifier ends with verify: 47 passed, 0 failed, 0 warning(s). The full walk-through, with the review tool by hand, a deliberately broken grant, the backup and the linter, is in docs/demo.md. The demo is for one machine, not for production: plain HTTP on localhost, and the schema applied by a superuser.

Security model in one page

Each line is an invariant, the mechanism that holds it, and the row of the test map (docs/threat-tests.md) that names the tests.

Invariant

Mechanism

Tests

A consumer reads only the scopes it was given, and cannot tell a hidden note from a missing one

The server connects to Postgres as the consumer's own login role. A security_barrier view filters on the scope roles that login role is a member of. No consumer can select from the notes table

T1

A consumer cannot act as another

One bearer token per consumer, compared in constant time. The database records the role that logged in, never a parameter

T2

Nothing reaches the vault without an approval

A consumer's role can only insert a proposal. Only the approver's decision moves it to the write queue, and the writer reads nothing else

T16

The approver sees the whole proposal, and decides on the version they saw

Proposals are immutable. Every field is neutralised for the terminal. Each decision is compare-and-swap on a revision

T4, T5

One writer, append-only, inside the vault folder

A claim is compare-and-swap. The writer appends a marked block, never follows symbolic links, and refuses any text that contains or imitates its own marker

T6, T7, T8, T17

The record is append-only

Triggers refuse changes to proposals and to the history, for the schema owner too. Every change adds a history row

T18

Note text, tokens and DSNs stay out of logs and error messages

One metadata line per call. Database errors are reduced to a class and a code. Client messages are fixed texts

T10

The wall can be checked from outside

memory-gate-verify checks roles, memberships, the effective privileges of every role, triggers and rules against an expected file, and probes as each consumer. It does not compare the text of functions and views with the shipped schema (V5)

T11, T12

Not covered. The full list, 66 items by category, is in docs/threat-model.md. The ones to know before you rely on this:

  • The operating system user that runs the tools, the schema owner and any database superuser are outside the wall. They can read every scope and disable the triggers.

  • A note is returned as data with a notice that it is not instructions. A language model may follow it anyway.

  • In local stdio mode the client holds a database credential: it can go around the server's checks, not around the database's.

  • Once a client has read a note, Memory Gate has no say in where the client sends it.

  • A stolen token is that consumer until you revoke it. Tokens do not expire.

  • The server speaks plain HTTP and has no rate limit: it needs a reverse proxy in front.

  • A person who approves without reading approves anything. Persuasive but visible text is not detected.

  • Paths the owner marks auto_approve are written without a person when the proposer reads nothing but public. The outcome of an approved proposal lets its author probe notes it cannot read.

  • The guard hooks for coding agents in kit/hooks/ are heuristics with a documented list of bypasses. File permissions are the boundary there.

  • Answer times are not equalised between a hidden note and a missing one.

  • Nobody outside the project has audited any of this.

To report a vulnerability, see SECURITY.md.

How it compares

Memory Gate adds per-consumer scopes inside one memory (enforced in the database), writes only as proposals, a person's approval, one writer and an append-only record. It lacks things other tools have: search by meaning, connectors to mail and chat, automatic capture, a hosted option, a web interface, OAuth. If you want an assistant that remembers on its own and finds things by meaning, look elsewhere. docs/comparison.md describes the neighbouring kinds of tools and compares one named project, fact by fact, from its own pages.

Status and maintenance

  • Version 0.1, unreleased. A reference implementation: small, meant to be read, run and adapted.

  • Maintained by one person, on a best-effort basis. No roadmap promises and no guaranteed response time.

  • Not audited by a third party. The evidence is the test suite and the verifier.

  • In scope: fixes to the invariants above, to the tools and to the documentation.

  • Planned next: OAuth, which hosted clients such as ChatGPT require for a protected server, an optional search by meaning, and refused proposals that are stored and counted, so that the answer under a forbidden prefix stops being a free probe (D11).

  • Out of scope for now: several vaults in one deployment, a web interface, a hosted service, Windows.

Platforms. The package needs Python 3.12 or later, and the schema PostgreSQL 16 or later. The CI workflow (.github/workflows/ci.yml) runs the test suite on Linux (ubuntu-latest, Python 3.12) against PostgreSQL 16 and 17; it is also run on macOS (arm64). The demo runs the tools in Linux containers (python:3.12-slim, postgres:17-alpine). Not on PyPI yet: install from a checkout, with uvx --from git+https://github.com/diegochiavarelli-code/memory-gate memory-gate-admin --help, or build the image (docs/operations.md). Windows is not supported: the writer relies on POSIX file descriptors and flock.

Origin. The design comes from a private single-user setup. This repository is a clean re-implementation of the core ideas, not the code that runs there.

Documentation

Document

For

docs/architecture.md

components, data model, the state machine of a proposal, design decisions

docs/demo.md

the demo, step by step

docs/server.md

configuration, tools, errors, logging

docs/sync.md

the scopes file, what is copied, deletions

docs/review-and-writer.md

review commands, block format, failure reasons, crash recovery, git

docs/verify.md

the expected file and every check

docs/connecting-clients.md

pointing an MCP client at the server; which clients cannot connect

docs/operations.md

production checklist, scheduling, upgrades, monitoring, incidents, restore

docs/threat-model.md

assets, actors, threats, and every known limitation

docs/threat-tests.md

each threat mapped to the tests that cover it

docs/comparison.md

related work

docs/faq.md

short answers

schema/README.md

applying the schema, roles and privileges, error codes

kit/README.md

the governance kit

CONTRIBUTING.md, CHANGELOG.md, SECURITY.md

tests, what exists, reporting

License

Apache License 2.0. See LICENSE and NOTICE.

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
      D
      maintenance
      Enables AI agents to securely read and write to an Obsidian-compatible Markdown vault with per-agent access control, audit logging, and conflict resolution.
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to build and maintain a shared, git-backed Markdown wiki: they search, file, update and link notes with YAML frontmatter, keep verbatim sources, and optionally read code repos, so knowledge one assistant records is available to all the others. Runs without LLM calls, embeddings or a database, with the vault's own files defining page types, instructions and tools.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to load bounded, verified-first team context from a shared markdown vault and propose human-approved writebacks through a server-enforced safety gate.
      1
      Apache 2.0