get_chunk
Retrieve a specific document chunk by its unique ID from the MCP RAG Server's vector storage for targeted content access.
Instructions
Retrieve a specific document chunk by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The unique identifier of the chunk to retrieve |
Implementation Reference
- src/mcp/tools.ts:81-97 (handler)Handler for 'get_chunk' tool that retrieves a document chunk by ID. Calls ragService.getChunk(args.id), returns the chunk with success status, or error if not found. Formats response with chunk id, content, metadata, and uri.
case 'get_chunk': const chunk = await ragService.getChunk(args.id); if (!chunk) { return { success: false, error: 'Chunk not found' }; } return { success: true, chunk: { id: chunk.id, content: chunk.content, metadata: chunk.metadata, uri: `rag://doc/${chunk.metadata.source}#${chunk.id}` } }; - src/services/vectorStore.ts:157-180 (handler)Core implementation of getChunk that retrieves a chunk by ID. Attempts ChromaDB query first, falls back to in-memory Map storage if ChromaDB fails. Returns DocumentChunk object or null if not found.
async getChunk(id: string): Promise<DocumentChunk | null> { if (this.collection) { try { const results = await this.collection.get({ ids: [id] }); if (!results.documents || results.documents.length === 0) { return null; } return { id: results.ids[0], content: results.documents[0], metadata: results.metadatas[0] }; } catch (error) { console.warn('ChromaDB getChunk failed, falling back to memory:', error); return this.chunks.get(id) || null; } } else { return this.chunks.get(id) || null; } } - src/mcp/tools.ts:33-46 (registration)Tool registration defining 'get_chunk' with description 'Retrieve a specific document chunk by its ID'. Input schema requires an 'id' string parameter identifying the chunk to retrieve.
{ name: 'get_chunk', description: 'Retrieve a specific document chunk by its ID', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The unique identifier of the chunk to retrieve' } }, required: ['id'] } }, - src/services/ragService.ts:66-68 (helper)RAGService wrapper method that delegates getChunk calls to the underlying VectorStore instance.
async getChunk(id: string): Promise<DocumentChunk | null> { return await this.vectorStore.getChunk(id); } - src/services/vectorStore.ts:5-16 (schema)DocumentChunk interface defining the structure of document chunks with id, content, and metadata fields including source, chunkIndex, totalChunks, title, page, and distance.
export interface DocumentChunk { id: string; content: string; metadata: { source: string; chunkIndex: number; totalChunks: number; title?: string; page?: number; distance?: number; }; }