Skip to content

memory: write side has no size caps, and every mutation rewrites the whole graph file — measured linear cost (hardening note) #5525

Closed

Description

@reservoir-cmyk

Which server?

memory (@modelcontextprotocol/server-memory)

Protocol era

Modern (2026-07-28)

MCP client

No response

The problem

Summary
This is a scalability/hardening observation, not a security report and not a bug claim. In the memory server (src/memory/index.ts, checked at monorepo commit 6cfff62):

  • There is no cap on the write side: no length limit on entity/relation/observation strings, and no count limit on the per-call input arrays or on the total graph. The only .max( in the file is the 2048-character cap on the search query string (index.ts:905, 909); the schemas at index.ts:889-903 carry no limits.
  • Every mutation loads and validates the entire file and writes the entire graph back (temp file + rename), under the cross-process file lock: load at index.ts:442, save at index.ts:532, 610, locking at index.ts:419.
    The read side already gained opt-in limits (Add lightweight read modes #3953: observationLimit, limit, …), so the write side is the remaining uncapped direction.

Measured cost (real KnowledgeGraphManager, synthetic dummy graph)
Median of 3 runs, single process, one minimal mutation ("add one entity") per measurement; synthetic entities ≈240 bytes/line with 3 observations each:
| Entities | File size | Time to add 1 entity |
| 1,000 | 0.23 MB | 7 ms |
| 5,000 | 1.18 MB | 25 ms |
| 20,000 | 4.78 MB | 93 ms |
| 50,000 | 12.0 MB | 223 ms |
| 100,000 | 24.1 MB | 411 ms |
The cost is linear at ≈4.1 µs/entity, and the write volume is the whole file every time: at 100,000 entities, adding a single ~300-byte entity rewrote 24.06 MB. (Measurement harness and raw numbers are preserved on the reporter's side and can be shared verbatim.)

What this note does not claim
No availability or timeout claim is made. At the measured rate, a single mutation costs well under a second even at 100,000 entities; nothing here demonstrates a client being starved or a write timing out. The point is only the combination of (a) no operator-set ceiling on how large the store can grow through the write tools, and (b) a per-mutation cost and lock-holding time that grow linearly with that unbounded size, in the shared-file multi-client configuration the README supports.

Reporter: Tomoki Murota, CISSP

Solution you have in mind (optional)

Consider parity with the read side: opt-in caps for write payloads and/or total graph size (entities, relations, observation bytes), and/or a short README note documenting the linear per-mutation cost so operators sharing one file can size it deliberately.

Which MCP feature does it demonstrate? (optional)

No response

Alternatives or workarounds you have tried

No response

Already built it locally?

Not built. No diff is attached, per this repository's contribution model. The measurement harness and raw numbers are preserved on the reporter's side and can be shared verbatim.

Before you submit

  • I searched existing issues and this is not a duplicate.
  • This is a request for this repository or one of its servers, not a new server, the MCP specification or an SDK.

Activity

  1. added
    server-memoryReference implementation for the Memory MCP server - src/memory
    on Nov 12, 2026
  2. cliffhall commented on Nov 12, 2026

    @cliffhall
    Member

    Triage: Priority Low (total 3)

    • Severity 2: no functional failure; per-mutation cost grows linearly with graph size but stays sub-second at 100,000 entities, as the report itself measures. The gap is the absence of an operator-set ceiling on the write side
    • Urgency 1: no time pressure, nothing waits on it
    • Bonuses: none

    Related history: #4117 (persistence hardening) and #3537 (string constraints across servers, closed not planned). Added server-memory.

    Board: Servers V2 (#43), Status Incoming, awaiting maintainer review (no milestone yet).

  3. added this to the v2.5.0 milestone on Nov 12, 2026
  4. self-assigned this
    on Nov 12, 2026
  5. cliffhall commented on Nov 12, 2026

    @cliffhall
    Member

    Shipped in #5534.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestserver-memoryReference implementation for the Memory MCP server - src/memoryv2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions