Skip to main content
Glama

Chunk text for RAG

ai_chunk_text
Read-onlyIdempotent

Generate token-sized chunks from text, Markdown, or files for retrieval-augmented generation (RAG) and embeddings, preserving headings, paragraphs, sentence boundaries, overlap, and offsets.

Instructions

Split text, markdown or a text file into token-sized chunks for retrieval (RAG) and embeddings. Splits at markdown headings (ATX "#" headings, never inside code fences) and paragraphs first, then sentences (lines inside code blocks), and only cuts mid-sentence when a single sentence is longer than maxTokens. Consecutive chunks of the same section share about overlapTokens of text. Each chunk returns index, text, tokens, startChar/endChar (JavaScript string offsets, end exclusive, so text === source.slice(startChar, endChar) once CRLF line endings are normalised to \n) and the heading path it sits under. Tokens are counted with tiktoken (o200k_base by default; for Claude treat counts as estimates). Give "text" or "path" (file path or base64); give "output" to also write the chunks as JSONL (one JSON object per line).

Input Schema

NameRequiredDescriptionDefault
pathNoOr: a UTF-8 text/markdown file, as a local path or base64 (raw or a data: URI).
textNoThe text (inline).
outputNoAlso write the chunks as JSONL to this file (or folder ending in "/").
encodingNoTokenizer: "o200k_base" (GPT-4o / o-series, default) or "cl100k_base" (GPT-4 / GPT-3.5 / text-embedding-3).o200k_base
markdownNoTreat "#" lines as section headings (default true). Set false for plain text.
maxChunksNoMost chunks to return inline (the JSONL file always has all). Default 2000.
maxTokensNoLargest chunk, in tokens. Default 500.
includeTextNoReturn each chunk's text inline. Default: true, or false when "output" is given.
overlapTokensNoTokens repeated from the end of the previous chunk (same section only). Default 50. Must be below maxTokens.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

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

Annotations cover safety (readOnly/idempotent/closed-world), and the description adds genuinely new behavior: heading-aware split order, never splitting inside code fences, mid-sentence cuts only when a sentence exceeds maxTokens, overlap only within the same section, and the caveat that Claude token counts are estimates. It also discloses the maxChunks inline cap vs. the JSONL file always containing all chunks.

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

Conciseness4/5

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

Well front-loaded: purpose first, then split strategy, then return fields, then input modes. It is dense (a single long paragraph covering splitting, overlap, return fields, tokenizer, and I/O modes), which slightly hurts scannability but every sentence carries information.

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

Completeness5/5

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

There is no output schema, yet the description enumerates each returned field (index, text, tokens, startChar/endChar, heading path) and the JSONL side-effect, plus the tokenizer caveat. An agent has everything needed to predict inputs and outputs.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3; the description goes beyond it by explaining overlap semantics ('same section only'), that endChar is exclusive with CRLF normalisation to \n, the tiktoken default and Claude caveat, and the includeText default flip when output is given.

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

Purpose5/5

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

States a specific verb+resource ('Split text, markdown or a text file into token-sized chunks') with an explicit purpose (RAG/embeddings). An agent can immediately distinguish this from siblings like ai_token_count or ai_pdf_to_markdown.

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

Usage Guidelines4/5

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

Clear usage context is given: 'Give "text" or "path" ... give "output" to also write the chunks as JSONL', which tells the agent how to invoke for the desired result. It does not name alternatives or exclusions (e.g., when to prefer ai_token_count or a markdown converter first), so it falls short of a 5.

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

Deploy Server

Other Tools