Knowledge Graph Memory Server
Enhanced fork of @modelcontextprotocol/server-memory
A full-featured persistent memory system using a local knowledge graph. This lets Claude remember information about the user across chats, with advanced search, graph traversal, and filtering capabilities.
What's New vs. @modelcontextprotocol/server-memory
Feature | server-memory | better-memory-mcp |
Advanced Search | Basic substring matching | Boolean operators ( |
Graph Traversal | Not available |
|
Filtering | Not available | Filter by entity type, relation type, observation patterns (dated, techdebt, deprecated) |
Observation Search | Search returns full entities |
|
Desktop Extension | Manual config only | One-click |
Core Concepts
Entities
Entities are the primary nodes in the knowledge graph. Each entity has:
A unique name (identifier)
An entity type (e.g., "person", "organization", "event")
A list of observations
Example:
Relations
Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other.
Example:
Observations
Observations are discrete pieces of information about an entity. They are:
Stored as strings
Attached to specific entities
Can be added or removed independently
Should be atomic (one fact per observation)
Example:
API
Tools
CRUD Operations
create_entities
Create multiple new entities in the knowledge graph
Input:
entities(array of objects)Each object contains:
name(string): Entity identifierentityType(string): Type classificationobservations(string[]): Associated observations
Ignores entities with existing names
create_relations
Create multiple new relations between entities
Input:
relations(array of objects)Each object contains:
from(string): Source entity nameto(string): Target entity namerelationType(string): Relationship type in active voice
Skips duplicate relations
add_observations
Add new observations to existing entities
Input:
observations(array of objects)Each object contains:
entityName(string): Target entitycontents(string[]): New observations to add
Returns added observations per entity
Fails if entity doesn't exist
delete_entities
Remove entities and their relations
Input:
entityNames(string[])Cascading deletion of associated relations
Silent operation if entity doesn't exist
delete_observations
Remove specific observations from entities
Input:
deletions(array of objects)Each object contains:
entityName(string): Target entityobservations(string[]): Observations to remove
Silent operation if observation doesn't exist
delete_relations
Remove specific relations from the graph
Input:
relations(array of objects)Each object contains:
from(string): Source entity nameto(string): Target entity namerelationType(string): Relationship type
Silent operation if relation doesn't exist
read_graph
Read the entire knowledge graph
No input required
Returns complete graph structure with all entities and relations
Search & Retrieval
search_nodes (Enhanced)
Advanced search with boolean operators, field prefixes, fuzzy matching, and relevance scoring
Input:
query(string): Search query with advanced syntax supportincludeNeighbors(boolean, optional): Include 1-hop connected entitiesfuzzy(boolean, optional): Enable fuzzy matching for typo tolerancelimit(number, optional): Maximum results to return
Query Syntax:
Multiple words: OR logic (matches any word)
+term: Required (must be present)-term: Excluded (must NOT be present)"phrase": Exact phrase matchname:value: Search only entity namestype:value: Search only entity typesobs:value: Search only observations
Examples:
"auth module"- finds entities matching "auth" OR "module""+auth +security"- finds entities matching BOTH"auth -deprecated"- finds "auth" but excludes "deprecated""name:AuthService type:Module"- field-specific search
Returns matching entities, relations (where at least one endpoint matches), and relevance scores
open_nodes
Retrieve specific nodes by name
Input:
names(string[])Returns:
Requested entities
Relations between requested entities
Silently skips non-existent nodes
search_observations (New)
Search at the observation level, returning individual matching observations instead of entire entities
More efficient than
search_nodeswhen you need specific facts rather than full entity dataReduces token usage by returning only relevant observations
Input:
query(string): Search query (same syntax as search_nodes)limit(number, optional): Maximum observations to return (default: 10)includeEntity(boolean, optional): Include full parent entities in responsefuzzy(boolean, optional): Enable fuzzy matching for typo tolerance
Returns:
matches: Array of matching observations with:entityName: Parent entity nameentityType: Parent entity typeobservation: The matching observation textscore: Relevance score
entities(optional): Full parent entities ifincludeEntityis true
Example query:
"+interview +German"returns only observations containing both terms
Graph Traversal Tools
get_neighbors
Get all entities directly connected to a given entity
Input:
entityName(string): The entity to find neighbors fordirection(optional):'incoming','outgoing', or'both'(default)relationType(optional): Filter by specific relation type
Returns array of neighbors with entity, relation, and direction
find_path
Find shortest path between two entities using BFS
Input:
fromEntity(string): Starting entitytoEntity(string): Target entitymaxDepth(number, optional): Maximum path length (default: 10)
Returns path (entities), relations, and length; or null if no path exists
get_subgraph
Extract N-hop neighborhood around seed entities
Input:
entityNames(string[]): Seed entitiesdepth(number, optional): Hops to expand (default: 1)
Returns subgraph with entities and relations within the neighborhood
Filtering Tools
filter_by_type
Get all entities of a specific type
Input:
entityType(string, case-insensitive)Returns entities of that type and relations between them
filter_relations
Filter relations by type, source, or target
Input (all optional):
relationType: Filter by relation typefromEntity: Filter by source entitytoEntity: Filter by target entity
Returns matching relations and connected entities
filter_observations
Find entities with observations matching patterns
Input:
pattern(string)Preset patterns:
"dated"- Observations starting with[YYYY-MM-DD]"techdebt"- Contains TODO, FIXME, HACK, or "tech debt""deprecated"- Mentions deprecated"purpose"- Contains "Purpose:""quirk"- Contains "Quirk:"
Or provide a custom regex pattern
Installation
Option 1: Desktop Extension (Recommended)
Install directly in Claude Desktop using the bundled extension:
Download the latest
.mcpbfile from ReleasesOpen Claude Desktop
Go to Settings → Extensions
Click Install from file and select the
.mcpbfileConfigure the memory file path when prompted (optional)
Option 2: Manual Installation
Prerequisites
Clone this repository
Install dependencies and build:
npm install npm run build
Configuration
The server can be configured using the following environment variable:
MEMORY_FILE_PATH: Path to the memory storage JSONL file (default:memory.jsonlin the server directory)
Claude Desktop (Manual Config)
Add this to your claude_desktop_config.json:
Replace C:/path/to/better-memory-mcp with the actual path to this repository.
VS Code
Add the configuration to your MCP settings using one of these methods:
Method 1: User Configuration (Recommended)
Open the Command Palette (Ctrl + Shift + P) and run MCP: Open User Configuration. Add the server configuration to your mcp.json file.
Method 2: Workspace Configuration
Add the configuration to .vscode/mcp.json in your workspace.
For more details about MCP configuration in VS Code, see the official VS Code MCP documentation.
System Prompt
The prompt for utilizing memory depends on the use case. Changing the prompt will help the model determine the frequency and types of memories created.
Here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a Claude.ai Project.
Codebase Knowledge Graph Prompts
The example_prompts/ directory contains ready-to-use system prompts for building knowledge graphs of codebases:
Prompt | Purpose |
Integration protocol for maintaining a codebase memory graph during development sessions | |
Complete 7-phase agent prompt for building knowledge graphs from scratch |
These prompts help Claude:
Build persistent memory of codebase structure, patterns, and decisions
Maintain dated observations with
[YYYY-MM-DD]formatTrack relationships between modules, services, and components
Document non-obvious quirks, tech debt, and architectural decisions
Tip: Turn codebase_graph_agent_prompt.md into a Claude Code custom slash command or subagent to automate codebase graph maintenance as part of your development workflow.
Development
Build
Watch mode
Run tests
Build Desktop Extension
To build the .mcpb extension bundle:
This creates a better-memory-mcp.mcpb file that can be installed directly in Claude Desktop.
License
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.