Skip to main content
Glama

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
NameRequiredDescriptionDefault
idYesThe unique identifier of the chunk to retrieve

Implementation Reference

  • 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}`
        }
      };
  • 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']
      }
    },
  • 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);
    }
  • 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;
      };
    }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LuizDoPc/mcp-rag'

If you have feedback or need assistance with the MCP directory API, please join our Discord server