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);
    }
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 with context, but doesn't describe what 'surrounding context' entails, whether it's read-only, potential errors, or response format. This is a significant gap for a tool with no annotation coverage, as it leaves key behavioral traits unspecified.

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 extremely concise and front-loaded with a single sentence that directly states the tool's function. There is no wasted language or unnecessary elaboration, making it efficient for quick comprehension. Every word earns its place by conveying the core purpose without fluff.

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 complexity of retrieving chunks with context, no annotations, and no output schema, the description is incomplete. It doesn't explain what a chunk is, how context is provided, or what the return value includes. For a tool with 3 parameters and no structured support, this leaves too many gaps for effective agent use.

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 description adds minimal meaning beyond the input schema, which has 100% coverage. It implies parameters for documentId, chunkId, and windowSize but doesn't explain their relationships or semantics (e.g., how chunkId relates to documentId, what windowSize units are). With high schema coverage, the baseline is 3, and the description doesn't significantly enhance parameter understanding.

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

Purpose3/5

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

The description states the tool's purpose ('Get specific chunk with surrounding context'), which is clear but vague. It specifies the verb 'Get' and resource 'chunk with surrounding context', but doesn't distinguish from siblings like 'get-document-by-id' or explain what a 'chunk' is in this context. The purpose is understandable but lacks specificity about what constitutes a chunk versus a document.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention siblings like 'get-document-by-id' or 'search-documents', nor does it specify prerequisites or exclusions. Usage is implied from the name and description but not explicitly stated, leaving the agent to infer context.

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

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