MCP Server
The MemoryLayer MCP server (@scitrera/memorylayer-mcp-server) gives LLM agents memory tools to store, recall, synthesize, and manage information across sessions via the Model Context Protocol. It exposes 28 tools in the default cc profile and 40 in the full profile. It wraps the TypeScript SDK and talks to any MemoryLayer server over HTTP.
The same server is used by the Claude Code, Codex, and OpenCode integrations.
Installation
npm install @scitrera/memorylayer-mcp-serverRequires Node.js 18 or later. The package installs a memorylayer-mcp executable. You can also run it on demand with npx @scitrera/memorylayer-mcp-server.
Quick Start
# Set environment variablesexport MEMORYLAYER_URL=http://localhost:61001export MEMORYLAYER_WORKSPACE_ID=my-workspace
# Run the server (stdio transport)npx memorylayer-mcpConfiguration for Claude Code
Add .mcp.json to your project root:
{ "mcpServers": { "memorylayer": { "command": "npx", "args": ["@scitrera/memorylayer-mcp-server"], "env": { "MEMORYLAYER_URL": "http://localhost:61001" } } }}Auto-workspace detection: Claude Code starts MCP servers from the project directory, so the server uses your git repo name (or directory name) as the workspace ID. Each project gets its own memory automatically.
Or via CLI:
claude mcp add --transport stdio memorylayer \ --env MEMORYLAYER_URL=http://localhost:61001 \ -- npx @scitrera/memorylayer-mcp-serverFor hooks, slash commands, and pre-compaction transcript capture on top of the MCP tools, install the Claude Code plugin instead.
Configuration for Claude Desktop
Add to claude_desktop_config.json (~/Library/Application Support/Claude/ on macOS, %APPDATA%\Claude\ on Windows):
{ "mcpServers": { "memorylayer": { "command": "npx", "args": ["@scitrera/memorylayer-mcp-server"], "env": { "MEMORYLAYER_URL": "http://localhost:61001", "MEMORYLAYER_WORKSPACE_ID": "my-project" } } }}Claude Desktop doesn’t start the server in a per-project directory, so set MEMORYLAYER_WORKSPACE_ID explicitly. Otherwise every conversation lands in whichever workspace the launch directory happens to resolve to.
Configuration for Other MCP Clients
Any MCP client that can launch a stdio server works the same way. Clients that use the mcpServers JSON format, such as Cursor (.cursor/mcp.json in the project or ~/.cursor/mcp.json globally), take the same block as Claude Desktop. Set MEMORYLAYER_WORKSPACE_ID whenever the client doesn’t launch the server from your project directory.
Environment Variables
| Variable | Description | Default |
|---|---|---|
MEMORYLAYER_URL | Base URL for the MemoryLayer API | http://localhost:61001 |
MEMORYLAYER_API_KEY | API key for authentication | — |
MEMORYLAYER_WORKSPACE_ID | Workspace ID (overrides auto-detection) | auto-detected |
MEMORYLAYER_AUTO_WORKSPACE | Set to false to turn off auto-detection. If no workspace ID is set either, the server uses default | true |
MEMORYLAYER_TOOL_PROFILE | Tool profile: cc, full, or minimal. Unknown values fall back to cc | cc |
MEMORYLAYER_AUTO_START_SESSION | Set to false (or 0) to stop the server from starting a session automatically when it launches | true |
Tool Profiles
Three tool profiles control which tools the LLM sees. Set the profile with the MEMORYLAYER_TOOL_PROFILE environment variable.
| Profile | Tools | Intended use |
|---|---|---|
cc (default) | 28 | Coding agents: core memory, sessions and context packs, context sandbox, chat threads, read-only skills |
full | 40 | Everything: adds graph, audit/statistics, destructive chat tools, skills_save, and the MCP-server registry |
minimal | 2 | memory_remember and memory_recall only |
cc — Coding Agents (Default)
The recommended profile for Claude Code, Codex, and OpenCode. Provides 28 tools:
- Core memory:
memory_remember,memory_recall,memory_reflect,memory_forget - Utility:
memory_briefing - Sessions:
memory_session_start,memory_session_end,memory_session_commit,memory_session_status,memory_session_checkpoint - Context packs:
memory_context_pack,memory_context_delta - Context environment: all 8
memory_context_*sandbox tools - Chat history:
chat_thread_create,chat_thread_append,chat_thread_get,chat_thread_list - Skills (read):
skills_list,skills_get,skills_get_file,skills_search
To keep the tool list short, cc leaves out the advanced tools (memory_associate, memory_statistics, memory_graph_query, memory_audit), the destructive chat tools (chat_thread_decompose, chat_thread_delete), skills_save, and the mcp_servers_* registry tools.
full — All Tools
Enables all 40 tools. Use it for power-user work, debugging, or graph-based memory. On top of cc it adds:
memory_associate: graph buildingmemory_statistics: workspace analytics (placeholder that currently returns zero values)memory_graph_query: multi-hop graph traversalmemory_audit: contradiction detection (placeholder that currently performs no audit)chat_thread_decompose: memory extraction from threadschat_thread_delete: thread deletionskills_save: create or update skillsmcp_servers_list,mcp_servers_get,mcp_servers_save,mcp_servers_delete,mcp_servers_import: the MCP server registry
minimal — Essentials Only
Just 2 tools: memory_remember and memory_recall. Use it for testing or very constrained environments.
Complete Tool Reference
Core Memory Tools
memory_remember
Store a new memory for later recall. Use it for facts, preferences, decisions, or events worth remembering.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
content | string | Yes | — | The memory content to store |
type | string | No | — | Memory type: episodic (events), semantic (facts), procedural (how-to), working (current context) |
importance | number | No | 0.5 | Importance from 0 to 1. Higher values are kept longer and rank higher in recall |
tags | string[] | No | — | Tags for categorization (e.g., ["python", "bug-fix"]) |
subtype | string | No | — | Domain classification: solution, problem, code_pattern, fix, error, workflow, preference, decision, directive |
metadata | object | No | — | Arbitrary memory metadata |
relations | object[] | No | — | Explicit typed entity relations evidenced by this memory. Each item needs relationship. Optional fields: source_entity_id/source_entity_name, target_entity_id/target_entity_name, and confidence (0-1) |
{ "content": "User prefers TypeScript for new projects", "type": "semantic", "importance": 0.8, "tags": ["preference", "typescript"], "subtype": "preference"}memory_recall
Search memories by semantic query. Returns relevant memories ranked by relevance.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | — | Natural language query (e.g., “How do I fix authentication errors?”) |
types | string[] | No | — | Filter by memory types: episodic, semantic, procedural, working |
limit | integer | No | 10 | Max memories to return (1-100) |
min_relevance | number | No | server default | Min relevance score (0-1) |
tags | string[] | No | — | Filter by tags (AND logic) |
budget_tokens | integer | No | — | Hard cap on the estimated tokens of returned memory content |
include_confidence | boolean | No | true | Include deterministic retrieval-confidence metadata |
include_relations | boolean | No | true | Allow bounded typed-relation retrieval when the server enables it |
{ "query": "What are the user's coding preferences?", "limit": 10, "min_relevance": 0.5, "types": ["semantic"], "tags": ["preference"]}memory_reflect
Synthesize and summarize memories that match a query. Use it when you need insight across many memories rather than individual results.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | — | What to reflect on |
detail_level | string | No | server default | Level of detail: abstract (brief), overview (medium), full (detailed) |
include_sources | boolean | No | true | Include source memory IDs in response |
depth | integer | No | 2 | Association traversal depth, how many hops to follow (1-5) |
{ "query": "What patterns have we seen with database performance?", "detail_level": "overview", "include_sources": true, "depth": 2}memory_forget
Delete or decay a memory that is outdated or incorrect. Use it sparingly, because old memories are still useful history.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
memory_id | string | Yes | — | ID of memory to forget |
reason | string | No | — | Why this memory should be forgotten (for audit trail) |
hard | boolean | No | false | Hard delete (permanent) vs soft delete (recoverable) |
memory_associate
Link two memories with a typed relationship. The links build a knowledge graph for traversal and causal reasoning.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
source_id | string | Yes | — | Source memory ID |
target_id | string | Yes | — | Target memory ID |
relationship | string | Yes | — | Relationship type (e.g., causes, solves, similar_to, part_of, related_to). See Relationships for the full ontology. |
strength | number | No | 0.8 | Strength of association (0-1) |
{ "source_id": "mem_problem", "target_id": "mem_solution", "relationship": "solves", "strength": 0.9}memory_briefing
Get a session briefing that summarizes recent activity and context. It returns workspace stats and recent memory content at a configurable detail level. Use it at session start or after compaction to regain context.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
time_window_minutes | number | No | 60 | Time window in minutes for recent memories |
detail_level | string | No | abstract | Level of detail: abstract (summaries), overview (more detail), full (complete content) |
limit | number | No | 10 | Maximum number of recent memories to include (max: 50) |
include_memories | boolean | No | true | Whether to include recent memory content |
include_contradictions | boolean | No | true | Flag contradicting memories in briefing |
memory_statistics
Get memory statistics and analytics for the workspace. This is currently a placeholder that returns zero values.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
include_breakdown | boolean | No | true | Include breakdown by type/subtype |
memory_graph_query
Traverse the memory graph across multiple hops to find related memories. Use it to discover causal chains or knowledge paths.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
start_memory_id | string | Yes | — | Starting memory ID |
relationship_types | string[] | No | — | Filter by relationship types (e.g., ["causes", "triggers"]) |
max_depth | integer | No | 3 | Maximum traversal depth (1-5) |
direction | string | No | both | Traversal direction: outgoing, incoming, both |
max_paths | integer | No | 50 | Maximum paths to return |
{ "start_memory_id": "mem_abc123", "relationship_types": ["causes", "triggers"], "max_depth": 3, "direction": "both"}memory_audit
Audit memories for contradictions and inconsistencies. This is currently a placeholder that performs no audit.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
memory_id | string | No | — | Specific memory to audit (omit to audit entire workspace) |
auto_resolve | boolean | No | false | Automatically mark newer contradicting memories as preferred |
Session Management Tools
See Sessions & Working Memory for the underlying model.
memory_session_start
Start a new session for working memory. The server starts one automatically when it launches (unless MEMORYLAYER_AUTO_START_SESSION=false), and the Claude Code SessionStart hook starts one too, but you can also call it manually. After context compaction, call memory_context_inspect to see the sandbox state that is still on the server.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
metadata | object | No | — | Optional metadata to attach to the session |
memory_session_end
End the current session and optionally commit working memory to long-term storage.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
commit | boolean | No | true | Whether to commit working memory to long-term storage |
importance_threshold | number | No | 0.5 | Minimum importance for extracted memories (0-1) |
memory_session_commit
Commit working memory to long-term storage without ending the session. Use it for checkpoints during long sessions or before likely interruptions. The session stays active after the commit.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
importance_threshold | number | No | 0.5 | Minimum importance for extracted memories (0-1) |
clear_after_commit | boolean | No | false | Clear working memory after commit (session stays active) |
memory_session_status
Get the current session status, including a working memory summary. Use it to check whether a session is active. No parameters.
memory_session_checkpoint
Durably capture a raw transcript segment, typically right before compaction. The raw capture is stored first; derived indexing and enrichment never block it. The Claude Code and OpenCode plugins call this automatically before compaction.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
transcript_segment | string | Yes | — | Exact raw transcript segment to preserve |
content_hash | string | Yes | — | Lowercase SHA-256 hex digest of the UTF-8 segment |
idempotency_key | string | Yes | — | Stable key for safe retry |
source_kind | string | No | transcript | Label for the transcript source |
source_sequence | integer | No | — | Optional source sequence number (≥ 0) |
source_boundary | integer | No | — | Optional source offset/boundary (≥ 0) |
memory_context_pack
Build one deterministic, hard-budgeted payload for resuming a session. It covers directives, working memory, recent activity, contradictions, a sandbox summary, and checkpoint recovery. The response includes a signed cursor that you can pass to memory_context_delta.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
topic | string | No | — | Optional topic focus |
entity_ids | string[] | No | — | Focus on these entity IDs |
entity_names | string[] | No | — | Focus on these entity names |
budget_tokens | integer | No | 2048 | Hard token budget (min 32) |
section_limits | object | No | — | Per-section item caps |
include_directives | boolean | No | true | Include directives |
include_working_memory | boolean | No | true | Include working memory |
include_recent_activity | boolean | No | true | Include recent activity |
include_contradictions | boolean | No | true | Include contradictions |
include_sandbox_summary | boolean | No | true | Include a sandbox summary |
include_checkpoint_recovery | boolean | No | true | Include recovery from raw checkpoints |
memory_context_delta
Return the context changes and tombstones since a signed context-pack cursor, collapsed and kept within a hard token budget.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
cursor | string | Yes | — | Cursor from a context pack or a prior delta |
budget_tokens | integer | No | 2048 | Hard token budget (min 32) |
Context Environment Tools
These tools give the agent a persistent Python execution environment on the server. Sandbox state survives context compaction, so call memory_context_inspect after compaction to see what is still there. See Context Environment.
memory_context_exec
Run Python code in the server-side sandbox. Variables from earlier exec calls are still available. Use it to transform, analyze, and compute over loaded memories.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
code | string | Yes | — | Python code to execute. Variables from prior exec calls are available. |
result_var | string | No | — | Store the expression result in this variable name |
return_result | boolean | No | true | Return execution output to caller. Set false for large intermediate results. |
max_return_chars | integer | No | 10000 | Maximum characters to return. Output beyond this is truncated. |
memory_context_inspect
Inspect variables in the server-side sandbox. Omit the variable name for an overview of all variables, or name one for a detailed view. Call it after context compaction or when continuing a session to see the current sandbox state.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
variable | string | No | — | Inspect a specific variable. Omit for overview of all variables. |
preview_chars | integer | No | 200 | Characters to include in value previews |
memory_context_load
Load memories from the store into a sandbox variable with a semantic search. The loaded memories are then available to the exec, query, and RLM tools.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
var | string | Yes | — | Variable name to store loaded memories |
query | string | Yes | — | Semantic search query |
limit | integer | No | 50 | Maximum memories to load |
types | string[] | No | — | Filter by memory types |
tags | string[] | No | — | Filter by tags |
min_relevance | number | No | — | Minimum relevance score (0-1) |
include_embeddings | boolean | No | false | Include embedding vectors (large) |
memory_context_inject
Store a value in the server-side sandbox as a named variable. Use it to pass data from the client into the execution environment.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | Yes | — | Variable name in sandbox |
value | string | Yes | — | Value to store (string, JSON string, or code snippet) |
parse_json | boolean | No | false | Parse value as JSON before storing (creates dict/list, not string) |
memory_context_query
Ask the server-side LLM a question, with sandbox variables as context. The LLM reads the variable data and answers your prompt.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
prompt | string | Yes | — | Question or instruction for the server LLM |
variables | string[] | Yes | — | Variable names to include as context |
max_context_chars | integer | No | server default | Max chars of variable data to send to LLM |
result_var | string | No | — | Store LLM response in this variable |
memory_context_rlm
Run a Recursive Language Model (RLM) loop. The server LLM reasons over sandbox data and memories in repeated passes toward a goal, then returns a synthesis of its findings.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
goal | string | Yes | — | Natural language goal for the RLM loop |
memory_query | string | No | — | Semantic query to pre-load memories before the loop starts |
memory_limit | integer | No | 100 | Max memories to pre-load |
max_iterations | integer | No | 10 | Maximum RLM loop iterations (1-50) |
variables | string[] | No | — | Existing sandbox variables to include as context |
result_var | string | No | — | Store the final synthesis in this variable |
detail_level | string | No | standard | Detail level: brief, standard, detailed |
memory_context_status
Get the status of the server-side context environment: sandbox state, active variables, and resource usage. Use it after context compaction to check whether a sandbox environment still exists. No parameters.
memory_context_checkpoint
Checkpoint the sandbox state for persistence. This fires persistence hooks so that deployments with durable sandbox storage, such as MemoryLayer Enterprise, can save the state. It does nothing on default in-memory deployments. No parameters.
Chat History Tools
chat_thread_create
Create a new chat thread for storing conversation history. Threads keep their messages over time and can be automatically decomposed into memories.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
thread_id | string | No | auto-generated | Client-provided thread ID |
user_id | string | No | — | User who owns this conversation |
observer_id | string | No | — | Observer entity ID (typically the AI agent) |
subject_id | string | No | — | Subject entity ID (typically the human user) |
title | string | No | — | Optional display title |
metadata | object | No | — | Arbitrary metadata |
chat_thread_append
Append messages to a chat thread. Messages are stored persistently and are decomposed into memories once a threshold is reached.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
thread_id | string | Yes | — | Thread to append to |
messages | object[] | Yes | — | Messages to append. Each message has role (required: user/assistant/system/tool), content (required, string or structured blocks), and optional metadata. |
chat_thread_get
Get a chat thread with its messages. Returns the thread metadata and a page of messages.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
thread_id | string | Yes | — | Thread ID to retrieve |
limit | integer | No | 100 | Max messages to return |
offset | integer | No | 0 | Message pagination offset |
order | string | No | asc | Message order: asc or desc |
chat_thread_list
List chat threads in the workspace, optionally filtered by user.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
user_id | string | No | — | Filter by user ID |
limit | integer | No | 50 | Max threads to return |
offset | integer | No | 0 | Pagination offset |
chat_thread_decompose
Trigger memory decomposition for a thread’s unprocessed messages, extracting memories from the chat history.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
thread_id | string | Yes | — | Thread to decompose |
chat_thread_delete
Delete a chat thread and all its messages.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
thread_id | string | Yes | — | Thread to delete |
Skills Tools
Skills are reusable agent knowledge units (SKILL.md plus optional bundle files) stored in MemoryLayer. See Skills & MCP Servers.
skills_list
List available agent skills. Returns the name, description, version, and scope of each skill.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | No | — | Filter by exact skill name |
enabled | boolean | No | only enabled | Filter by enabled status |
include_shadowed | boolean | No | — | Include skills shadowed by a higher-scope skill with the same name |
limit | integer | No | 100 | Maximum skills to return (1-500) |
offset | integer | No | 0 | Pagination offset |
skills_get
Fetch the full SKILL.md for a skill: its frontmatter plus the instruction markdown. Provide either skill_id or name.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
skill_id | string | No | — | Skill ID (skl_...) |
name | string | No | — | Skill name, resolved by the server if skill_id is not provided |
skills_get_file
Fetch a single file (script, reference, or asset) from a skill’s bundle. Returns text content or base64-encoded binary.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
skill_id | string | Yes | — | Skill ID (skl_...) |
path | string | Yes | — | Relative path within the bundle (e.g. scripts/extract.py) |
skills_search
Search for skills by intent or description with vector recall.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | — | Natural language description of the capability you need |
limit | integer | No | 10 | Maximum candidate skills to return (1-50) |
skills_save
Create or update a skill. Every agent that shares the workspace can then use it.
Profile: full only
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | Skill name (1-64 chars, lowercase letters/digits/hyphens) |
description | string | Yes | — | Skill description (1-1024 chars) |
body | string | No | — | SKILL.md body markdown |
version | string | No | 0.1.0 | Skill version |
license | string | No | — | License identifier (e.g. MIT) |
compatibility | string | No | — | Compatibility notes (max 500 chars) |
allowed_tools | string | No | — | Space-separated tool allowlist (experimental) |
source_mode | string | No | server | Where canonical storage lives: server, filesystem, mirrored |
metadata | object | No | — | Arbitrary metadata |
files | object[] | No | — | Optional bundle files (scripts, references, assets) |
MCP Server Registry Tools
Store and share MCP server definitions in MemoryLayer. All five tools are available in the full profile only.
| Tool | Required parameters | Description |
|---|---|---|
mcp_servers_list | — | List registered MCP servers. Optional filters: transport (stdio, http, sse, streamable-http), enabled, name, limit (default 100), offset |
mcp_servers_get | server_id or name | Fetch a single server record |
mcp_servers_save | name, transport | Create or update a server by name. Optional: command, args, env, url, headers, description, enabled (default true), metadata. env and headers values are stored as secrets |
mcp_servers_delete | server_id | Delete a server record |
mcp_servers_import | mcpServers | Bulk import from an mcpServers object (the .mcp.json / claude_desktop_config.json format). Returns imported, updated, and error counts |
Workspace Detection
The server picks your workspace in this order:
MEMORYLAYER_WORKSPACE_IDenvironment variable (explicit override)- Git remote origin: the repo name from the remote URL
- Git root directory: the name of the root folder
- Current directory: the name of the current working directory
Steps 2-4 run only while MEMORYLAYER_AUTO_WORKSPACE is not false.
Programmatic Usage
import { MemoryLayerClient, createServer } from "@scitrera/memorylayer-mcp-server";
const client = new MemoryLayerClient({ baseUrl: "http://localhost:61001", workspaceId: "my-workspace", apiKey: "optional-api-key",});
const server = await createServer(client, { toolProfile: "full" });await server.run();MEMORYLAYER_TOOL_PROFILE, when set, overrides the toolProfile option.