Skip to content

feat(memory): expose knowledge graph as MCP Resource#3323

Merged
olaservo merged 3 commits into
modelcontextprotocol:mainfrom
RaidLZ:feat/memory-add-resource-support
Jun 17, 2026
Merged

feat(memory): expose knowledge graph as MCP Resource#3323
olaservo merged 3 commits into
modelcontextprotocol:mainfrom
RaidLZ:feat/memory-add-resource-support

Conversation

@RaidLZ

@RaidLZ RaidLZ commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Register the knowledge graph as a readable MCP Resource at
memory://knowledge-graph, enabling clients to discover and read
the graph via the Resources protocol.

This demonstrates the underutilized Resources feature of MCP in a
reference server, as encouraged by CONTRIBUTING.md.

@cliffhall cliffhall added enhancement New feature or request server-memory Reference implementation for the Memory MCP server - src/memory labels Apr 20, 2026
@cliffhall

Copy link
Copy Markdown
Member

@claude review

@claude

claude Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cliffhall's task in 1m 47s —— View job


PR Review: feat(memory): expose knowledge graph as MCP Resource

  • Gather context and read changed files
  • Analyze implementation for correctness and MCP protocol compliance
  • Check code quality and style
  • Post review feedback

Summary

Good concept — adding a Resource to the memory server directly supports the CONTRIBUTING.md goal of showcasing underutilized MCP protocol features. The handler implementation is correct: uri.href echoes back the requested URI, the contents array structure matches the spec, and application/json is the right MIME type. A few things need attention before merging.


Issues

1. Resource name violates project naming convention (must fix)

src/memory/index.ts:471

server.registerResource(
  "knowledge_graph",   // ❌ snake_case

CLAUDE.md explicitly requires kebab-case for registered tools/prompts/resources:

kebab-case for file names and registered tools/prompts/resources

The name should be "knowledge-graph" (consistent with the URI memory://knowledge-graph too).

Fix this →


2. No tests (should fix)

The PR adds no tests. The everything server has a registrations.test.ts that verifies registerResource is called with the right arguments. The memory server should have an equivalent test — at minimum asserting the resource is registered with the correct URI and MIME type, and that its handler returns JSON-serialized graph data.

// example sketch
it('should register knowledge-graph resource with correct URI', () => {
  const mockServer = { registerResource: vi.fn() };
  // trigger registration ...
  expect(mockServer.registerResource).toHaveBeenCalledWith(
    'knowledge-graph',
    'memory://knowledge-graph',
    expect.objectContaining({ mimeType: 'application/json' }),
    expect.any(Function)
  );
});

3. Comment block exceeds project style limit (minor)

src/memory/index.ts:468–470

// Expose the knowledge graph as a readable MCP Resource.
// This demonstrates the Resources protocol feature, enabling clients
// to discover and read the graph without calling a tool.

CLAUDE.md says: "Don't add multi-line comment blocks — one short line max." Condense to one line, or drop entirely since the code is self-explanatory.


Observations (not blockers)

  • Subscription support: Since the graph changes frequently via mutation tools, clients subscribed to this resource won't receive notifications/resources/updated events. Wiring up server.sendResourceUpdated("memory://knowledge-graph") after each write operation would make this much more useful. Not required now, but worth a follow-up.
  • title field: The SDK's resource metadata supports a human-readable title (separate from the name arg). Adding title: "Knowledge Graph" alongside description would improve discoverability in clients that display resource titles.

Verdict

Request changes on items 1 (naming) and 2 (tests). Item 3 is a minor style fix. The core implementation is solid.

Register the knowledge graph as a readable MCP Resource at
memory://knowledge-graph, enabling clients to discover and read
the graph via the Resources protocol without invoking a tool.

Mutation tools (create_entities, create_relations, add_observations,
delete_entities, delete_observations, delete_relations) now emit
notifications/resources/updated so subscribed clients see live
graph changes.

Resource registration is extracted into the exported
registerKnowledgeGraphResource() function so it can be unit-tested
in isolation, mirroring the everything server's registration
pattern. New tests assert registerResource is called with the
correct kebab-case name, URI, mime type, and that the handler
returns the graph as JSON in the contents array.

Addresses PR modelcontextprotocol#3323 review feedback:
- kebab-case resource name per CLAUDE.md style guide
- single-line comment per CLAUDE.md style guide
- title metadata for client discoverability
- resource update notifications after mutations
- test coverage matching everything/registrations.test.ts pattern
- README documents the new Resource
@RaidLZ RaidLZ force-pushed the feat/memory-add-resource-support branch from cb66bcc to 40b2581 Compare May 1, 2026 23:19

@LuuOW LuuOW left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Technical audit: Verified MCP server implementation for consistency with current SDK patterns.

…ource

PR modelcontextprotocol#3323 emitted notifications/resources/updated after every mutation but
the server only advertised resources.listChanged, so resources/subscribe
returned -32601 and a spec-compliant client could never actually subscribe.

Declare resources.subscribe, add subscribe/unsubscribe request handlers that
track subscribed URIs, and only emit notifications/resources/updated when the
client has subscribed to that URI.

Co-authored-by: Lazreg Raed <lazregraed222@gmail.com>
@olaservo

Copy link
Copy Markdown
Member

Thanks for adding this, @RaidLZ — exposing the knowledge graph as a Resource is a great demonstration of the feature.

One gap I found while testing with an SDK client: the server emits notifications/resources/updated after mutations, but it only advertised resources.listChanged, not resources.subscribe. So resources/subscribe returned -32601 (Method not found), and a spec-compliant client could never actually subscribe to receive those updates — the README's "subscribed clients see live changes" wasn't reachable end to end.

Since "allow edits from maintainers" was enabled, I pushed a small follow-up commit to this branch (keeping your authorship of the base PR) that:

  • declares resources.subscribe
  • adds subscribe/unsubscribe request handlers that track subscribed URIs
  • only emits resources/updated when the client has actually subscribed to that URI
  • adds unit tests for the subscription wiring

Verified end to end with an SDK client: capability advertised, no notification before subscribe, subscribe succeeds, a notification fires while subscribed, and it stops after unsubscribe. Build is clean and all 50 tests pass.

Feel free to adjust or squash the follow-up however you like. Thanks again for the contribution!

Follow-up commit drafted with assistance from Claude Code.

@RaidLZ

RaidLZ commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @olaservo ! I pulled your follow-up commit and reviewed it the subscribe/unsubscribe handlers and tests look great, and I'm happy to keep them as-is. Appreciate you getting this over the line.

@olaservo olaservo merged commit 7b1170d into modelcontextprotocol:main Jun 17, 2026
19 checks passed
@olaservo

Copy link
Copy Markdown
Member

@RaidLZ thanks for your PR and for your patience. :)

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

Labels

enhancement New feature or request server-memory Reference implementation for the Memory MCP server - src/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants