Skip to content

About

local mcp server for persistent agent knowledge

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

knowledge-mcp

An MCP server for persistent agent knowledge. Agents query and write structured knowledge about projects — conventions, subsystem understanding, and design decisions — without re-reading source files every time.

Quick Start

One command downloads the binary for your platform and wires everything up (OpenCode MCP entry, agent instructions block, skill, and the Grep/Glob augment hook):

curl -fsSL https://raw.githubusercontent.com/renderorange/knowledge-mcp/main/install.sh -o install.sh
chmod +x install.sh
./install.sh --root /path/to/org --global /path/to/global-store

Flags passed to install.sh become the server's flags (--root, --project, --global, --store, --index). --version <tag> pins a specific release; --dry-run previews what would happen.

What install writes:

  • the MCP server entry in ~/.config/opencode/opencode.jsonc (marker-delimited)
  • an instruction block in ~/.config/opencode/AGENTS.md
  • the knowledge-mcp skill at ~/.config/opencode/skills/knowledge-mcp/SKILL.md
  • the augment plugin at ~/.config/opencode/plugins/knowledge-mcp.ts
  • an install record at ~/.config/knowledge-mcp/install.json

The plugin intercepts Grep/Glob and appends matching knowledge-store entries to the results, so agent searches surface stored conventions automatically.

Remove the integration (data-safe — store files are never touched):

knowledge-mcp uninstall [--remove-binary]

The client manages the server process — you don't need to run it manually.

Build From Source

make build

Or with a specific version:

make build/1.2.3

Check the version:

./knowledge-mcp --version

make install builds and deploys the binary where the MCP config reads it — the same directory install.sh resolves: the existing install's directory when writable (so upgrades land in place, e.g. /home/blaine/bin), else the first writable $HOME/* or /usr/local/bin dir on PATH, else ~/.local/bin. Both share scripts/install-dir.sh, so they can never disagree. It uses install(1) so it cannot fail with "Text file busy" while the server holds the old file. After installing, restart the server (only the client can): the running process keeps executing the old inode until it is respawned.

Behavior evals

