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;
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves a chunk, implying a read-only operation, but doesn't mention error handling (e.g., what happens if the ID is invalid), performance characteristics (e.g., speed, caching), or authentication needs. For a retrieval tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without any fluff or redundancy. It's appropriately sized for a simple retrieval tool and front-loaded with the essential information, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (1 parameter, no output schema, no annotations), the description is minimal but adequate for basic understanding. However, it lacks context about what a 'document chunk' is (e.g., part of a larger document), how IDs are obtained, or what the return format looks like (since no output schema exists). For a retrieval tool, this leaves the agent with incomplete information to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'id' parameter fully documented as 'The unique identifier of the chunk to retrieve'. The description adds no additional meaning beyond this, as it only restates that retrieval is by ID. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('retrieve') and resource ('document chunk'), specifying it's by ID. It distinguishes from 'search' (which likely finds chunks by content) and 'ingest_docs' (which adds documents), but doesn't explicitly differentiate from 'refresh_index' (which might update metadata). The purpose is specific but could be slightly more precise about what a 'chunk' entails.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'search' (for finding chunks by query) or 'refresh_index' (for updating indices). The description implies usage when you have a specific chunk ID, but it doesn't state prerequisites (e.g., needing to know the ID from prior operations) or exclusions (e.g., not for bulk retrieval).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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