Skip to main content
Glama

本地工作器 MCP

本地MCP,客户端无关。前沿模型规划、委托和审查。本地执行繁重、机械且可验证的工作。

目标是减少付费AI的令牌消耗,而不将原始内容放入其上下文中。

Codex / Claude / Gemini / Grok
              │
              ▼
       Local Worker MCP
              │
       ┌──────┴───────────────┐
       ▼                      ▼
 Gemma 4 12B QAT          arquivos / PDF
 via Ollama               extração + evidências
       │
       ▼
 resultado compacto e verificável
       │
       ▼
 Frontier revisa

这不替代主AI,也不是模型路由器。这是真正的工作委托。

LOCAL DISPONÍVEL?          NÃO
      │                     │
      ▼                     ▼
   DELEGA                NÃO INSISTE
      │                     │
      ▼                     ▼
   COMPRIME            FRONTIER ASSUME
      │
      ▼
 FRONTIER REVISA

Gemma是一种优化。它绝不能成为单点故障。

原则

当任务机械、重复、可验证或上下文密集时委托:PDF、日志、CSV、代码、提取、分类、摘要。

保留在前沿:架构决策、安全、关键变更、主观判断、模糊需求。

如果本地工作器离线,前沿继续运行。MCP快速返回unavailable并推荐回退。客户端可以记录:

Worker local indisponível; executei diretamente.

不需要用户干预。

Related MCP server: ollama-handoff

要求

  • Python 3.10+

  • Ollama 在同一PC或局域网另一台PC上

  • 一个本地模型(推荐:Gemma 4 12B QAT)

安装

git clone https://github.com/CaioAllgayer/Local-Worker-MCP.git
cd Local-Worker-MCP
python -m pip install -e ".[dev]"
copy .env.example .env

Ollama + Gemma

  1. 安装并启动Ollama。

  2. 下载模型。名称不是硬编码的——使用ollama list中的实际名称:

ollama list
ollama pull <nome-real-do-gemma>
  1. 如果LOCAL_LLM_MODEL为空,工作器尝试检测名称包含gemma的模型。否则,使用列表中的第一个模型。

  2. 测试端点:

curl http://127.0.0.1:11434/api/tags
local-worker status
  1. 启动MCP:

local-worker-mcp

同一PC

LOCAL_LLM_PROVIDER=ollama
LOCAL_LLM_BASE_URL=http://127.0.0.1:11434
LOCAL_LLM_MODEL=

local与lan通过主机名检测。127.0.0.1、localhost和::1为本地。

笔记本使用桌面

工作器不假设localhost。后端可以在局域网的另一台PC上。

在笔记本上:

LOCAL_LLM_PROVIDER=ollama
LOCAL_LLM_BASE_URL=http://192.168.x.x:11434

将192.168.x.x替换为桌面的实际IP(Windows上ipconfig,Linux上ip a)。项目中没有固定IP。

行为相同:快速失败、断路器、缓存、压缩。

在桌面上,Ollama需要接受局域网连接(变量OLLAMA_HOST=0.0.0.0,防火墙放行端口11434)。

OpenAI兼容

LM Studio、llama.cpp server、vLLM等:

LOCAL_LLM_PROVIDER=openai_compatible
LOCAL_LLM_BASE_URL=http://127.0.0.1:1234/v1
LOCAL_LLM_MODEL=...
LOCAL_LLM_API_KEY=

快速失败和断路器

默认值:

LOCAL_LLM_CONNECT_TIMEOUT_SECONDS=2
LOCAL_LLM_REQUEST_TIMEOUT_SECONDS=45
LOCAL_LLM_MAX_RETRIES=0
LOCAL_LLM_CIRCUIT_BREAKER_FAILURES=2
LOCAL_LLM_CIRCUIT_BREAKER_COOLDOWN_SECONDS=60

连接被拒绝不进入重试。N次失败后,电路断开,后续调用立即返回unavailable。冷却后,允许一次尝试。

{
  "status": "unavailable",
  "fallback_recommended": true,
  "reason": "Local LLM endpoint unreachable"
}

MCP工具

工具

功能

local_status

提供商、端点、本地/局域网、延迟、模型、断路器、缓存

delegate_task

通用任务 → 紧凑JSON

delegate_batch

并行独立任务(MAX_PARALLEL_WORKERS=4)

delegate_file

TXT、Markdown、CSV、JSON、代码、日志

delegate_pdf

按页提取、分块、层次综合、证据

cache_stats

大小、条目、命中、未命中、命中率、过期

cache_cleanup

立即GC(TTL → 不再使用 → LRU)

cache_clear

删除可丢弃条目

文件的原始内容不需要进入付费AI的上下文。工作器读取、压缩并返回可验证的证据(页、行、片段)。

安全

默认:SECURITY_MODE=READ_ONLY,ENABLE_SHELL=false。

