You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e1d154e
Browse filesBrowse the repository at this point in the historyBrowse files
Add opt-in write limits: `MEMORY_MAX_ENTITIES`, `MEMORY_MAX_RELATIONS` and `MEMORY_MAX_FILE_BYTES` cap how large the write tools may grow the graph, and the README now documents that every write rewrites the whole memory file.
Copy file name to clipboardExpand all lines: src/memory/README.md
+52-34Lines changed: 52 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,15 @@ Published on npm as [`@modelcontextprotocol/server-memory`](https://www.npmjs.co
7
7
## Core Concepts
8
8
9
9
### Entities
10
+
10
11
Entities are the primary nodes in the knowledge graph. Each entity has:
12
+
11
13
- A unique name (identifier)
12
14
- An entity type (e.g., "person", "organization", "event")
13
15
- A list of observations
14
16
15
17
Example:
18
+
16
19
```json
17
20
{
18
21
"name": "John_Smith",
@@ -22,17 +25,21 @@ Example:
22
25
```
23
26
24
27
### Relations
28
+
25
29
Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other.
26
30
27
31
Example:
32
+
28
33
```json
29
34
{
30
35
"from": "John_Smith",
31
36
"to": "Anthropic",
32
37
"relationType": "works_at"
33
38
}
34
39
```
40
+
35
41
### Observations
42
+
36
43
Observations are discrete pieces of information about an entity. They are:
37
44
38
45
- Stored as strings
@@ -41,6 +48,7 @@ Observations are discrete pieces of information about an entity. They are:
41
48
- Should be atomic (one fact per observation)
42
49
43
50
Example:
51
+
44
52
```json
45
53
{
46
54
"entityName": "John_Smith",
@@ -55,6 +63,7 @@ Example:
55
63
## API
56
64
57
65
### Tools
66
+
58
67
-**create_entities**
59
68
- Create multiple new entities in the knowledge graph
60
69
- Input: `entities` (array of objects)
@@ -195,22 +204,27 @@ Add this to your claude_desktop_config.json:
-`MEMORY_FILE_PATH`: Path to the memory storage JSONL file (default: `memory.jsonl` in the server directory). A leading `~` expands to your home directory; a relative path resolves against the server directory. Set it to an absolute path you own; see [Choosing where the graph is stored](#choosing-where-the-graph-is-stored).
281
+
-`MEMORY_MAX_ENTITIES`: The most entities the graph may hold. Unset by default (no limit).
282
+
-`MEMORY_MAX_RELATIONS`: The most relations the graph may hold. Unset by default (no limit).
283
+
-`MEMORY_MAX_FILE_BYTES`: The most bytes the memory file may hold. Unset by default (no limit).
284
+
285
+
The three limits are opt-in, and each is described under [Limiting how large the graph grows](#limiting-how-large-the-graph-grows). A variable that is set must hold a positive whole number; any other value, an empty one included, stops the server at startup with an error naming the variable.
280
286
281
287
When `MEMORY_FILE_PATH` is not set and the server directory still holds a legacy `memory.json` but no `memory.jsonl`, the server renames `memory.json` to `memory.jsonl` at startup. If that rename fails, the server exits with an error naming both paths and the cause, rather than starting on an empty graph; fix the cause (a permission problem, say) and restart, or set `MEMORY_FILE_PATH` to choose a file explicitly.
282
288
@@ -299,6 +305,17 @@ Each MCP client starts its own server process, so two clients using the same `ME
299
305
- A write that cannot get the lock within 60 seconds fails with a tool error rather than overwriting the file.
300
306
- The lock relies on exclusive file creation, which local filesystems provide; a network filesystem that does not honour it cannot be shared safely this way.
301
307
308
+
#### Limiting how large the graph grows
309
+
310
+
Every write tool reads the whole memory file, changes the graph and writes the whole file back, holding the lock throughout. Its cost, and how long other servers sharing the file wait for the lock, therefore grow linearly with the file, however small the change: adding one entity to a graph of 100,000 entities rewrites the whole file, about 24 MB at around 240 bytes per entity, in roughly 0.4 seconds on a laptop (#5525). The read tools load the whole file too. Size a shared file with that in mind.
311
+
312
+
By default nothing caps the graph. Set `MEMORY_MAX_ENTITIES`, `MEMORY_MAX_RELATIONS` or `MEMORY_MAX_FILE_BYTES` to put a ceiling on it:
313
+
314
+
-`create_entities`, `create_relations` and `add_observations` refuse a call that would leave the graph over a limit, with a tool error naming the variable. The whole call is refused and nothing is saved, not just the part past the limit.
315
+
- A call that adds nothing new (every entity or relation already exists, say) is still answered, even when the graph is at or over a limit.
316
+
- The delete tools are never refused, so a graph over a limit (one that grew before the limit was set, or lowered) can always be shrunk. While it is over, calls that would grow it further on that dimension are refused.
317
+
-`MEMORY_MAX_FILE_BYTES` counts the bytes of the file as it would be saved, unreadable lines included, so it bounds the cost of each write directly. The counts are easier to reason about but do not bound how long each entity's observations grow.
318
+
302
319
# VS Code Installation Instructions
303
320
304
321
For quick installation, use one of the one-click installation buttons below:
@@ -324,10 +341,7 @@ Alternatively, you can add the configuration to a file called `.vscode/mcp.json`
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.
377
386
378
-
Here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a [Claude.ai Project](https://www.anthropic.com/news/projects).
387
+
Here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a [Claude.ai Project](https://www.anthropic.com/news/projects).
379
388
380
389
```
381
390
Follow these steps for each interaction:
@@ -408,7 +417,7 @@ Follow these steps for each interaction:
0 commit comments