rag-chunk-mcp
# rag-chunk-mcp
[](https://github.com/leofannf/rag-chunk-mcp/actions/workflows/test.yml)
[](LICENSE)
[](pyproject.toml)
An MCP server that gives agents RAG text-chunking tools with source
offsets for citations. Built on
[rag-chunk-lab](https://github.com/JiangChunchao/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:
```json
{
"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:
```json
{"index": 1, "start": 36, "end": 216, "chars": 180, "text": "第一条 为规范公司考勤管理…第三条 考勤管理实行打卡制…"}
```
## Install
```bash
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`](examples/mcp-config.json)):
```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:
```bash
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:
```bash
python -m unittest discover -s tests -v
```
## License
MIT, see [LICENSE](LICENSE).
TDQS
Scored across 3 tools
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.
All three names follow a consistent verb_noun pattern: explain_strategy, chunk_text, compare_strategies. No style mixing or vague verbs.
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.
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.