chunktuner MCP setup (Python / FastMCP)¶
The MCP server is pure Python: it imports the chunktuner library directly (no Node.js, no separate HTTP hop for MCP).
Install¶
Claude Desktop (.mcp.json)¶
{
"mcpServers": {
"chunktuner": {
"command": "uvx",
"args": ["--from", "chunktuner[mcp]", "chunk-tune-mcp"],
"env": {
"CHUNK_TUNER_BASE_DIR": "/absolute/path/to/your/corpus"
}
}
}
}
CHUNK_TUNER_BASE_DIR: everypathargument to tools must resolve under this directory (security boundary).CHUNKTUNER_API_BASE/CHUNKTUNER_API_KEY: optional OpenAI-compatible endpoint and key for LiteLLM when tools pass anembedding_model(LM Studio, Ollama, etc.). Do not put secrets in MCP tool arguments.CHUNKTUNER_LLM_MODEL: LiteLLM model id passed to the evaluator asllm_answer_modelfor MCPevaluate_chunking/recommend_config(dataset generation, generation metrics when enabled, etc.); defaults togpt-4o-miniwhen unset (seechunktuner.config.DEFAULT_LLM_MODEL). It applies regardless of whether anembedding_modelis passed to the tool.CHUNKTUNER_MAX_PREVIEW_CHARS: maximumtextlength accepted bypreview_chunks(default500000characters); longer input is rejected with an error suggestingevaluate_chunkingwith a file path.CHUNKTUNER_CACHE_DIR: used by the library helperchunktuner.config.default_cache_dir. MCP tools cache embeddings and generated datasets in the default workspacecache_dir(~/.cache/chunktuner), which is the same locationchunk-tune cache stats|clearuses when no workspace config is given.- Entry point:
chunk-tune-mcp→chunktuner.mcp.server:run(stdio JSON-RPC on stdout; neverprint()in MCP code).
Cursor¶
Cursor’s MCP configuration uses the same command / args / env shape as above: register a server named (for example) chunktuner with uvx, args ["--from", "chunktuner[mcp]", "chunk-tune-mcp"], and set CHUNK_TUNER_BASE_DIR to an absolute corpus root. Where to paste this JSON depends on your Cursor version (global MCP settings vs project config); see the Cursor MCP documentation for the current UI.
Data handling¶
- Embeddings: When MCP tools are called with an
embedding_model,LiteLLMEmbeddingFunctioninvokes your configured provider via LiteLLM (same as the CLI). With no model, tools useDummyEmbeddingFunction— no external embedding calls (src/chunktuner/mcp/service.py). - Document content: Ingestion reads files under the validated
pathinsideCHUNK_TUNER_BASE_DIR. The MCP server does not send document text to a chunktuner-operated cloud; stdout is reserved for the MCP JSON-RPC stream (src/chunktuner/mcp/server.py). - Logging: Tool timing is logged at INFO to stderr in
chunktuner.mcp.tools(no document body in those messages). - SQLite cache: When a real
embedding_modelis used,evaluate_chunking/recommend_configcache embedding vectors in~/.cache/chunktuner/chunktuner_cache.sqlite. Passuse_cache: falseto turn this off. Dummy embeddings are never cached. LLM-generated datasets (generate_dataset: true) are stored as JSON under~/.cache/chunktuner/datasets/. Usechunk-tune cache stats|clearto inspect or clear the embedding cache. See also FAQ — caching.
Local dev (editable)¶
Optional HTTP API¶
The FastAPI app under chunktuner.api is separate from MCP. Start it with:
Use this when you want REST clients; MCP hosts talk to chunk-tune-mcp only.
Tools¶
| Tool | Purpose |
|---|---|
list_strategies |
Strategies + param schemas |
preview_chunks |
Chunk inline text (no embeddings). Optional content_type (default markdown) |
evaluate_chunking |
Cost dry-run or full eval (dummy embeddings unless you pass a model + keys) |
recommend_config |
Full tuner + ranking |
Optional fields on evaluate_chunking and recommend_config¶
| Field | Default | Description |
|---|---|---|
content_type |
none | evaluate_chunking keeps only documents of this type and the strategies that support it. recommend_config uses it to select strategies |
top_k |
5 |
No effect on metrics. Retrieval depth is the effective k = 2000-token context budget / avg chunk tokens |
dataset_path |
none | JSON/YAML eval dataset file. It must resolve under CHUNK_TUNER_BASE_DIR or the call is rejected. document_id may be the file path relative to path, an absolute path, or the file name |
generate_dataset |
false |
Generate questions with CHUNKTUNER_LLM_MODEL. MCP has no confirmation prompt, so call evaluate_chunking with dry_run: true, generate_dataset: true first and check llm_dataset_tokens / llm_cost_usd. The result is cached and reused. Mutually exclusive with dataset_path |
retrieval_scope |
document |
document or corpus: which ranking feeds the score's rank metrics |
retrieval_mode |
dense |
First-stage retrieval: dense (embedding similarity), bm25 (lexical BM25, no embedding calls) or hybrid (dense + BM25 fused with reciprocal rank fusion). bm25 and hybrid need the bm25 extra |
reranker |
none | Optional second-stage reranker spec: dummy (no cost), local or local:<hf-model-id> (local cross-encoder; needs the late extra, downloads the model), or any other string as a LiteLLM rerank model (e.g. cohere/rerank-v3.5; uses the provider's env vars and may cost money). MCP has no confirmation prompt, and the evaluate_chunking dry run does not count rerank calls. Invalid values are rejected, also on dry runs |
use_cache |
true |
SQLite embedding cache for real embedding models |
Responses (other than dry runs) include a warnings list. With neither dataset_path nor generate_dataset, a placeholder dataset is used (one query per document, whose answer is the first 200 characters), and warnings says so. Documents whose content type a selected strategy does not support are skipped and reported in warnings (also on evaluate_chunking dry runs); if none remain, the tool returns an error naming strategies that support them. evaluate_chunking also reports dataset_summary.source (trivial, user_provided or llm_generated).
Resources & prompts¶
- Resources:
doc://overview,doc://strategy_guidelines,doc://metrics_guide - Prompts:
explain_chunking_results,design_eval_questions