Skip to content

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

Open
RaidLZ wants to merge 1 commit intomodelcontextprotocol:mainfrom
RaidLZ:feat/memory-add-resource-support
Open

feat(memory): expose knowledge graph as MCP Resource#3323
RaidLZ wants to merge 1 commit intomodelcontextprotocol:mainfrom
RaidLZ:feat/memory-add-resource-support

Conversation

@RaidLZ
Copy link
Copy Markdown

@RaidLZ RaidLZ commented Feb 11, 2026

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
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 21, 2026

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
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.

2 participants