Repository navigation
feat(memory): add lightweight read modes to the read tools - #5394
Merged
Merged
Conversation
read_graph, search_nodes and open_nodes take an optional observationLimit, which caps the observations returned per entity and adds each entity's total as observationCount (0 gives an overview of names, types and counts). read_graph also takes entityTypes, and search_nodes a limit on matches. Every option is optional, so a call without them, and the knowledge-graph resource, return what they did. read_graph's description also says when to use it rather than its siblings (#5202's guidance): its inputSchema is on the next line, so the two edits cannot sit in separate PRs without conflicting. Closes #3953 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
🦋 Changeset detectedLatest commit: 27148ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the lightweight memory-read changes.
No open issues 🎉
What changed in this PR
Adds optional lightweight reads to the memory server, addressing #3953 by letting clients retrieve an overview before loading full observations. Existing calls and the knowledge-graph resource retain their behavior.
Changes:
- Adds observation limits and counts to all three read tools, entity-type filtering to
read_graph, and a result limit tosearch_nodes. - Updates input validation, output schemas, documentation, and
read_graphselection guidance. - Adds protocol-level tests and a minor-release changeset.
| File | Description |
|---|---|
src/memory/README.md |
Documents the optional inputs and overview-to-detail usage. |
src/memory/index.ts |
Implements read options, schemas, and tool wiring. |
src/memory/__tests__/tools.test.ts |
Updates expected tool descriptions and advertised schemas. |
src/memory/__tests__/read-options.test.ts |
Tests options, validation, defaults, and unchanged resource results. |
.changeset/memory-3953-lightweight-reads.md |
Records the feature for a minor package release. |
Review effort: Balanced
Member
Author
|
Copilot round 1: clean (no findings, approval recommended). Review loop stops on this first clean round. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3953
Description
Optional lightweight read modes for the memory server's three read tools, so a large graph need not be returned whole:
read_graph,search_nodes,open_nodesobservationLimit(integer ≥ 0)observationCountwith its total.0returns names, types and counts only: the "metadata only" overview the issue asks forread_graphentityTypes(string[], at least one)search_nodeslimit(integer ≥ 1)Every option is optional: a call without them, and the
memory://knowledge-graphresource, return exactly what they did. Inputs are Zod-validated, with a description on every field that says when to use it (observationLimit: 0for an overview, thenopen_nodesfor the entities you need). The read tools'outputSchemagains an optionalobservationCounton each entity, so structured results still validate. README and a minor changeset are included.read_graph's description also changes here, carrying the #5202 guidance ("use this only when you need everything; prefer search_nodes … and open_nodes …"). Itsdescription:andinputSchema:lines are adjacent, so they cannot be edited by two PRs that merge cleanly in either order; the #5202 PR changes the other two descriptions.Server Details
@modelcontextprotocol/server-memory)read_graph,search_nodes,open_nodes(new optional inputs, optionalobservationCountin output,read_graphdescription), the manager'sreadGraph/searchNodes/openNodes, README, tests.Motivation and Context
#3953: on a long-lived graph
read_graphreturns every observation of every entity, tens of thousands of tokens, with no way to load names first and observations selectively. The prototype #3959 by @surapuramakhil informed this; it differs in foldingincludeObservationsandmetadataOnlyintoobservationLimit: 0(one knob instead of three overlapping ones, and the counts the issue asks for), and in not adding observation paging.Declined as beyond a reference-server-sized change: pagination cursors /
observationOffset, archiving or splitting oversized observations into new entities, and sorting or "most recent first" selection. Each would be a capability of its own, not an optional knob on the existing reads.How Has This Been Tested?
Protocol-level tests in
__tests__/read-options.test.ts(an SDK Client over an in-memory transport) cover every option on every tool, their combinations, the defaults (unchanged results, noobservationCount, the resource unaffected) and the validation errors;__tests__/tools.test.tspins the new advertised schemas. Per-file coverage ofindex.ts: 98.9 statements, 99.3 branches, 98.1 functions, 99.2 lines.Inspector CLI 2.12.0, against a seeded graph (Alice: 3 observations, Bob: 1, Acme Corp: 2; Alice knows Bob, Alice works_at Acme Corp), each call run with
--protocol-era legacy(2025-11-25) and--protocol-era modern(2026-07-28), identical results in both:read_graph {"observationLimit":0}: onv2/mainthe unknown argument is ignored and every observation comes back; on this branch:{"name":"Alice","entityType":"person","observations":[],"observationCount":3}, Bob0/1, Acme Corp0/2, both relations.read_graph {"entityTypes":["organization"]}→ Acme Corp only, withAlice works_at Acme Corp.search_nodes {"query":"acme","limit":1,"observationLimit":1}→ Alice only,["works at Acme Corp"],observationCount: 3, and her two relations.open_nodes {"names":["Alice"],"observationLimit":2}→["works at Acme Corp","likes tea"],observationCount: 3.read_graph {}→ the full graph, noobservationCount(default unchanged).search_nodes {"query":"a","limit":0}→isError: true,Input validation error: Invalid arguments for tool search_nodes: limit: Too small: expected number to be >=1.LLM client: Claude Code 2.1.312 (
claude -p --strict-mcp-config, local build, read tools allowed; no era switch, so the era could not be selected):read_graph {"observationLimit":0}; answered with a table of names, types and counts (3/1/2), offeringopen_nodesfor detail.read_graph {"entityTypes":["organization"],"observationLimit":0}; "one organization, Acme Corp, and its only relation is that Alice works_at Acme Corp".npm run local:gateexits 0.Breaking Changes
None. Every new input is optional and defaults to the old behavior;
observationCountis an optional output field that appears only whenobservationLimitis passed.Types of changes
Checklist
npm run changeset) if this changes what a TypeScript server publishes (minor:.changeset/memory-3953-lightweight-reads.md)🤖 Generated with Claude Code