Skip to content

fix(memory): reject dangling relations#4477

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/memory-relation-entity-validation
Open

fix(memory): reject dangling relations#4477
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/memory-relation-entity-validation

Conversation

@jstar0

@jstar0 jstar0 commented Jul 5, 2026

Copy link
Copy Markdown

Summary

Fixes #4457.

The memory server now rejects create_relations requests when either endpoint does not name an existing entity. This prevents the knowledge graph from persisting dangling relations that point at nodes that were never created.

Changes

createRelations previously filtered only duplicate relations before appending new entries to the graph. That allowed a fresh graph to store relations such as Ghost_A -> Ghost_B while entities remained empty.

This change validates every incoming relation endpoint against the current entity set before saving. If a batch contains an invalid endpoint, the call fails before writing any of the batch, matching the fail-fast behavior already used by add_observations for unknown entities.

The memory README now documents that create_relations fails when the source or target entity does not exist.

Risk / Scope

The change is limited to the memory reference server. Existing valid relations and duplicate-relation skipping behavior are unchanged.

The only behavior change is that create_relations now fails instead of silently storing a relation whose from or to endpoint is missing.

Verification

npm test --workspace @modelcontextprotocol/server-memory -- __tests__/knowledge-graph.test.ts
npm test --workspace @modelcontextprotocol/server-memory
npm run build --workspace @modelcontextprotocol/server-memory
npm run build --workspaces
npm test --workspaces

Signed-off-by: King Star <mcxin.y@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: create_relations accepts relations to non-existent entities (dangling relations, silent graph corruption)

1 participant