Skip to content

MCP server stdio transport: add_drawer and kg_add write to WAL but not to ChromaDB/SQLite #538

@duha887b

Description

@duha887b

Environment

  • OS: Windows 11 (bash shell via Claude Code)
  • Python: 3.12 (via uvx)
  • MemPalace: 3.1.0
  • ChromaDB: 0.6.3
  • Claude Code: 2.1.100
  • MCP transport: stdio

Bug

When calling mempalace_add_drawer or mempalace_kg_add via the MCP server (stdio transport), operations are logged in the WAL (~/.mempalace/wal/write_log.jsonl) with "result": null, but no data is written to ChromaDB or the Knowledge Graph SQLite.

Calling the same functions directly from Python works correctly:

from mempalace.mcp_server import tool_add_drawer, tool_kg_add

# This works — drawer is written and searchable
result = tool_add_drawer('myproject', 'general', 'test content')
# {'success': True, 'drawer_id': '...'}

# This works — triple is written
result = tool_kg_add('User', 'prefers', 'dark mode', '2026-04-10')
# {'success': True, 'triple_id': '...'}

But via MCP stdio (Claude Code session), the WAL shows:

{"timestamp": "...", "operation": "kg_add", "params": {"subject": "peter", "predicate": "preferred_temperature", "object": "21 Grad Celsius"}, "result": null}
{"timestamp": "...", "operation": "add_drawer", "params": {"drawer_id": "...", "wing": "personalai", "room": "kira", "content_length": 417}, "result": null}

After the session:

  • mempalace status shows unchanged drawer counts
  • mempalace search does not find MCP-added content
  • Knowledge Graph SQLite has 0 entities, 0 triples
  • Direct Python calls to the same functions DO write successfully

Steps to Reproduce

  1. Install mempalace plugin: claude plugin install --scope user mempalace
  2. Mine a project: mempalace mine /path/to/project
  3. Start Claude Code session, ask Claude to save a fact (triggers mempalace_kg_add)
  4. Check WAL: cat ~/.mempalace/wal/write_log.jsonl — shows "result": null
  5. Check KG: mempalace search — fact not found
  6. Direct Python test (same function, same palace path) — works

Suspected Cause

The MCP server runs as a stdio subprocess. Possible issues:

  • ChromaDB connection not being committed/flushed in the stdio event loop
  • SQLite WAL mode not syncing before process exit
  • _get_collection() creates a new client per call that doesn't persist
  • Async/sync mismatch in the FastMCP stdio transport

Workaround

WAL entries can be replayed via direct Python calls:

import json
from mempalace.mcp_server import tool_add_drawer, tool_kg_add

with open('~/.mempalace/wal/write_log.jsonl') as f:
    for line in f:
        entry = json.loads(line)
        if entry['result'] is None:
            if entry['operation'] == 'add_drawer':
                p = entry['params']
                tool_add_drawer(p['wing'], p['room'], p.get('content_preview',''), p.get('source_file'), p.get('added_by'))
            elif entry['operation'] == 'kg_add':
                p = entry['params']
                tool_kg_add(p['subject'], p['predicate'], p['object'], p.get('valid_from'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mcpMCP server and toolsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions