feat: Add MCP tool for searching cached documents #115

Closed
opened 2026-01-23 22:12:05 +00:00 by jack · 1 comment
Owner

Problem

The documents table caches external documentation from Context7 (query-docs, resolve-library-id) and potentially WebFetch results. However, this cached content is not accessible via MCP tools.

Currently, users can only access documents via direct database queries:

bun -e "SELECT * FROM documents WHERE source LIKE '%anthropic%'"

This means Claude cannot recall previously fetched documentation without re-querying Context7.

Proposed Solution

Add a new MCP tool search_documents (or extend search with a source parameter):

Option A: New dedicated tool

mcp__plugin_claude-mem_mcp-search__search_documents({
  query: "streaming responses token counting",
  source?: "context7" | "webfetch" | "all",
  library_id?: "/anthropics/anthropic-sdk-typescript",
  limit?: 10
})
mcp__plugin_claude-mem_mcp-search__search({
  query: "anthropic sdk",
  source: "documents",  // New: "observations" (default) | "documents" | "all"
  limit: 5
})

Use Cases

  1. Avoid redundant Context7 calls - If documentation was fetched earlier in the session, reuse it
  2. Cross-session knowledge - Access library docs fetched in previous sessions
  3. Documentation recall - "What did Context7 say about React hooks earlier?"

Current Documents Schema

CREATE TABLE documents (
  id INTEGER PRIMARY KEY,
  project TEXT NOT NULL,
  source TEXT NOT NULL,           -- e.g., "/anthropics/anthropic-sdk-typescript"
  source_tool TEXT NOT NULL,      -- e.g., "context7" or "webfetch"
  title TEXT,
  content TEXT NOT NULL,          -- The actual documentation
  content_hash TEXT NOT NULL,
  type TEXT DEFAULT 'library-docs',
  metadata TEXT,
  memory_session_id TEXT,
  observation_id INTEGER,
  access_count INTEGER DEFAULT 1,
  last_accessed_epoch INTEGER,
  created_at TEXT,
  created_at_epoch INTEGER
);

Implementation Notes

  • Search could use FTS5 on content field for full-text search
  • Or simple LIKE queries for basic matching
  • Should update access_count and last_accessed_epoch on retrieval
  • Consider returning summarized/truncated content for large docs
  • Documents are created by the hook system when Context7 MCP tools are used
  • The observation_id field suggests documents can be linked to observations
## Problem The `documents` table caches external documentation from Context7 (`query-docs`, `resolve-library-id`) and potentially WebFetch results. However, this cached content is **not accessible via MCP tools**. Currently, users can only access documents via direct database queries: ```bash bun -e "SELECT * FROM documents WHERE source LIKE '%anthropic%'" ``` This means Claude cannot recall previously fetched documentation without re-querying Context7. ## Proposed Solution Add a new MCP tool `search_documents` (or extend `search` with a `source` parameter): ### Option A: New dedicated tool ```typescript mcp__plugin_claude-mem_mcp-search__search_documents({ query: "streaming responses token counting", source?: "context7" | "webfetch" | "all", library_id?: "/anthropics/anthropic-sdk-typescript", limit?: 10 }) ``` ### Option B: Extend existing search ```typescript mcp__plugin_claude-mem_mcp-search__search({ query: "anthropic sdk", source: "documents", // New: "observations" (default) | "documents" | "all" limit: 5 }) ``` ## Use Cases 1. **Avoid redundant Context7 calls** - If documentation was fetched earlier in the session, reuse it 2. **Cross-session knowledge** - Access library docs fetched in previous sessions 3. **Documentation recall** - "What did Context7 say about React hooks earlier?" ## Current Documents Schema ```sql CREATE TABLE documents ( id INTEGER PRIMARY KEY, project TEXT NOT NULL, source TEXT NOT NULL, -- e.g., "/anthropics/anthropic-sdk-typescript" source_tool TEXT NOT NULL, -- e.g., "context7" or "webfetch" title TEXT, content TEXT NOT NULL, -- The actual documentation content_hash TEXT NOT NULL, type TEXT DEFAULT 'library-docs', metadata TEXT, memory_session_id TEXT, observation_id INTEGER, access_count INTEGER DEFAULT 1, last_accessed_epoch INTEGER, created_at TEXT, created_at_epoch INTEGER ); ``` ## Implementation Notes - Search could use FTS5 on `content` field for full-text search - Or simple LIKE queries for basic matching - Should update `access_count` and `last_accessed_epoch` on retrieval - Consider returning summarized/truncated content for large docs ## Related - Documents are created by the hook system when Context7 MCP tools are used - The `observation_id` field suggests documents can be linked to observations
Author
Owner

Vereinfachung: Keine Source-Unterscheidung

Nach Überlegung: Die source-Filterung ist wahrscheinlich unnötig komplex.

Einfacherer Ansatz:

mcp__plugin_claude-mem_mcp-search__search_documents({
  query: "streaming responses",
  limit?: 10
})

Sucht einfach in allen gecachten Documents - egal ob Context7, WebFetch oder andere Quellen.

Vorteile:

  • Simpler API
  • User muss nicht wissen, woher die Doku kam
  • Einheitliche Suche über alle externen Ressourcen

Die source und source_tool Felder bleiben in der Response erhalten, sodass der User sieht woher das Ergebnis stammt - aber filtern muss man nicht danach.

## Vereinfachung: Keine Source-Unterscheidung Nach Überlegung: Die `source`-Filterung ist wahrscheinlich unnötig komplex. **Einfacherer Ansatz:** ```typescript mcp__plugin_claude-mem_mcp-search__search_documents({ query: "streaming responses", limit?: 10 }) ``` Sucht einfach in **allen** gecachten Documents - egal ob Context7, WebFetch oder andere Quellen. **Vorteile:** - Simpler API - User muss nicht wissen, woher die Doku kam - Einheitliche Suche über alle externen Ressourcen Die `source` und `source_tool` Felder bleiben in der Response erhalten, sodass der User sieht woher das Ergebnis stammt - aber filtern muss man nicht danach.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
customable/claude-mem#115
No description provided.