Skip to main content
Glama
rag-chunk-mcp
by leofannf

rag-chunk-mcp

Tests License: MIT Python 3.10+

An MCP server that gives agents RAG text-chunking tools with source offsets for citations. Built on rag-chunk-lab.

Agents that answer questions over enterprise documents live or die by chunking: split a policy clause in half and the answer is wrong even when the model is fine; lose the offsets and the answer cannot cite its source. This server lets an agent chunk a document, compare strategies on the actual text, and pick deliberately instead of guessing.

Tools

Tool

What it does

chunk_text

Chunk text with one strategy (fixed, sentence, recursive); returns chunks with start/end offsets plus coverage stats

compare_strategies

Run all three strategies at the same size and compare counts, sizes, and coverage

explain_strategy

Explain when to use each strategy

Example compare_strategies result on a 753-character Chinese policy document at size 200:

{
  "fixed":     {"count": 5, "avg_chars": 190.4, "min_chars": 152, "max_chars": 200, "coverage": 0.9987},
  "sentence":  {"count": 6, "avg_chars": 159.8, "min_chars": 69,  "max_chars": 194, "coverage": 0.9987},
  "recursive": {"count": 6, "avg_chars": 123.8, "min_chars": 34,  "max_chars": 191, "coverage": 0.9867}
}

And a chunk_text result keeps whole policy articles together with offsets an agent can cite:

{"index": 1, "start": 36, "end": 216, "chars": 180, "text": "第一条 为规范公司考勤管理…第三条 考勤管理实行打卡制…"}

Related MCP server: rag-mcp

Install

git clone https://github.com/leofannf/rag-chunk-mcp.git
cd rag-chunk-mcp
pip install -e .

Use with an MCP client

Add the server to your client's MCP configuration (see examples/mcp-config.json):

{
  "mcpServers": {
    "rag-chunk": {
      "command": "rag-chunk-mcp",
      "args": []
    }
  }
}

The server speaks MCP over stdio and works with both the v1 (FastMCP) and v2 (MCPServer) Python SDKs. You can also run it directly:

rag-chunk-mcp          # or: python -m rag_chunk_mcp

中文简介

rag-chunk-mcp 是一个 MCP 服务器,把 RAG 文本分块能力提供给智能体调用:固定窗口、按句打包、递归分隔符三种策略,每块带原文字符偏移方便引用溯源,并可一键对比三种策略在同一文档上的块数、大小与覆盖率。适合企业制度问答等需要“答得准、引得出”的场景。

Roadmap

  • chunk_file tool for local files (txt/md) with heading-path metadata

  • Token-based sizing alongside character counts

  • Semantic chunking option (split where embedding similarity drops)

  • Streamable HTTP transport option

Contributing

Issues and pull requests are welcome. Run the tests before submitting:

python -m unittest discover -s tests -v

License

MIT, see LICENSE.

Available Tools

3 tools
chunk_textA

Split a document into RAG chunks with source offsets for citations.

strategy is one of "fixed", "sentence", "recursive". size is the max characters per chunk. overlap applies to "fixed"; overlap_sentences applies to "sentence".

Inputs: text (required), size, overlap, strategy, +1 more.

compare_strategiesB

Compare fixed, sentence, and recursive chunking on the same text.

Returns per-strategy chunk counts, size statistics, and source coverage so an agent can pick a strategy before embedding.

Inputs: text (required), size.

explain_strategyB

Explain when to use the "fixed", "sentence", or "recursive" strategy.

Inputs: strategy (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 3 tools

    Disambiguation4/5

    Each tool has a fairly distinct role: explain_strategy is static guidance, chunk_text performs chunking, and compare_strategies runs an empirical comparison. The only mild overlap is between explain_strategy and compare_strategies, since both serve strategy selection, but descriptions make the boundary (advice vs. measured statistics) clear enough.

    Naming Consistency5/5

    All three names follow a consistent verb_noun pattern: explain_strategy, chunk_text, compare_strategies. No style mixing or vague verbs.

    Tool Count5/5

    Three tools for a narrow chunking utility is well-scoped: one for guidance, one for execution, one for comparison. Each earns its place and nothing extraneous is included.

    Completeness4/5

    The surface covers the core lifecycle of choosing a strategy, applying it, and validating the choice via comparison. Minor gaps exist (no token-based sizing, custom separator control, or direct chunk preview/inspection tool), but agents can work around these.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides AI agents with comprehensive document parsing capabilities including PDF text extraction, OCR, HTML-to-markdown conversion, table extraction, and summarization, optimized for agent workflows.
      65 npm
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables ingestion and semantic search over text documents using PostgreSQL + pgvector and OpenAI-compatible embeddings, allowing any LLM agent to retrieve relevant chunks for grounded answers.
      4
      1
      AGPL 3.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI agents with document conversion to Markdown, intelligently routing small and large files, and enabling targeted extraction via sections, search, and token budgets.
      6
      MIT