Skip to main content
Glama

chunk_text

Split Markdown text into deterministic, embedding-ready chunks using configurable max characters and overlap for retrieval.

Instructions

Split Markdown text into deterministic, embedding-ready chunks. This is a read-only low-level retrieval primitive: it does not index, embed, or write anything.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesMarkdown text to split
source_idNoOptional source identifier used in stable chunk ids
max_charsNoTarget maximum chunk body size before overlap. Default 1200.
overlap_charsNoPrefix overlap for chunks after the first. Default 120.

Implementation Reference

  • Tool handler for 'chunk_text' in handle_call_tool. It extracts text, source_id, max_chars, overlap_chars from arguments, calls chunk_markdown(), and returns the result as JSON.
    elif name == "chunk_text":
        text = args.get("text", "")
        source_id = args.get("source_id", "")
        chunks = chunk_markdown(
            text,
            source_id=source_id,
            max_chars=int(args.get("max_chars", 1200)),
            overlap_chars=int(args.get("overlap_chars", 120)),
        )
        result = {"source_id": source_id, "chunk_count": len(chunks), "chunks": chunks}
        return [types.TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))]
  • Tool registration for 'chunk_text' in handle_list_tools. Defines name 'chunk_text', description, and inputSchema with text (required), source_id, max_chars, overlap_chars.
    types.Tool(
        name="chunk_text",
        description="Split Markdown text into deterministic, embedding-ready chunks. This is a read-only low-level "
                    "retrieval primitive: it does not index, embed, or write anything.",
        inputSchema={
            "type": "object",
            "properties": {
                "text": {"type": "string", "description": "Markdown text to split"},
                "source_id": {"type": "string", "description": "Optional source identifier used in stable chunk ids"},
                "max_chars": {"type": "integer", "description": "Target maximum chunk body size before overlap. Default 1200."},
                "overlap_chars": {"type": "integer", "description": "Prefix overlap for chunks after the first. Default 120."},
            },
            "required": ["text"]
        }
    ),
  • The actual chunk_markdown() function that splits Markdown into deterministic chunks. Called by the chunk_text tool handler.
    def chunk_markdown(
        text: str,
        *,
        source_id: str = "",
        max_chars: int = 1200,
        overlap_chars: int = 120,
    ) -> list[dict[str, Any]]:
        """Split Markdown into stable, embedding-ready chunks.
    
        This is a pure low-level primitive: it does not read files, write SQLite, or
        call an embedding model. Higher-level retrieval and context tools can build
        on this contract without coupling chunking to a specific workflow.
        """
        normalized = text.replace("\r\n", "\n").replace("\r", "\n")
        if not normalized.strip():
            return []
    
        max_chars = max(1, int(max_chars))
        overlap_chars = max(0, min(int(overlap_chars), max_chars // 2))
        base_chunks = _make_base_chunks(normalized, max_chars=max_chars)
    
        chunks: list[dict[str, Any]] = []
        body_hash_counts: dict[str, int] = {}
        for index, block in enumerate(base_chunks):
            prefix_start = max(0, block.start - overlap_chars) if index else block.start
            overlap = block.start - prefix_start
            chunk_text = normalized[prefix_start:block.end]
            body_text = normalized[block.start:block.end]
            body_hash = hashlib.sha1(body_text.encode("utf-8")).hexdigest()[:12]
            text_hash = hashlib.sha1(chunk_text.encode("utf-8")).hexdigest()[:12]
            occurrence = body_hash_counts.get(body_hash, 0)
            body_hash_counts[body_hash] = occurrence + 1
            digest = hashlib.sha1(
                f"{CHUNKER_VERSION}\0{source_id}\0{body_hash}\0{occurrence}".encode("utf-8")
            ).hexdigest()[:12]
            chunks.append(
                {
                    "id": f"chunk:{digest}",
                    "chunker_version": CHUNKER_VERSION,
                    "source_id": source_id,
                    "index": index,
                    "start_char": prefix_start,
                    "end_char": block.end,
                    "body_start_char": block.start,
                    "body_end_char": block.end,
                    "overlap_chars": overlap,
                    "char_count": len(chunk_text),
                    "heading": block.heading,
                    "body_hash": body_hash,
                    "text_hash": text_hash,
                    "text": chunk_text,
                }
            )
        return chunks
  • Import of chunk_markdown from nouz_mcp.chunks into server.py, enabling the tool handler to call the chunking logic.
    from nouz_mcp.chunks import CHUNKER_VERSION, chunk_markdown
Behavior3/5

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

Since no annotations are provided, the description carries full burden. It states it is read-only, deterministic, and low-level. While it discloses essential behavioral traits, it lacks details on edge cases (e.g., handling of malformed Markdown, performance limits).

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, consisting of two sentences. The first sentence states the main action and result; the second adds critical context (read-only, non-indexing). No superfluous words.

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

Completeness4/5

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

Given the tool's simplicity and full schema documentation, the description covers key aspects: purpose, read-only nature, and input. It does not describe the output format (e.g., chunk structure or IDs), but for a low-level primitive this is acceptable.

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?

Schema coverage is 100% with each parameter described. The description does not add extra meaning beyond the schema; it repeats the purpose but does not elaborate on parameter nuances like the effect of overlap_chars or default values.

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?

The description clearly states the action 'Split Markdown text' and the purpose 'into deterministic, embedding-ready chunks'. It distinguishes itself from siblings like chunk_file (file-based) and embed (embedding) by calling itself a low-level retrieval primitive.

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?

The description provides context on when to use it (splitting text into chunks) and clarifies what it does not do (index, embed, write). However, it does not explicitly mention when not to use it or compare with alternatives like chunk_file or embed.

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/Semiotronika/NOUZ-MCP'

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