Local Ollama-backed MCP server — 44 tools, smart buffer, execution filters, persistent scratchpad
Project description
localthink-mcp
Local LLM context compression for Claude Code. Offloads large file queries and document processing to Ollama so they never burn Claude's context window.
v0.1.0 benchmarked at ~30× token savings on 16 KB file queries. v1.1 adds 13 new tools covering every major token-waste pattern. v1.2 adds pre-injection:
local_improve_promptandlocal_preplanrun locally before Claude sees the task — sharpening prompts and scaffolding plans so Claude executes rather than guesses. v2.1 adds smart buffer, execution filters, session scratchpad, persistent notes, response refinement, and a disk-backed result cache — 14 new tools, 44 total.
Quick start
# 1. Pull a model (once)
ollama pull qwen2.5:14b-instruct-q4_K_M
# 2. Register with Claude Code
claude mcp add localthink -- uvx localthink-mcp
# 3. Verify
claude mcp list # localthink → Connected
Requirements
- Ollama installed and running (
ollama serve) - Claude Code CLI
- Python 3.10+
All 44 tools
v0.1.0 — Core compression
| Tool | When to use |
|---|---|
local_answer(file_path, question) |
Query a large file without loading it into context |
local_summarize(text, focus?) |
Compress a large text blob already in context |
local_extract(text, query) |
Pull only the cited passages you need from a document |
v1.1 — New routes
File operations
| Tool | What it does |
|---|---|
local_shrink_file(file_path, focus?) |
Read a file → return compressed content (not an answer). Hold the compressed version in context for repeated reference. |
local_batch_answer(file_paths, question) |
Answer one question across many files in a single call. No files enter Claude's context. |
local_scan_dir(dir_path, pattern, question?, max_files?) |
Walk a directory, summarize or query every matching file. Glob pattern support (**/*.ts, config/*.yaml). |
Composition (fewer round-trips)
| Tool | What it does |
|---|---|
local_pipeline(text, steps) |
Chain summarize → extract → answer in one call. Up to 5 steps. Eliminates back-and-forth for predictable multi-stage workflows. |
local_auto(input, question?) |
Meta-tool: detects file path vs text, picks the right op, handles large docs with auto extract-then-answer. Zero decision overhead. |
Stateful document chat
| Tool | What it does |
|---|---|
local_chat(document, message, history?) |
Multi-turn Q&A. Document is compressed on first call and stays with Ollama. Claude holds only conversation history — the original doc never enters Claude's window. |
Semantic & structural
| Tool | What it does |
|---|---|
local_grep_semantic(file_path, meaning, max_results?) |
Find passages matching a concept, not a literal string. "Find where rate limiting is enforced" works even if the word "rate" isn't there. |
local_outline(text) |
Structural table of contents with line ranges — no content returned. Use before local_extract to find the right section. |
local_code_surface(file_path) |
Public API skeleton. Python: pure AST (no Ollama, instant). Other languages: fast LLM. Typically 5-10% of original size. |
Analysis / meta
| Tool | What it does |
|---|---|
local_classify(text) |
Classify content type + recommend the best tool. Returns JSON. Use for programmatic routing in hooks/scripts. |
local_audit(file_path, checklist) |
Checklist-based file audit: PASS / FAIL / PARTIAL / N/A per item. File never enters Claude's context. |
local_models() |
List local Ollama models and show current DEFAULT / FAST model config. |
v1.2 — Pre-injection (run before Claude thinks)
These tools run a local model pass before Claude engages with a task. Claude never sees the raw input — only the pre-processed output. Eliminates waste at the source rather than compressing after the fact.
| Tool | What it does |
|---|---|
local_improve_prompt(prompt, context?) |
Rewrite a vague or rough prompt into a clear, specific, unambiguous version. Claude receives only the sharpened result. Uses the fast model — minimal overhead. |
local_preplan(task, context?, depth?) |
Generate a structured implementation plan (goal / assumptions / ordered steps / risks / open questions) via local model. Claude executes the scaffold rather than planning from scratch. depth: "quick" (3-5 steps), "standard" (default), "detailed" (sub-bullets + rationale). |
local_improve_prompt example:
"make the auth faster"
→ local_improve_prompt(prompt, context="Next.js, JWT, DB bottleneck suspected")
→ "Optimise JWT validation latency in src/auth/middleware.ts — profile the verify()
hot path, remove redundant DB round-trips, target p95 < 5 ms."
→ Feed that to Claude as the actual task
local_preplan example:
plan = local_preplan(
task="add rate limiting to the API",
context="Express.js, Redis available, routes in src/routes/",
depth="standard"
)
# Returns: Goal / Assumptions / Steps with file paths / Risks / Open questions
# Then: "Execute this plan: <plan>"
v1.1 expansion — high-context compression + smart reading
High-context compression
| Tool | What it does |
|---|---|
local_compress_log(file_path, level?, since?) |
Compress a log file to its essential signal. Groups repeated errors with counts, extracts key events, surfaces anomalies. Optional level (ERROR/WARN) and timestamp-prefix filters. Turns 5 MB logs into ~500-token summaries. |
local_compress_stack_trace(text) |
Distil a stack trace (+ source context) to: root cause, failure point, 3-5 key frames, fix hint. Eliminates framework boilerplate that inflates traces to thousands of tokens. |
local_compress_data(data, keep_fields?, question?) |
Compress JSON objects, CSV exports, and API responses. Strips nulls, samples large arrays, keeps IDs/status codes. REST responses commonly shrink 20:1. |
local_session_compress(file_path) |
Recursive meta-tool. Compress a saved Claude conversation transcript to a re-entry briefing: context, decisions, current state, open items, constraints. The transcript never enters Claude's context. |
local_prompt_compress(text) |
Compress a long CLAUDE.md or system prompt to its minimal directive set. Preserves every unique rule; removes duplicates and verbose prose. |
Smart reading (avoid loading files at all)
| Tool | What it does |
|---|---|
local_symbols(file_path) |
Full symbol table: every definition with type, line number, and one-line description. Replaces "read file to see what's in it." |
local_find_impl(file_path, spec) |
Natural-language code search inside a file. Returns the complete matching logical unit with line numbers. E.g. spec="where JWT token is verified". |
local_strip_to_skeleton(file_path) |
All function bodies → ..., everything else preserved (docstrings, decorators, type annotations, comments). Typically 30-50% of original. |
Format transformation
| Tool | What it does |
|---|---|
local_translate(text, target_format) |
Convert formats without loading source into context: json↔yaml↔toml, csv→markdown_table, code→pseudocode, sql→english, env→json. |
local_schema_infer(data) |
Sample data → compact JSON Schema (draft-07). API samples are often 100:1 data-to-schema ratio. |
Temporal & multi-file diff
| Tool | What it does |
|---|---|
local_timeline(text) |
Chronological event sequence from logs, changelogs, git log, or incident reports. Deduplicates repeated events. |
local_diff_files(path_a, path_b, focus?) |
Diff two files by path — neither file loaded into context. Counterpart to local_diff which takes in-context text. |
v2.1 — Smart buffer, execution filters, scratchpad, notes, cache
Smart Buffer (raw output triage)
| Tool | What it does |
|---|---|
local_gate(raw_output) |
Triage any raw output (test results, build logs, lint dumps) into Pattern + Anomalies + Signal. Always fits in budget. Use before injecting any raw tool output into context. |
local_slice(file_path, offset_lines) |
Read a window of lines from a file at an offset. On-demand raw access when local_gate identifies a region worth inspecting. |
local_diff_semantic(before, after) |
Meaning-level diff — noise (whitespace, formatting, minor rewording) suppressed. Only semantic changes surface. |
Execution Filters (project tools → local LLM)
| Tool | What it does |
|---|---|
local_run_tests() |
Run the project test suite. Returns only {failed, delta, pointer}. Nothing else enters context. |
local_run_lint() |
Run the linter. Violations grouped by rule; passing rules suppressed. |
local_run_build() |
Run the build. Returns root cause + affected symbols only. |
Session Scratchpad (stateful decisions)
| Tool | What it does |
|---|---|
local_memo_write(section, content) |
Write to a named scratchpad section: decisions, assumptions, pitfalls, open_questions. Auto-compacts beyond threshold. |
local_memo_read() |
Read the full scratchpad as a distilled summary. Restore context mid-session without re-reading files. |
local_memo_checkpoint() |
Freeze scratchpad into a RESUME_PROMPT string. Paste after /clear to continue with full context. |
Persistent Notes (cross-session knowledge)
| Tool | What it does |
|---|---|
local_note_write(category, content) |
Write a permanent note to disk (architecture, gotcha, pattern). Survives /clear and new sessions. |
local_note_search(query) |
Full-text search across all persisted notes. Run at session start to surface relevant prior knowledge. |
Response Quality & Cache
| Tool | What it does |
|---|---|
local_refine(prompt, draft, instructions?) |
Post-process an LLM draft through a refinement pass. Optional instructions target tone, brevity, or accuracy. |
local_cache_stats() |
Show cache hit/miss counts, entry count, and total disk usage. |
local_cache_clear() |
Evict all cached results. |
Decision guide
| Situation | Tool |
|---|---|
| File > 5 KB, one specific question | local_answer |
| File > 5 KB, need to reference it multiple times | local_shrink_file |
| Text already in context, want to compress it | local_summarize |
| "Find me the part about X" | local_extract |
| Need to outline a doc before extracting | local_outline → local_extract |
| Want to know what's in a code file | local_symbols |
| Want to understand a code file's structure | local_code_surface |
| Want the full file but bodies stripped | local_strip_to_skeleton |
| "Find the function that does X" | local_find_impl |
| Multi-step process on the same document | local_pipeline |
| Unsure which tool to use | local_auto |
| Multiple questions about the same large doc | local_chat |
| Same question across 5+ files | local_batch_answer |
| Understand what's in a directory | local_scan_dir |
| "Find where X is handled" (concept search) | local_grep_semantic |
| Security or quality checklist | local_audit |
| Unsure of content type before processing | local_classify |
| Large log file | local_compress_log |
| Stack trace + source context | local_compress_stack_trace |
| JSON / CSV / API response payload | local_compress_data |
| Session too long, need to restart | local_session_compress |
| CLAUDE.md grown too large | local_prompt_compress |
| Need JSON as YAML (or any format swap) | local_translate |
| Need a schema for sample data | local_schema_infer |
| Need a timeline from a log or changelog | local_timeline |
| Compare two files without loading them | local_diff_files |
| Compare two in-context text blobs | local_diff |
| Prompt is vague — sharpen before sending to Claude | local_improve_prompt |
| Task is large — plan locally before Claude touches it | local_preplan |
| Raw test/build/lint output about to enter context | local_gate |
local_gate flagged a specific region worth reading |
local_slice |
| Two text blobs — want only the meaningful diff | local_diff_semantic |
| Run tests without dumping output into context | local_run_tests |
| Run lint without dumping output into context | local_run_lint |
| Run build without dumping output into context | local_run_build |
| Want to record a decision or assumption mid-session | local_memo_write |
| Resuming work, need to restore session context | local_memo_read |
About to /clear — want to resume with full context |
local_memo_checkpoint |
| Want to save a pattern or gotcha for future sessions | local_note_write |
| Starting a session — check for relevant prior notes | local_note_search |
| LLM draft needs a quality pass | local_refine |
| Check or clear the result cache | local_cache_stats / local_cache_clear |
local_pipeline examples
# Extract auth sections, then summarize for security review
local_pipeline(text=big_doc, steps=[
{"op": "extract", "query": "authentication and authorization"},
{"op": "summarize", "focus": "security risks and gotchas"},
])
# Answer a question after narrowing to the relevant section
local_pipeline(text=api_docs, steps=[
{"op": "extract", "query": "rate limiting"},
{"op": "answer", "question": "what headers control retry behaviour?"},
])
local_chat example
# Turn 1 — document is compressed automatically
r = local_chat(full_doc, "What does this library do?", "")
# r["doc"] = compressed version (hold this)
# r["history"] = conversation so far (hold this)
# r["answer"] = the answer
# Turn 2 — pass compressed doc + history back
r = local_chat(r["doc"], "How do I configure auth?", r["history"])
# Turn 3
r = local_chat(r["doc"], "Show me the relevant config keys", r["history"])
Configuration
| Env var | Default | Description |
|---|---|---|
OLLAMA_BASE_URL |
http://localhost:11434 |
Ollama endpoint |
OLLAMA_MODEL |
qwen2.5:14b-instruct-q4_K_M |
Model for all quality operations |
OLLAMA_FAST_MODEL |
(same as OLLAMA_MODEL) | Lighter model for classify, outline, code_surface on non-Python |
LOCALTHINK_CACHE_DIR |
OS temp dir | Directory for disk-backed result cache |
CACHE_TTL_DAYS |
7 |
Cache entry time-to-live in days |
Smaller fast model example (qwen2.5:3b for lightweight ops):
{
"mcpServers": {
"localthink": {
"env": {
"OLLAMA_MODEL": "qwen2.5:14b-instruct-q4_K_M",
"OLLAMA_FAST_MODEL": "qwen2.5:3b-instruct"
}
}
}
}
Install options
uvx (recommended — zero setup)
claude mcp add localthink -- uvx localthink-mcp
pip
pip install localthink-mcp
claude mcp add localthink -- localthink-mcp
Windows — if uvx isn't on Claude's PATH
claude mcp add --transport stdio localthink -- cmd /c uvx localthink-mcp
Security
- Local only — runs as a stdio child process, never exposed to the network.
local_answer/local_shrink_file/local_auditread any path your shell can access. Same trust level as Claude's built-inReadtool.- Ollama has no auth by default. Don't expose port
11434to the internet. - No data leaves your machine. All inference is local.
Troubleshooting
[localthink] Ollama is not running
ollama serve
curl http://localhost:11434/api/tags
Slow responses Switch to a smaller model or set a fast model:
OLLAMA_MODEL=qwen2.5:7b-instruct claude
Windows: uvx not found
Install uv, then retry. Or use cmd /c uvx fallback.
License
MIT © 2026 H3xabah
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file localthink_mcp-2.1.0.tar.gz.
File metadata
- Download URL: localthink_mcp-2.1.0.tar.gz
- Upload date:
- Size: 63.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d160ec68f564a620e11bd79479c308fafff98d08e117e390dfbc9c54ff5c0037
|
|
| MD5 |
bbf05146841f6838134031f27371988b
|
|
| BLAKE2b-256 |
e83eeb4d1795afa3c0db16673dc244d784d381685af8d213070b95bf61eb4a00
|
Provenance
The following attestation bundles were made for localthink_mcp-2.1.0.tar.gz:
Publisher:
publish.yml on H3xabah/Localthink-MCP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localthink_mcp-2.1.0.tar.gz -
Subject digest:
d160ec68f564a620e11bd79479c308fafff98d08e117e390dfbc9c54ff5c0037 - Sigstore transparency entry: 1326244527
- Sigstore integration time:
-
Permalink:
H3xabah/Localthink-MCP@5212cb6e8e3cfce5f77994672cc21da300109239 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/H3xabah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5212cb6e8e3cfce5f77994672cc21da300109239 -
Trigger Event:
push
-
Statement type:
File details
Details for the file localthink_mcp-2.1.0-py3-none-any.whl.
File metadata
- Download URL: localthink_mcp-2.1.0-py3-none-any.whl
- Upload date:
- Size: 42.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c76b2d9c9f8fc13282ffa9d2da21c966ab098627a3027e049cc28bfbee0ccb
|
|
| MD5 |
a08adf48b1cae41c64f884cfbb52ceb2
|
|
| BLAKE2b-256 |
9b476b9c7d23624a0f96f6628de5fd08387a3e785a2d799295375b48b9bb7c5e
|
Provenance
The following attestation bundles were made for localthink_mcp-2.1.0-py3-none-any.whl:
Publisher:
publish.yml on H3xabah/Localthink-MCP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localthink_mcp-2.1.0-py3-none-any.whl -
Subject digest:
e7c76b2d9c9f8fc13282ffa9d2da21c966ab098627a3027e049cc28bfbee0ccb - Sigstore transparency entry: 1326244623
- Sigstore integration time:
-
Permalink:
H3xabah/Localthink-MCP@5212cb6e8e3cfce5f77994672cc21da300109239 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/H3xabah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5212cb6e8e3cfce5f77994672cc21da300109239 -
Trigger Event:
push
-
Statement type: