Skip to content

fix(memory): report relations create_relations skipped - #5708

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/5654-memory-create-relations-skipped
Nov 30, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/5654-memory-create-relations-skipped

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5654

Description

create_relations returned a bare [] for a relation that already exists, so an agent could not tell "already there" from "nothing happened". It now mirrors create_entities' skip report (#4887):

  • structuredContent carries a new optional skipped array of the requested relations that were not added, present only when at least one was skipped.
  • A second text item names them, e.g. Skipped 1 relation that already exists: A -[knows]-> B. It is already in the graph, so nothing was added for it.
  • Within-request repeats are treated as create_entities treats them: the first occurrence is created, the repeat is reported as skipped.
  • The tool description and the README say so.

The skip list is computed by identity against what createRelations returned (skippedRelations), exactly as skippedEntityNames does for entities. KnowledgeGraphManager.createRelations itself is unchanged.

Server Details

  • Server: memory
  • Changed: create_relations tool (output schema gains optional skipped, description, result content), README

Motivation and Context

See #5654: the create_entities handler adds its notice because "otherwise an agent reads the response as its observations having been stored"; a relation the agent asked for and did not get has the same problem.

How Has This Been Tested?

Protocol-level tests (__tests__/tools.test.ts): the issue's exact repro (repeat an existing relation: relations: [] plus skipped and the notice), a mixed batch with an existing relation and a within-batch repeat, the updated tools/list expectation for the description and output schema, and write-limits.test.ts's at-the-limit repeat. npm run local:gate exited 0; its interface-diff stage shows only the description change and the added outputSchema.properties.skipped (additive; required unchanged).

Inspector CLI 2.12.0 (stdio): create_entities A, B; create_relations A knows B; then the same create_relations again. The second call's result:

  • Before (v2/main build), 2025-11-25 (--protocol-era legacy) and 2026-07-28 (modern) alike:
    {"content":[{"type":"text","text":"[]"}],"structuredContent":{"relations":[]}}
  • After, legacy:
    {"content":[{"type":"text","text":"[]"},{"type":"text","text":"Skipped 1 relation that already exists: A -[knows]-> B. It is already in the graph, so nothing was added for it."}],"structuredContent":{"relations":[],"skipped":[{"from":"A","to":"B","relationType":"knows"}]}}
  • After, modern: the same, plus _meta["io.modelcontextprotocol/serverInfo"] (2026-07-28 answered).

LLM client: Claude Code 2.1.332 (claude -p --strict-mcp-config, local build; the era cannot be selected from this client). Prompt: "create entities A and B, then create the relation A knows B, then call create_relations again with exactly the same relation; report what the second call returned and whether the relation was stored." The model received {"relations":[],"skipped":[{"from":"A","to":"B","relationType":"knows"}]} and answered: "The second create_relations call skipped the relation because it was already stored. The graph still holds exactly one A knows B relation."

Breaking Changes

None. The new output field is optional and only present when something was skipped; existing clients that read relations see the same value.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (patch, matching memory: create_entities silently drops observations for existing entities #4887's precedent for create_entities' skipped)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling (not applicable: no new error paths; missing entities still fail the call as before)
  • I have documented all environment variables and configuration options (not applicable: none added)

Additional context

Sibling PRs touch the same file: #5693 rewrites createRelations' dedupe loop (behavior-preserving). This PR relies on createRelations returning the requested relation objects themselves; the protocol tests here fail if a rewrite stops doing so.

🤖 Generated with Claude Code

create_relations returned a bare empty list for a relation that already
exists, so an agent could not tell "already there" from "nothing
happened". Mirror create_entities: list the skipped relations (existing,
or repeated earlier in the same call) in an optional `skipped` field of
structuredContent, add a text notice naming them, and say so in the
tool description and README.

Closes #5654

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 label Nov 30, 2026
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: edb349e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server-memory Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

memory: MCP interface diff

Base: c0075947ac6b (Merge pull request #5682 from modelcontextprotocol/v2/chore/5681-python-calver-2026.11.27)
Head: the build in this checkout, at 82359a85adf8 (Merge edb349e into c007594)

Diffed because it was named (--server).

⚠️ Interface changes detected in 1 part(s) of the interface. Review them below to confirm they are intended.

Tools Prompts Resources Resource templates
Base 9 0 1 0
Head 9 0 1 0

tools

--- base/tools.json
+++ target/tools.json

- tools[create_relations].description: "Create multiple new relations between entities in the knowledge graph. Relations should be in active..."
+ tools[create_relations].description: "Create multiple new relations between entities in the knowledge graph. Relations should be in active..."
+ tools[create_relations].outputSchema.properties.skipped: {"items":{"additionalProperties":false,"properties":{"from":{"description":"The name of the entity where the relation starts","type":"string"},"relationType":{"description":"The type of the relation",...

Updated by this run for edb349e3cf443893df273538957cc504810ed940.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change to report skipped duplicate relations.

No open issues 🎉

What changed in this PR

Updates the memory server’s create_relations response to report skipped duplicates, matching create_entities and addressing #5654 without changing graph mutation behavior.

Changes:

  • Adds an optional skipped array and a text notice for existing relations and within-request repeats.
  • Updates the tool description and README to explain skip reporting.
  • Adds protocol regression coverage and a patch changeset.
File Description
src/​memory/​README.md Documents duplicate handling and skipped-relation responses.
src/​memory/​index.ts Adds skip detection, notices, and the optional output field.
src/​memory/​__tests__/​write-limits.test.ts Updates duplicate-at-limit expectations to include skipped relations.
src/​memory/​__tests__/​tools.test.ts Verifies the updated schema, mixed batches, and repeated calls.
.changeset/​memory-create-relations-skipped.md Records the memory server patch release change.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: clean (no findings, no suppressed comments). The loop stops on the first clean round, so no further round was requested.

@cliffhall
cliffhall merged commit 28761d0 into v2/main Nov 30, 2026
48 checks passed
@cliffhall
cliffhall deleted the v2/fix/5654-memory-create-relations-skipped branch November 30, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: create_relations returns an empty list for an existing relation with no notice, unlike create_entities' skipped

2 participants