Skip to content

Expose project-scoped context as an MCP resource - #412

Closed
Lauritz-Timm wants to merge 6 commits into
rtk-ai:developfrom
Lauritz-Timm:feat/mcp-memory-resources
Closed

Expose project-scoped context as an MCP resource#412
Lauritz-Timm wants to merge 6 commits into
rtk-ai:developfrom
Lauritz-Timm:feat/mcp-memory-resources

Conversation

@Lauritz-Timm

@Lauritz-Timm Lauritz-Timm commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Expose one bounded active-project context resource through MCP.

Motivation

MCP resources are useful for context loading, but local transport does not justify exposing all memories, topics, memoirs, and graph links. The resource must remain project-scoped and bounded.

Changes

  • advertise MCP resources
  • expose only icm://context/current
  • derive the project from the server working directory
  • read exact project, context-<project>, and contexte-<project> topics
  • exclude global preferences and other projects
  • enforce a 1,200-token Markdown budget
  • return no templates and reject arbitrary memory, topic, and memoir URIs
  • bound each exact-topic query to 500 rows
  • use private one-hour list caching and ttlMs: 0 for reads
  • use -32602 for invalid modern resource requests

Compatibility and safety

Modern clients receive result, cache, and server metadata. Legacy clients retain the plain MCP resource shape and existing error behavior. Existing tools are unchanged.

Validation

cargo test -p icm-mcp --locked --offline
cargo clippy -p icm-mcp --all-targets --locked --offline -- -D warnings
cargo fmt --all -- --check

The suite covers fixed listings, empty templates and context, localized project topics, cross-project and preference exclusion, truncation, malformed and unknown URIs, both error-code eras, internal errors, and cache policy.

Manual smoke test:

TEST_DB="$(mktemp -d)/icm.sqlite"
cargo run -q -p icm-cli -- --db "$TEST_DB" --no-embeddings \
  store --topic context-icm --content "MCP project resource smoke test"
printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"resources/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
  '{"jsonrpc":"2.0","id":2,"method":"resources/read","params":{"uri":"icm://context/current","_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' \
  | cargo run -q -p icm-cli -- --db "$TEST_DB" --no-embeddings serve

Expected: one fixed resource and a bounded Markdown snapshot for the current project.

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.

1 participant