Skip to main content
Glama
cskwork

Knowledge Retrieval Server

by cskwork

get-chunk-with-context

Retrieve a specific document chunk with surrounding context to understand content in relation to adjacent information.

Instructions

Get specific chunk with surrounding context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentIdYesDocument ID
chunkIdYesChunk ID
windowSizeNoContext window size (default: 1)

Implementation Reference

  • The handler function for the 'get-chunk-with-context' tool. It retrieves the document by ID from the repository, fetches the specified chunk with context using getChunkWithWindow, handles errors, and formats the response as text content.
    case 'get-chunk-with-context': { const { documentId, chunkId, windowSize } = args as { documentId: number; chunkId: number; windowSize?: number; }; const document = repository.getDocumentById(documentId); if (!document) { const content: TextContent[] = [{ type: 'text', text: `Document with ID ${documentId} not found.` }]; return { content }; } const chunks = document.getChunkWithWindow(chunkId, windowSize || 1); if (chunks.length === 0) { const content: TextContent[] = [{ type: 'text', text: `Chunk with ID ${chunkId} not found.` }]; return { content }; } const content = chunks.map(chunk => chunk.text).join('\n\n---\n\n'); const textContent: TextContent[] = [{ type: 'text', text: content }]; return { content: textContent }; }
  • Input schema definition for the 'get-chunk-with-context' tool, specifying parameters: documentId (required), chunkId (required), windowSize (optional, default 1).
    inputSchema: { type: 'object', properties: { documentId: { type: 'number', description: 'Document ID' }, chunkId: { type: 'number', description: 'Chunk ID' }, windowSize: { type: 'number', description: 'Context window size (default: 1)', default: 1 } }, required: ['documentId', 'chunkId'] }
  • src/index.ts:262-283 (registration)
    Tool registration in the listTools response, including name, description, and inputSchema.
    name: 'get-chunk-with-context', description: 'Get specific chunk with surrounding context.', inputSchema: { type: 'object', properties: { documentId: { type: 'number', description: 'Document ID' }, chunkId: { type: 'number', description: 'Chunk ID' }, windowSize: { type: 'number', description: 'Context window size (default: 1)', default: 1 } }, required: ['documentId', 'chunkId'] } }
  • Core helper method implementing the chunk retrieval with context window. Finds the target chunk by ID, then returns surrounding chunks within the specified window size.
    getChunkWithWindow(chunkId: number, windowSize: number): DocumentChunk[] { const chunkIndex = this.chunks.findIndex( (chunk) => chunk.chunkId === chunkId ); if (chunkIndex === -1) { return []; } const start = Math.max(0, chunkIndex - windowSize); const end = Math.min(this.chunks.length, chunkIndex + windowSize + 1); return this.chunks.slice(start, end); }

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/cskwork/keyword-rag-mcp'

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