Skip to main content
Glama
halans

Knowledge Base MCP Server

by halans

get_chunk

Retrieve full content from a knowledge base by specifying a chunk ID. Use this tool to access detailed information after identifying relevant content through search.

Instructions

Retrieve a specific chunk from the knowledge base by its ID. Use this when you need the full content of a previously found chunk.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chunk_idYesThe ID of the chunk to retrieve (e.g., 'chunk-42')

Implementation Reference

  • The MCP tool registration and handler implementation for "get_chunk".
    server.tool(
      "get_chunk",
      "Retrieve a specific chunk from the knowledge base by its ID. Use this when you need the full content of a previously found chunk.",
      {
        chunk_id: z.string().describe("The ID of the chunk to retrieve (e.g., 'chunk-42')"),
      },
      async ({ chunk_id }) => {
        try {
          const chunk = getChunkById(chunk_id);
    
          if (!chunk) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Chunk not found with ID: "${chunk_id}"`,
                },
              ],
            };
          }
    
          return {
            content: [
              {
                type: "text" as const,
                text: `# ${chunk.title}
    **Category:** ${chunk.category}
    **Chunk ID:** ${chunk.id}
    
    ${chunk.content}`,
              },
            ],
          };
        } catch (error) {
          const errorMessage =
            error instanceof Error ? error.message : "Unknown error";
          return {
            content: [
              {
                type: "text" as const,
                text: `Error retrieving chunk: ${errorMessage}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The helper function that performs the actual logic of retrieving the chunk by ID.
    export function getChunkById(chunkId: string): Chunk | null {
      // Validate chunk ID format to prevent potential issues
      if (!CHUNK_ID_PATTERN.test(chunkId)) {
        return null;
      }
      
      const knowledge = getKnowledge();
      return knowledge.chunks.find((chunk) => chunk.id === chunkId) || null;
    }
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/halans/local-mcp-simple'

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