claude-token-saver-mcp
Enables offloading code generation, text summarization, and other boilerplate tasks to local LLMs via Ollama, reducing API costs.
Exposes server metrics (e.g., request counts, token usage) in Prometheus format for monitoring and observability.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@claude-token-saver-mcp Write a function to shuffle an array in TypeScript"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
English | 日本語
claude-token-saver-mcp
Beta — 個人利用向け。736 テスト / カバレッジ 97%。
Claude Code の「それ、ローカルでよくない?」を自動化する MCP サーバー。
ボイラープレート生成、テスト作成、テキスト要約 — Cloud API に投げるまでもない定型タスクを、手元の Ollama でさばきます。セキュリティ対策込み。
モチベーション
Claude Code の API 利用を分析してみたら、リクエストの約 40% は定型的なコード生成やテキスト処理でした。この手のタスクは 7B クラスのローカルモデルでも実用的な品質が出ます。「推論は Cloud、作業は Local」— この振り分けを MCP で自動化したのがこのツールです。
Related MCP server: claude-delegate-local-mcp
ローカル LLM はどこまで来たか
ローカル LLM の進化は速いです。2024 年の Llama 3 から 2025 年の Qwen3 まで、わずか 1 年でコード生成ベンチマーク (HumanEval) のスコアは 60% → 85% に跳ね上がりました。
この調子なら、Agent ワークフローにローカル LLM が当たり前に組み込まれる日もそう遠くないでしょう。claude-token-saver-mcp は Cloud と Local を使い分けるための土台を提供します。
しくみ
MCP (Model Context Protocol) は Claude Code が外部ツールを呼び出すための標準プロトコルです。このサーバーを登録すると、Claude Code がタスクの内容を見て、定型的な処理を自動的にローカル LLM へ回します。
Claude Code ──MCP──▶ token-saver ──HTTP──▶ Ollama (ローカル)
│ │
│ 「定型タスクだ → ローカルに振ろう」 │
│ │
└─── 高度な推論・設計判断は Cloud で継続 ───┘Ollama が落ちていたり応答が遅い場合は Cloud API にフォールバック可能です。
30 秒セットアップ
前提: Node.js 20+ と Ollama がインストール済みであること。
0. Ollama を起動
ollama serve1. プロジェクトルートに .mcp.json を作成
{
"mcpServers": {
"token-saver": { "command": "npx", "args": ["-y", "claude-token-saver-mcp"] }
}
}2. Claude Code を起動して、こう頼む
コーディング用にローカルLLMをセットアップしてRAM に応じた最適モデルが推奨 → ダウンロード(約 4GB)→ プリロードまで自動で走ります。
3. 動作確認
TypeScript で配列をシャッフルする関数を書いて「ローカルLLM(qwen2.5-coder:…)で生成しました」のようにローカルモデル名が表示されれば OK。
出ない場合は ollama list でモデルを確認し、トラブルシューティング を参照してください。
git clone https://github.com/BlackFoil/claude-token-saver-mcp.git
cd claude-token-saver-mcp
npm ci && npm run buildプロジェクトルートの .mcp.json に追加:
{
"mcpServers": {
"token-saver": {
"command": "node",
"args": ["/path/to/claude-token-saver-mcp/dist/server.js"]
}
}
}特徴
ローカル完結 — 定型タスクは Cloud API を使わずに処理できる
自動モデル選択 — RAM を検出して最適なモデルを推奨・DL・プリロード(
auto_setup)セキュリティ内蔵 — プロンプトインジェクション検知 + 出力サニタイズ
コスト可視化 — 節約額をリアルタイムで追跡(定型タスク比率 40% なら月 $50〜80 程度の削減が目安)
Cloud フォールバック — Ollama が落ちても Cloud に自動切り替え可能
使用例
あなた: 「ソート関数を書いて」 → offload_work がローカルで生成 💰 $0.02 節約
あなた: 「このログを要約して」 → compress_context がローカルで圧縮 💰 $0.05 節約
あなた: 「コスト節約を見せて」 → cost_dashboard: 累計 $47.89 節約
あなた: 「3つのAPIを一括実装して」 → batch_offload: 3 タスクを順次処理ローカル品質の実際
ローカル 7B モデルの出力は Claude に及びません。それは前提です。ただ、定型タスクに限れば十分実用的です。
タスク | ローカル品質 | 向き不向き |
ボイラープレート生成 | ★★★★☆ | ✅ 得意 |
ユニットテスト作成 | ★★★★☆ | ✅ 得意 |
テキスト要約 | ★★★★☆ | ✅ 得意 |
単純なリファクタリング | ★★★☆☆ | ✅ 実用的 |
アーキテクチャ設計 | ★★☆☆☆ | ❌ Cloud に任せるべき |
複雑なデバッグ | ★★☆☆☆ | ❌ Cloud に任せるべき |
Claude Code がタスクの複雑さを判断して自動で振り分けます。ローカルの品質が足りなければ Cloud で処理されます。
自動ティアリング
RAM | Tier | モデル | DL サイズ |
< 16 GB | Light | phi4:latest | ~2.5 GB |
16–48 GB | Standard | qwen2.5-coder:7b | ~4.7 GB |
> 48 GB | Ultra | qwen2.5-coder:32b | ~18 GB |
ツール一覧
ツール | 説明 |
| コード生成・リファクタリングをローカルで実行 |
| 長大なテキストをローカルで要約 |
| 最適モデルの推奨 → DL → プリロードをワンステップで |
| 複数タスクを一括投入(順次 / 並列) |
| 累計節約額・モデル使用統計 |
ツール | 説明 |
| サーバーメトリクス(JSON / Prometheus) |
| タスクカテゴリ別の最適モデル推奨 |
| Ollama モデルのダウンロード |
| VRAM へのプリロード |
| ロード中モデルの一覧 |
| モデルセレクターのランタイム設定 |
セキュリティ
ローカル LLM への入出力を自動で保護します。
プロンプトインジェクション検知 — 5 カテゴリ・20 パターンで悪意ある入力をブロック
出力サニタイズ — API キー・パスワード・JWT など 11 パターンを
[REDACTED]に置換データプライバシー — 全処理がローカル完結。外部への送信なし
ドキュメント
5 分で始める | |
具体的な活用例 | |
全設定項目 | |
よくある質問 | |
エラー対応 |
アーキテクチャ
src/
├── server.ts # MCP エントリポイント(11 ツール登録)
├── tools/ # offload_work, compress_context, auto_setup, batch_offload 等
├── ollama/ # Ollama クライアント & マルチノードロードバランサー
├── queue/ # FIFO キュー & 優先度キュー(URGENT/HIGH/NORMAL/LOW)
├── model-selector/ # モデル推奨エンジン, ベンチマーク DB, 実行トラッカー
├── validators/ # 入力バリデーション & プロンプトインジェクション検知
├── cost/ # コスト計算 & レポーター
├── metrics/ # Prometheus メトリクス収集
├── persistence/ # ExecutionTracker / BenchmarkStore のファイル永続化
├── config/ # Zod 設定スキーマ & ローダー
├── tiering/ # RAM ベースの自動ティアリング
├── logging/ # 構造化ログヘルパー
└── errors.ts # CTS-XXXX エラー体系開発
npm ci
npm test # 736 テスト(カバレッジ 97%)
npm run typecheck # 型チェック
npm run lint # ESLint
npm run build # プロダクションビルド対応プラットフォーム: macOS / Linux / Windows(Ollama が動く環境)
コントリビューション歓迎です → CONTRIBUTING.md
ライセンス
Available Tools
11 toolsauto_setupA
Automate the full model setup flow: recommend the best model for a task category, download it if needed, and preload it into VRAM — all in one step.
Inputs: category, skip_pull, skip_preload, prefer_quality.
batch_offloadA
Submit multiple coding tasks as a batch to the local LLM. Tasks are processed sequentially or in parallel. Supports partial failure.
Inputs: tasks (required), sequential.
compress_contextA
Compress/summarize large text content using a local LLM to reduce cloud token usage. Use for summarizing logs, large files, or verbose context before sending to Claude.
Inputs: content (required), focus, model, max_length.
configure_model_selectorB
View or modify model selector settings at runtime. Manage blocked models, license filters, and custom model recommendations.
Inputs: action (required), setting (required), values, custom_config.
cost_dashboardA
View cumulative cost savings and model usage statistics.
Inputs: no named parameters.
get_metricsB
Get server metrics in Prometheus text format or JSON. Includes request counts, latency, queue stats, cost savings, and health status.
Inputs: format.
list_loaded_modelsA
List all models currently loaded in VRAM with usage details. Shows VRAM usage, expiry time, and available slots.
Inputs: no named parameters.
offload_workA
Offload coding/text tasks to a local LLM (Ollama) to save Claude API tokens. Use for code generation, refactoring, formatting, boilerplate, and other routine tasks.
Inputs: task (required), model, context, category, +2 more.
preload_modelA
Preload a model into VRAM for warm inference. Sends an empty chat request with keep_alive to keep the model loaded during the session.
Inputs: model (required), keep_alive.
pull_modelA
Download a model from the Ollama registry to local storage. Use this to install recommended models before preloading them into VRAM.
Inputs: model (required).
recommend_modelA
Recommend the best local LLM model for a given task category based on system specs and installed models. Returns prioritized list with installation status and license info.
Inputs: category (required), prefer_quality.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Each tool has a clearly distinct purpose: metrics, model listing, downloading, task offloading (single and batch), context compression, cost dashboard, model recommendation, VRAM preloading, configuration, and automated setup. No two tools overlap in functionality.
All tools follow the verb_noun snake_case pattern without exception. Names like 'get_metrics', 'offload_work', 'batch_offload', and 'auto_setup' are predictable and consistent.
11 tools is appropriate for a server focused on saving tokens via local LLMs. Each tool addresses a specific aspect (model management, task offloading, monitoring, configuration) without being excessive or insufficient.
The tool set covers the full workflow: model installation, recommendation, preloading, offloading, context compression, and monitoring. Minor gaps exist: there is no tool to unload models from VRAM or delete models, but these are not critical for the primary use case.
Maintenance
Related MCP Connectors
No-data MCP handoff for local Claude Code to Codex harness moves. $49 lifetime.
Work on your own computers from Claude or ChatGPT: run commands, edit and search files.
AI code governance and code review for Claude Code, Copilot and Cursor. Checks rules and security.
Persistent memory for Claude Code and Cursor. Stop re-explaining your project every session.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Claude to delegate coding tasks to local Ollama models, reducing API token usage by up to 98.75% while leveraging local compute resources. Supports code generation, review, refactoring, and file analysis with Claude providing oversight and quality assurance.27AGPL 3.0
- AlicenseNot gradedqualityBmaintenanceEnables Claude Code to hand off bulk, mechanical, read-heavy tasks to a local model, including agentic loops that can read, write, and run commands sandboxed at zero cloud token cost.MIT
- AlicenseAqualityBmaintenanceEnables Claude Code to delegate agent tasks to local LLMs via llama.cpp or vLLM servers on your own hardware, reducing API usage while maintaining full agent capabilities.1122MIT
- AlicenseAqualityBmaintenanceEnables Claude Code to offload bulk reading and first drafts to a local Ollama model on your GPU, and to draft weekly devlogs from merged pull requests.3MIT