SECURITY_MODE=READ_ONLY
ALLOWED_PATHS=C:\Projects,D:\Research
ENABLE_SHELL=false
  • READ_ONLY — 仅读取授权路径;写入和shell被阻止

  • WORKSPACE_WRITE — 在授权路径上读写;仅当ENABLE_SHELL=true时允许shell

  • FULL_LOCAL — 更宽松;仍阻止破坏性命令

路径遍历被阻止。rm、del、format等被拒绝。

缓存和日志

持久缓存位于~/.local-worker-mcp/cache,自动清理:

CACHE_TTL_DAYS=30
CACHE_MAX_SIZE_GB=10
CACHE_CLEANUP_THRESHOLD_PERCENT=90
CACHE_TARGET_USAGE_PERCENT=80
CACHE_CLEANUP_INTERVAL_HOURS=6

条目默认可丢弃。persistent=true保留重要工件。

日志轮转并过期:

LOG_RETENTION_DAYS=14
LOG_MAX_SIZE_MB=250

日志不保存文件的完整内容。

基准测试

local-worker benchmark arquivo.pdf

输出:

Arquivo: arquivo.pdf
Worker: gemma4:12b-qat
Backend: ollama
Endpoint: LAN/local
Tamanho: ...
Tokens originais estimados: ...
Tokens processados localmente: ...
Resultado para frontier: ...
Compressão: ...
Tempo: ...
Cache: HIT/MISS

Codex

~/.codex/config.toml或客户端的JSON:

{
  "mcpServers": {
    "local-worker": {
      "command": "local-worker-mcp",
      "env": {
        "LOCAL_LLM_PROVIDER": "ollama",
        "LOCAL_LLM_BASE_URL": "http://127.0.0.1:11434",
        "ALLOWED_PATHS": "C:\\Projects"
      }
    }
  }
}

参见examples/codex.json。

Claude Code

claude mcp add local-worker --scope user -- local-worker-mcp

或将examples/claude_code.json粘贴到~/.claude.json。

在项目的CLAUDE.md / AGENTS.md中,教导策略:

机械任务和大文件读取交给delegate_pdf / delegate_file / delegate_task。如果local_status或工具返回unavailable,直接执行并继续。

其他MCP客户端

任何stdio客户端都可以工作。通用示例在examples/generic.json:

{
  "mcpServers": {
    "local-worker": {
      "command": "local-worker-mcp",
      "env": {
        "LOCAL_LLM_PROVIDER": "ollama",
        "LOCAL_LLM_BASE_URL": "http://127.0.0.1:11434"
      }
    }
  }
}

示例

  • examples/pdf.md — 论文/长PDF

  • examples/code.md — 仓库初始读取

  • examples/logs.md — 错误提取

测试

python -m pip install -e ".[dev]"
pytest
ruff check src tests

测试套件不依赖真实的Ollama/Gemma。全部模拟。

此MVP不包括的内容

Windows GUI自动化、Playwright、复杂多智能体、向量RAG、仪表板、Kubernetes、ML路由器。

架构为下一阶段的delegate_repo、delegate_git、delegate_browser等留出空间。

许可证

MIT。

Available Tools

8 tools
cache_cleanupA

Run cache garbage collection now (TTL, unused, then LRU).

Inputs: no named parameters.

cache_clearA

Delete disposable cache entries. Persistent artifacts stay unless include_persistent=true.

Inputs: include_persistent.

cache_statsB

Cache size, entry count, hits, misses, hit rate, and expired entries.

Inputs: no named parameters.

delegate_batchB

Run independent local tasks in parallel. One failure does not cancel the batch.

Inputs: tasks (required).

delegate_fileC

Have the local worker read a file (txt/md/csv/json/code/log) without loading it into frontier context.

Inputs: path (required), objective (required), persistent, output_mode, +1 more.

delegate_pdfC

Extract, chunk, and analyze a PDF locally. Returns compact findings with page evidence.

Inputs: path (required), objective (required), persistent, output_mode, +1 more.

delegate_taskC

Delegate a mechanical task to the local worker. Returns compact structured output.

Inputs: objective (required), context, persistent, force_refresh, +2 more.

local_statusA

Check local worker health: provider, endpoint, model, circuit breaker, cache.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool has a clear, distinct purpose: health check, task delegation, batch processing, file reading, PDF analysis, cache statistics, cleanup, and clearing. There is no overlap in functionality, making it easy for an agent to select the appropriate tool.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern (e.g., local_status, delegate_task, cache_stats). The naming is predictable and clear, with verbs like 'delegate' and 'cache' used consistently to indicate the action and domain.

    Tool Count4/5

    With 8 tools, the count is appropriate for the server's purpose of managing a local worker and its cache. The scope is well-defined without being too thin or overly broad.

    Completeness4/5

    The tool surface covers the key operations: health checks, task delegation (including batch and file processing), and cache management (stats, cleanup, clear). A minor gap is the lack of a tool to update or cancel a delegated task, but the core workflows are well supported.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers