Skip to content

feat(mcp): add hermes-memory MCP server for bidirectional memory access#10833

Closed
easyvibecoding wants to merge 4 commits into
NousResearch:mainfrom
easyvibecoding:feat/hermes-memory-mcp-clean
Closed

feat(mcp): add hermes-memory MCP server for bidirectional memory access#10833
easyvibecoding wants to merge 4 commits into
NousResearch:mainfrom
easyvibecoding:feat/hermes-memory-mcp-clean

Conversation

@easyvibecoding

Copy link
Copy Markdown

Summary

  • Add a lightweight FastMCP stdio server (mcp-servers/hermes-memory-mcp.py) that exposes Hermes memory stores (MEMORY.md, USER.md) and session history (state.db) to any MCP-compatible client
  • Enables Claude Code, Cursor, VS Code, and other MCP clients to read and write Hermes memory directly — bridging the gap that hermes mcp serve doesn't cover (conversation browsing only, no memory access)
  • Aligned with Hermes internals: atomic writes (os.replace + fsync), file locking (fcntl.flock), prompt-injection scanning, §-delimited sections, char limits

Motivation

hermes mcp serve exposes 10 conversation/messaging tools but zero memory tools. Users running Hermes alongside Claude Code (or other MCP clients) have no way to share persistent memory between agents. This server fills that gap with 7 tools covering memory CRUD + session browsing for dream-consolidation workflows.

Tools (7)

Memory

Tool Description
read_memory(store) Read MEMORY.md, USER.md, or both
add_memory_entry(store, entry, old_text) Append or substring-replace in a memory store
remove_memory_entry(store, old_text) Remove a section or substring cleanly
memory_status() Char usage, section count, state.db session count

Session (Dream Workflow)

Tool Description
recent_sessions(limit, source) List recent sessions for review
session_read(session_id, last_n) Read full transcript of a session
session_search(query, limit, source) FTS5 full-text search across all sessions

Safety (aligned with tools/memory_tool.py)

  • Atomic writes — temp file + os.replace() + fsync, no corruption on crash
  • File lockingfcntl.flock() prevents race conditions with concurrent Hermes writes
  • Prompt-injection scanning — blocks role hijacking, instruction override, chat-template tokens, invisible Unicode
  • Read-only state.db — all session queries use ?mode=ro

Dream Workflow

Inspired by Honcho's on_session_end and Holographic's auto-extraction:

  1. recent_sessions() → review what happened
  2. session_read(id) → read the transcript
  3. LLM extracts key insights
  4. add_memory_entry() / remove_memory_entry() → consolidate
  5. memory_status() → verify capacity

Automatable via Claude Code hooks, cron, or manual commands.

Files

mcp-servers/
├── hermes-memory-mcp.py      # FastMCP server (7 tools, ~440 lines)
└── hermes-memory-runner.sh    # Shell wrapper for `uv run`
skills/mcp/hermes-memory-bridge/
└── SKILL.md                   # Setup guide (Hermes + Claude Code dual registration)
tests/
└── test_hermes_memory_mcp.py  # 43 tests, all passing

Test Plan

43 pytest tests covering all tools and safety features:

  • Security scanning: injection, chat templates, invisible Unicode, role hijack (5 tests)
  • Memory CRUD: read/add/replace/remove, char limits, store validation (16 tests)
  • Session tools: FTS5 search, transcript read, recent list, edge cases (15 tests)
  • Safety primitives: atomic write, file locking (4 tests)
  • Edge cases: empty stores, nonexistent sessions, overflow, truncation (3 tests)
  • Uses tmp_path isolation with real SQLite — no mocks, matching repo test patterns
43 passed in 0.70s

easyvibecoding and others added 4 commits April 16, 2026 14:40
Expose Hermes memory stores (MEMORY.md, USER.md) and session history
(state.db FTS5 search) to any MCP client via a lightweight FastMCP
stdio server. This enables Claude Code, Cursor, and other MCP-compatible
tools to read/write Hermes memory directly.

Tools: read_memory, add_memory_entry, memory_status, session_search

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…mory

- Atomic writes (tempfile + os.replace + fsync) aligned with Hermes MemoryStore
- File locking (fcntl.flock) to prevent race conditions with concurrent Hermes writes
- Prompt-injection scanning (role hijacking, invisible Unicode) matching memory_tool.py
- New remove_memory_entry tool for pruning stale memory sections
- New session_read tool to read full session transcripts
- New recent_sessions tool to list sessions for dream consolidation
- memory_status now includes state.db session count
- SKILL.md v2.0.0 with dream workflow documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Covers all 7 tools and safety features:
- Security scanning (injection, chat templates, invisible Unicode, role hijack)
- read_memory (empty, content, user-only, invalid store)
- add_memory_entry (add, append, replace, char limit, injection block)
- remove_memory_entry (section, not found, last section)
- memory_status (empty, with content, with state.db)
- session_search (FTS5 match, no match, source filter, limit)
- session_read (transcript, nonexistent, limit, truncation)
- recent_sessions (list, filter, limit, empty db)
- Atomic write and file locking primitives

Uses tmp_path isolation with real SQLite (no mocks), matching repo test patterns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace Unix-only fcntl.flock with platform-aware locking:
- Unix: fcntl.flock (unchanged)
- Windows: msvcrt.locking
- Fallback: no locking if neither available

Per CONTRIBUTING.md cross-platform compatibility guidelines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant