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.

发布方自己的服务:model.tools — Zero-Auth Agent Utilities

已验证STDIO仅桌面开发者工具AI 与机器学习

概览

AI 生成的概览

一个本地 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 的网络。
安装前请注意
所选文件内容和问题,或规格说明与参考文件,会发送给配置的 worker provider,可能是远程服务。code_write 可创建目录并覆盖已有目标文件。除非扩展 SHUNT_ALLOWED_ROOTS,文件访问仅限工作目录。API 密钥应放在环境变量中,而不是 config.json(后者还接受 api_key 备用字段)。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Model Shunt,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

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). No pip install, no virtual environment, and no npm required.
  • 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).
  • Bypasses Linux ARG_MAX Limits: Unlike naive implementations that pass file contents as CLI arguments (capped at ~128 KB on Linux), Model-Shunt streams corpus data over stdin, 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_read payload 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 absolute N| 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

model-shunt/├── src/model_shunt/│   ├── worker.py              # Universal LLM worker engine with model discovery (zero-deps)│   └── server.py              # Stdio MCP server exposing routing tools├── bin/model-shunt.js         # npm/npx launcher shim (requires local Python 3)├── plugin/│   ├── .claude-plugin/        # Plugin manifest for hook-compatible agents│   ├── hooks/                 # PreToolUse interceptor hooks (check-file-size, check-bash-read)│   ├── scripts/               # Executable streaming CLIs (bulk-read, code-write)│   └── skills/                # Agent skill manifests (/bulk-reader, /code-writer)├── pyproject.toml             # PyPI packaging (uvx / pip install)├── package.json               # npm packaging (npx)├── config.example.json        # Configuration template├── test_shunt.py              # Automated test suite└── .gitignore                 # Credential and cache protection

⚙️ 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

json
{  "provider": "gemini",  "model": "auto",  "timeout": 90,  "max_tokens": 8192}

Tip: Setting "model": "auto" (or passing --auto-model in 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, or SHUNT_API_KEY). An api_key field exists as a last-resort fallback, but keeping secrets out of files is strongly recommended.

Using Environment Variables

bash
# Google Gemini (Recommended: 1M token context, high speed, ultra-low cost)export SHUNT_PROVIDER="gemini"export GEMINI_API_KEY="your-api-key"
# Groq (Ultra-low latency inference)export SHUNT_PROVIDER="groq"export GROQ_API_KEY="your-api-key"
# Ollama (100% private, local, and free)export SHUNT_PROVIDER="ollama"export SHUNT_BASE_URL="http://localhost:11434/v1"
# OpenAI / DeepSeek / OpenRouter / Anthropicexport SHUNT_PROVIDER="deepseek"export DEEPSEEK_API_KEY="your-api-key"

🛠️ Usage Modes

Mode 1: Universal MCP Server (Recommended)

Model-Shunt provides a standard stdio MCP server exposing three tools:

  1. 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.
  2. bulk_read(question, file_paths, model?, provider?): Reads large or multiple files and outputs concise, structured bullets with exact line citations. A citation name (N|k) is dropped when source line k does not contain that name.
  3. code_write(spec, reference_path, target_path?, model?, provider?): Generates code using a specification and reference file. Returns the code when target_path is 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):

bash
curl -fsSL https://yasmanycastillo.github.io/model-shunt/install.sh | bash

Manual alternatives:

bash
claude mcp add model-shunt -- uvx model-shunt      # if you have uvclaude mcp add model-shunt -- npx -y model-shunt   # if you have Node + Python

Any MCP client (Cursor, Windsurf, Antigravity, Claude Desktop, etc.) — add to its MCP settings. No clone, no absolute paths:

json
{  "mcpServers": {    "model-shunt": {      "command": "uvx",      "args": ["model-shunt"],      "env": {        "SHUNT_PROVIDER": "gemini",        "SHUNT_MODEL": "auto",        "GEMINI_API_KEY": "your-api-key"      }    }  }}

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_write only operate on files inside the server's working directory (the agent workspace). Set SHUNT_ALLOWED_ROOTS (PATH-style list) to expand the sandbox.

Map-Reduce Tuning (optional)

VariableDefaultPurpose
SHUNT_MAX_DIRECT_TOKENS200000Payloads above this estimated size switch to map-reduce
SHUNT_CHUNK_CHARS600000Chunk size in characters (~150k tokens)
SHUNT_CHUNK_RETRIES3Retries per chunk on rate limits
SHUNT_CHUNK_RETRY_DELAY60Seconds to wait out a provider quota window (free-tier TPM)

Mode 2: PreToolUse Interceptor Hooks

For agents supporting pre-execution hooks (e.g., Claude Code, custom agent loops):

  1. 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 to bulk-read.
    • Targeted reads with offset and limit are allowed, preserving surgical context for code editing.
  2. Terminal Guard (check-bash-read):
    • Prevents agents from bypassing the read hook by executing commands like cat, less, or more on large files directly in the terminal context.

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
bash
python3 src/model_shunt/worker.py --list-models --provider gemini
Run Bulk Reading Analysis
bash
./plugin/scripts/bulk-read \  --question "How does the token refresh cycle work?" \  --paths src/auth.py src/tokens.py \  --auto-model
Generate Boilerplate Directly to Disk
bash
./plugin/scripts/code-write \  --spec "Create unit tests for the BillingService covering charge and refund" \  --reference tests/test_user.py \  --target tests/test_billing.py \  --auto-model

🧪 Verification

Run the built-in test suite to verify your environment:

bash
python3 test_shunt.py

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
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v1.2.1最新Sep 24, 2026
  2. v1.1.1Sep 23, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

其他 Model 集成