
Model Shunt
io.github.yasmanycastillo由 GitHub 帳號 yasmanycastillo 發布v1.2.1更新於 Oct 24, 2026
Model routing for AI agents: delegate bulk reads & boilerplate to cheap worker models.
概覽
一個本機 MCP 伺服器,把程式代理中耗 token 的檔案讀取與樣板程式碼產生轉交給更便宜或本機的 worker 模型。
- 可以做什麼
- 查詢可用的 worker 模型,並依 provider 給出讀取與寫入模型建議,探索失敗或不支援時回傳內建建議(get_available_models)。讀取大型或多個檔案,輸出附精確行號引用的精簡結構化重點,超大語料自動分塊彙整(bulk_read)。依規格說明與參考檔案產生程式碼,可直接回傳或寫入目標路徑並覆寫既有檔案(code_write)。
- 適用情境
- 當程式代理把上下文耗在批次讀取檔案或重複樣板程式碼(測試、mock、樁、設定)上時使用,把這類工作交給快速、便宜或本機的模型,讓主要上下文保持乾淨。
- 執行需求
- 以 Python 3 套件(uvx 或 pip)透過 stdio 在本機執行,或透過需要本機 Python 3 的 npm 啟動器執行。需以環境變數設定 worker provider,例如 SHUNT_PROVIDER 加上對應金鑰(GEMINI_API_KEY、GROQ_API_KEY、DEEPSEEK_API_KEY 或 SHUNT_API_KEY),或以 SHUNT_BASE_URL 指向 Ollama 等本機端點。除本機端點外需要連線至 provider 的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Model Shunt,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Model-Shunt 🔀
[CI Test Suite] [License: MIT] [Python 3.9+] [Dependencies: 0] [Website Live] [M8ven Score]
A decoupled, zero-dependency, universal implementation of the Shunt model-routing pattern (originally conceived by Spotify Engineering).
Model-Shunt allows AI coding agents (Antigravity, Cursor, Windsurf, Claude Code, Aider, OpenHands, etc.) to delegate token-heavy I/O (bulk file reading/code analysis) and repetitive boilerplate generation (tests, mocks, stubs, configs) to fast, economical, or local worker models (Gemini 2.5 Flash, Groq/Llama, Ollama, DeepSeek, GPT-4o-mini). This cuts primary agent token consumption by up to 90% while keeping the main context window clean.
⚡ Key Highlights
- Zero External Dependencies: Built with pure Python 3 standard library (
urllib,json,re,argparse). Nopip install, no virtual environment, and nonpmrequired. - Agent-Agnostic: Works transparently across any AI coding agent via standard MCP (Model Context Protocol), standalone CLI scripts, or PreToolUse lifecycle hooks.
- Dynamic Model Discovery & Auto-Routing: Queries the worker endpoint in real time to discover available models and automatically routes to the best model for the task:
- Reader Mode (Bulk I/O): Prioritizes massive context windows and ultra-low cost (e.g.,
gemini-2.5-flash,llama-3.3-70b-versatile,gpt-4o-mini). - Writer Mode (Code Generation): Prioritizes specialized coding models (e.g.,
qwen2.5-coder:latest,gemini-2.5-flash,deepseek-chat).
- Reader Mode (Bulk I/O): Prioritizes massive context windows and ultra-low cost (e.g.,
- Bypasses Linux
ARG_MAXLimits: Unlike naive implementations that pass file contents as CLI arguments (capped at ~128 KB on Linux), Model-Shunt streams corpus data overstdin, allowing analysis of hundreds of thousands of lines without buffer overflows. - Deterministic Line Numbering (
N|): Automatically prefixes every line in file blocks with its 1-based index, forcing worker models to cite verifiable, exact line numbers instead of hallucinating locations. - Binary File Protection: Inspects byte headers to reject binary files (PDFs, images, compiled objects) before sending them to the LLM.
- Network Resilience: Automatic exponential backoff retries for rate limits (HTTP 429) and transient server errors (HTTP 503/502), with configurable timeouts and token limits.
- Map-Reduce for Oversized Corpora: When a
bulk_readpayload exceeds the direct limit (SHUNT_MAX_DIRECT_TOKENS, default ~200k tokens), Model-Shunt automatically splits the corpus into chunks, maps the question over each chunk (preserving absoluteN|line numbers), and reduces the extracts into one cited answer. Giant single-line files (minified JSON/JS) are sliced by characters with explicit position markers. Rate-limit pacing waits out provider quota windows instead of failing.
📁 Repository Structure
⚙️ Configuration
Configure your worker model via environment variables or a config.json file (placed in ~/.config/model-shunt/config.json or in the project root):
Using config.json
Tip: Setting
"model": "auto"(or passing--auto-modelin the CLI) will automatically inspect the provider's active models and pick the optimal one for reading vs writing.
Security: Do not put your API key in
config.json— use environment variables instead (e.g.GEMINI_API_KEY,GROQ_API_KEY, orSHUNT_API_KEY). Anapi_keyfield exists as a last-resort fallback, but keeping secrets out of files is strongly recommended.
Using Environment Variables
🛠️ Usage Modes
Mode 1: Universal MCP Server (Recommended)
Model-Shunt provides a standard stdio MCP server exposing three tools:
get_available_models(provider?): Queries the provider endpoint and recommends reader and writer models. If discovery fails or is unsupported, returns built-in recommendations whose current availability is not verified.bulk_read(question, file_paths, model?, provider?): Reads large or multiple files and outputs concise, structured bullets with exact line citations. A citationname (N|k)is dropped when source linekdoes not contain that name.code_write(spec, reference_path, target_path?, model?, provider?): Generates code using a specification and reference file. Returns the code whentarget_pathis omitted; otherwise creates missing parent directories and writes the code, overwriting an existing target file.
bulk_read sends the selected files and question to the configured worker provider; code_write sends the specification and reference file. The provider can be remote or local (such as Ollama). Token savings depend on the input and response.
The MCP server runs locally over stdio. Set provider credentials through environment variables. File access follows resolved paths, so symlinks pointing outside the allowed workspace roots are rejected. Invalid requests return structured errors and leave the server available for subsequent calls.
Installation
MCP Registry name: mcp-name: io.github.yasmanycastillo/model-shunt
Universal one-liner (detects uv / pip / pipx / npm, installs the model-shunt command, and registers it with Claude Code if present):
Manual alternatives:
Any MCP client (Cursor, Windsurf, Antigravity, Claude Desktop, etc.) — add to its MCP settings. No clone, no absolute paths:
Fallback (offline / no uv / no npx): run straight from a clone with Python 3.9+ — replace
"command"/"args"with"command": "python3", "args": ["/absolute/path/to/model-shunt/src/model_shunt/server.py"].
Security: by default
bulk_read/code_writeonly operate on files inside the server's working directory (the agent workspace). SetSHUNT_ALLOWED_ROOTS(PATH-style list) to expand the sandbox.
Map-Reduce Tuning (optional)
Mode 2: PreToolUse Interceptor Hooks
For agents supporting pre-execution hooks (e.g., Claude Code, custom agent loops):
- File Read Interceptor (
check-file-size):- If the agent attempts a whole-file read on a file exceeding the threshold (default: 350 lines, configurable via
SHUNT_MIN_LINES), the hook blocks the call and instructs the agent to delegate tobulk-read. - Targeted reads with
offsetandlimitare allowed, preserving surgical context for code editing.
- If the agent attempts a whole-file read on a file exceeding the threshold (default: 350 lines, configurable via
- Terminal Guard (
check-bash-read):- Prevents agents from bypassing the read hook by executing commands like
cat,less, ormoreon large files directly in the terminal context.
- Prevents agents from bypassing the read hook by executing commands like
Mode 3: Standalone CLI & Scripts
You can also use Model-Shunt directly from the command line or from agent bash sessions:
Discover Available Models & Recommendations
Run Bulk Reading Analysis
Generate Boilerplate Directly to Disk
🧪 Verification
Run the built-in test suite to verify your environment:
The test suite validates:
- Configuration resolution, fallback cascades, and model selection.
- Binary file detection and rejection.
- Hook decisions (surgical reads allowed, large file reads blocked, bash flag parsing).
- MCP stdio protocol compliance and tool execution.
- CLI discovery flags.
📄 License
MIT. Inspired by Spotify Engineering's Shunt architecture.
🔒 Privacy
See PRIVACY.md for filesystem scope, provider data handling, and credential practices.
來源:README.md,提交 8cf822d
工具
0版本歷史
2- v1.2.1最新Sep 24, 2026
- v1.1.1Sep 23, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
其他 Model 整合

model.tools — Zero-Auth Agent Utilities
tools.model官方發布者
零認證遠端工具伺服器,讓代理程式讀取一次性信箱驗證碼、保存檢查點、接收 Webhook、排定喚醒、取得任務回執,並把網頁轉成 Markdown。
NLP.COM.AI Open Model Catalog
ai.com.nlp官方發布者
搜尋精選的開放權重AI模型發布、授權條款、架構和原始來源。AI 翻譯

Hologram Model Hub
foundation.uor.hub官方發布者
一個遠端 MCP 伺服器,讓助理搜尋開放模型索引,並取得附有 SHA-256 校驗值的下載連結。

ModelLens
由 GitHub 帳號 Greatbeing 發布
探測相容於 OpenAI 的模型閘道,依實測延遲與成功率為模型排名,並推薦該用哪個模型。

Bedrock Multi-Model
由 GitHub 帳號 Sagargupta16 發布
本機 MCP 伺服器,把 AWS Bedrock 的文字、影像、影片與嵌入模型包裝成九個工具,讓助理可以提問、比較與評審模型。