make eval-mock runs the deterministic mock tier (no API key); make eval runs the full real-tier agent-behavior suite (needs a model provider). Scenarios live in evals/scenarios/*.yaml with mock contracts in evals/mock_agents/*.jsonl.

Modes

Single-project

Targets one project root. Indexes its knowledge/ store.

// opencode.jsonc
{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp", "--project", "/path/to/project"],
      "type": "local"
    }
  }
}

Org-wide

Discovers all projects under the org root. Indexes per-project and org-level knowledge/.

// opencode.jsonc
{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp", "--root", "/path/to/org"],
      "type": "local"
    }
  }
}

Multi-root / multi-project

Repeat --root and --project as needed; they can be mixed:

// opencode.jsonc
{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp",
        "--root", "/home/blaine/git",
        "--root", "/home/blaine/work",
        "--project", "/scratch/proto"],
      "type": "local"
    }
  }
}

Central store

--store <dir> re-roots every knowledge store under one central directory, keeping repos clean of store dirs:

// opencode.jsonc
{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp", "--root", "/path/to/org", "--store", "/path/to/knowledge"],
      "type": "local"
    }
  }
}

Layout:

<store>/
  <project>/knowledge/             # per-project store (qualified names nest:
                                   #   <root>/<project> -> <store>/<root>/<project>/knowledge)
  <org>/knowledge/                 # org store
  • In-tree knowledge/ dirs are ignored (startup warnings list them). Migrate by moving them: mkdir -p <store>/<address> && mv <project>/knowledge <store>/<address>/knowledge.
  • Only --global stays where it is; it merges into listings as usual.
  • init_knowledge initializes the central store for resolvable paths and errors for others (add them via --project/--root first).
  • The store directory itself must exist and is never created for you.
  • The store files are single-writer: their YAML reads/writes do not support concurrent access across server instances, so point only one server at a store for writing. Queries are safe from any instance — the search index is per-process in-memory and never shared.

Shared global store

--global <path> adds one knowledge store shared across every project. Querying or listing any project automatically merges the global store's entries alongside the project's own.

// opencode.jsonc
{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp",
        "--root", "/path/to/org",
        "--global", "/path/to/global-store"],
      "type": "local"
    }
  }
}
  • The global store is addressed as _global and is also queryable directly.
  • list_knowledge marks merged global sections with a (global) suffix so they are never mistaken for the project's own entries; projects with no entries of their own are explicitly reported as having none.
  • The global store itself is just a directory with knowledge/<category>.yaml files — it can live in its own git repo.

General notes:

  • Each --root discovers its immediate children as projects (one level deep — pass deeper directories as additional flags).
  • Duplicate project basenames across roots are addressed as <root>/<project> (e.g. work/api); list_projects shows which names need qualification.
  • query_knowledge accepts org root names to search that root's knowledge/ store. YAML category files are indexed as entries.
  • The search index is built in memory per server process at startup and does not survive a restart. There is no index on disk anywhere, no lock, and no contention — any number of instances may query concurrently.
  • The index notices out-of-band store edits (hand edits, git checkout, migration scripts) and rebuilds itself before serving the next query, so query_knowledge never silently disagrees with list_knowledge. Use reindex_knowledge to force a full rebuild.
  • --index <path> is deprecated and ignored (the search index is in-memory).
  • Old leftover .index/ directories and $XDG_STATE_HOME/knowledge-mcp/ artifacts from earlier releases are inert and can be deleted.

Startup Options

Both --no-index-on-startup and --index are deprecated no-ops. The server always builds its search index from the store files at startup (backgrounded; queries wait for it once). They remain accepted so existing configurations keep working without changes.

Debugging

knowledge-mcp debug runs a one-shot startup diagnosis against the same flags as server mode and exits non-zero when it finds a problem (unresolved project, blocked queries):

knowledge-mcp debug --root /path/to/org

The report has three sections — Resolution (projects/stores resolved), Startup trail (phase timings and a watchdog-bounded index self-query that flags a slow index kick), and Environment (version, doc count, install record) — followed by ok/warn/fail findings.

For live diagnostics, run the server with --debug (optionally --log-file <path> to tee). Lines go to stderr, which MCP clients such as opencode forward into their own logs. Tool calls are logged with sanitized arguments — entry bodies are replaced by sizes and never written. Set KNM_DEBUG=1 to get the same for the Grep/Glob hook-augment plugin hook.

MCP Tools

Tool Description
init_knowledge Create a knowledge/ store (YAML category files)
write_knowledge Add a knowledge entry to a category file
query_knowledge Full-text search with category filters
list_knowledge List all entries; entries with rules shown first as constraints
update_knowledge Update an entry by ID
list_projects List all discovered projects (org-wide mode only)
reindex_knowledge Rebuild the search index from the store files (queries also refresh automatically)

Queries are plain-text search with no operator syntax — special characters in queries are always treated as literal text.

Knowledge File Format

Entries are stored in <project>/knowledge/<category>.yaml:

  • conventions.yaml — patterns, naming, build commands
  • subsystems.yaml — how things work
  • decisions.yaml — why choices were made
  • workflows.yaml — procedures the agent runs on demand (brainstorm, plan, debug, verify)
  • _meta.yaml — project metadata

Category files use a project:/version:/entries: wrapper — a bare YAML list parses as zero entries. list_knowledge marks entries merged from a shared global store with a (global) suffix so they are never mistaken for the project's own entries.

The same layout is used at every scope: <global>/knowledge/, <org>/knowledge/, and <project>/knowledge/. .agents/ is reserved for agent-harness assets (skills, plugins, commands) and is never a store.

Org stores

Org roots use the same knowledge/ store and YAML entry schema as projects, so org-level facts carry ids, categories, and rule constraints. There is no separate org markdown format.

  • write_knowledge and update_knowledge require category and operate on the org's knowledge/<category>.yaml.
  • Writes are atomic (temp file + fsync + rename) and take the same per-file lock as any store. Queries see them through the index fingerprint.

Rules / Constraints

Entries can include an optional rule field — an imperative statement of what's forbidden or required (e.g. "Never create files outside ./tmp"). list_knowledge surfaces entries with rules in a separate ## constraints section above regular entries, so agents see hard rules immediately without needing to query detail.

project: my-project
version: 1
entries:
  - id: conv-001
    summary: Tmp directory rules and session workflow
    detail: "All project docs go in ./tmp/docs/..."
    rule: "NEVER create files outside ./tmp; all docs go in ./tmp/docs/ only"
    source: "user preference"
    date: "2026-09-08"

Agent Configuration

OpenCode

Add to opencode.jsonc:

{
  "mcp": {
    "knowledge-mcp": {
      "command": ["knowledge-mcp", "--root", "/path/to/org"],
      "type": "local"
    }
  }
}

Claude Code

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "knowledge-mcp": {
      "command": "knowledge-mcp",
      "args": ["--root", "/path/to/org"]
    }
  }
}

Token Savings

The store saves tokens on repeat lookups, not on first write. Typical wins:

Action Without the store With knowledge MCP
Session-start rule recall Re-read instruction files (~1-2K tokens/session) list_knowledge (~300-500 tokens, constraints first)
Look up one domain's conventions Grep + read the relevant docs (~2-5K tokens) query_knowledge with a targeted query (~500-900 tokens)
Recall how a subsystem works Re-read source files (~10-50K tokens) query_knowledge for a written subsystem entry (~500-1K tokens)

The savings only materialize if the content respects the format:

  • Detail is a summary (10-20 lines of query-able facts), not a copy of the source files it was distilled from. Copying sources into detail doubles the token cost and saves nothing.
  • No duplication with always-loaded instructions. Rules that also live in an auto-loaded AGENTS.md are read at session start anyway; the store earns its keep by holding the detail behind those rules, so agents query it only when they actually need the enforcement specifics.
  • Org-level stores are entries, not whole files. YAML entries return individually, so query_knowledge on an org root returns only the matching entries.

Anti-patterns that erase the savings:

  • Storing whole documents or source code in detail.
  • Mirroring the same rules in both AGENTS.md and the store intentlessly.
  • Running query_knowledge with no query against an org store (returns every entry).

License

MIT — Copyright (c) 2026 Blaine Motsinger. See LICENSE.

About

local mcp server for persistent agent knowledge

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages