MCP integration
August 31, 2026 ยท View on GitHub
LongMemory exposes one high-level Model Context Protocol server over the same
createMemory engine used by the package, CLI, REST API, projects, and
connectors. It supports local stdio and remote Streamable HTTP transports.
Local stdio
longmemory mcp --db .longmemory/project.db --project current
An MCP client can launch the same command directly:
{
"mcpServers": {
"longmemory": {
"command": "longmemory",
"args": ["mcp", "--db", ".longmemory/project.db", "--project", "current"]
}
}
}
The stdio command writes only MCP protocol messages to stdout. Use
--read-only to open an existing SQLite database without migrations or writes.
Use --audit <path> to override the default
<database>.mcp-audit.jsonl path.
Streamable HTTP
longmemory serve --db ./longmemory.db --mcp-http
The endpoint is http://127.0.0.1:7331/mcp. REST and MCP share one in-process
memory engine. When LONGMEMORY_API_KEY is set, MCP requires the same bearer
token or X-API-Key as /v1/*. LONGMEMORY_MCP_HTTP=true also enables it for
pnpm serve.
Tools
The deny-by-default allowlist contains exactly thirteen high-level tools:
longmemory_project_contextlongmemory_recalllongmemory_ingestlongmemory_remember_decisionlongmemory_update_task_statelongmemory_explainlongmemory_report_conflictslongmemory_sync_connectorlongmemory_match_skillslongmemory_manage_skilllongmemory_code_graphlongmemory_asset_cataloglongmemory_manage_asset
Recall delegates to Hydrograph modes and their temporal, contract,
contradiction, grounding, confidence, world, and permission gates. Connector
sync defaults to dry_run: true. Read-only mode rejects write-capable tools.
Skill matching can filter an agent loadout; Skill management creates immutable
versions, bindings, or archive versions. CodeGraph is read-only and provides
symbol search, callers, callees, and reverse impact paths from persisted source
snapshots.
Asset catalog calls discover governed Chat Memory, Skill, LLM-Wiki, and
CodeGraph records or assemble a target-specific loadout. Asset management is a
write tool, requires owner or explicit manage ACL, and is blocked by MCP
read-only mode. Runtime configuration fixes user/team/role/agent/framework
identity; tool arguments cannot impersonate another configured agent.
Resources
longmemory://projectslongmemory://project/{project_id}/summarylongmemory://project/{project_id}/current-contextlongmemory://project/{project_id}/decisionslongmemory://project/{project_id}/taskslongmemory://project/{project_id}/skillslongmemory://project/{project_id}/assetslongmemory://project/{project_id}/asset/{asset_id}longmemory://project/{project_id}/agent/{agent_id}/manifestlongmemory://project/{project_id}/conflictslongmemory://entity/{entity_id}longmemory://world/{world_id}longmemory://memory/{node_id}
Direct memory, entity, and world reads enforce configured user and project scope. Denied candidates are removed from MCP diagnostic traces as well as result items.
Prompts
longmemory_before_codinglongmemory_after_codinglongmemory_debug_sessionlongmemory_project_handofflongmemory_architecture_context
Prompts never interpolate connector content as instructions. Retrieved memory
must remain delimited as untrusted <longmemory-data> evidence.
Programmatic server
import { create_longmemory_mcp } from "longmemory";
const { server, runtime } = create_longmemory_mcp({
db_path: "./longmemory.db",
project_id: "longmemory",
user_id: "agent:local",
read_only: true,
});
allowed_tools can reduce the advertised tools. Unknown names are rejected at
startup, and omitted tools are not registered.