Skip to main content
Glama
fthsrbst

lmstudio-ollama-mcp

by fthsrbst

lmstudio-ollama-mcp

npm install -g lmstudio-ollama-mcp
lmstudio-ollama-mcp doctor   # or: forge doctor
lmstudio-ollama-mcp "add unit tests for src/utils/logger.ts"

本地优先。私密。免费。无需 API 密钥。 前沿模型(GPT-4o、Claude 4)可选——仅用作规划器,实际工作由小型本地模型完成。别名 forge / forgecode 让你保留肌肉记忆。


为什么选择 lmstudio-ollama-mcp

Claude Code / Codex

lmstudio-ollama-mcp

运行环境

云端 API(付费,数据离开本机)

LM Studio · Ollama · llama.cpp(离线、私密)

成本

按 token 计费

$0(下载模型后)

子代理

单线程或云端并行

硬件感知的本地并行

模型选择

厂商锁定

任意 GGUF / 兼容 OpenAI 的模型

混合模式

前沿模型规划,本地模型执行(可选)

沙箱

云端容器

你的文件系统,你的规则

MCP

已就绪:将本地运行时桥接为 MCP 工具

一句话: lmstudio-ollama-mcp 将 Claude Code 的智能体循环——读取 → 规划 → 编辑 → 借助工具验证——带到你的 MacBook 上:内置智能路由器,简单任务交给本地 7B 模型,仅在需要复杂推理时才调用前沿模型。


Related MCP server: Shared Workspace MCP

演示

# 1 — Diagnose
lmstudio-ollama-mcp doctor
# Hardware: Apple M3 (8 cores / 16GB) • Recommended: 8 agents
# ● lmstudio (LM Studio) http://localhost:1234/v1  available
#   models: gemma-3-12b-qat, qwen3-27b-ud-iq2_s …

lmstudio-ollama-mcp models
# ● lmstudio  ▸ gemma-3-12b-qat 6.5GB Q4_0
#             ▸ qwen3-27b 7.8GB IQ2_S

# 2 — One-shot
lmstudio-ollama-mcp "refactor src/providers into a registry + add tests. keep public API stable"

# 3 — Parallel (auto-splits into sub-agents)
lmstudio-ollama-mcp --parallel 4 "implement auth module, write tests, and update docs"
# forge alias also works:
forge --parallel 4 "implement auth module, write tests, and update docs"

# 4 — Force a specific model
lmstudio-ollama-mcp --model ollama:qwen2.5-coder:14b "explain this repo's error handling"
lmstudio-ollama-mcp --provider lmstudio --model gemma-3-12b "fix the failing test in tests/tools.test.ts"

# 5 — Interactive
lmstudio-ollama-mcp
# lmstudio-ollama-mcp> add dark mode to docs/index.html

快速开始

前置要求

  • Node.js >= 18

  • 以下任选其一:

    • LM Studio —— 开发者 → 本地服务器 → 启动(端口 1234

    • Ollama —— ollama serve,然后 ollama pull qwen2.5-coder:7b

    • llama.cpp —— ./llama-server -m model.gguf --port 8080

安装

npm install -g lmstudio-ollama-mcp
# aliases also available: forge, forgecode
# or one-off
npx lmstudio-ollama-mcp doctor

首次运行

git clone https://github.com/your-org/your-project && cd your-project
lmstudio-ollama-mcp init   # creates lmstudio-ollama-mcp.json (also reads forgecode.json for compat)
lmstudio-ollama-mcp doctor # verify providers + hardware
lmstudio-ollama-mcp "list the codebase structure and suggest 3 small improvements"

纯本地模式无需 API 密钥。混合模式(前沿 + 本地)请设置以下环境变量:

export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...

架构

┌─────────────────────────────────────────────────────────┐
│  CLI  lmstudio-ollama-mcp "task"  •  doctor  •  models   │
│       aliases: forge, forgecode                         │
├─────────────────────────────────────────────────────────┤
│  Router  (strategy: auto | local-first | frontier-first)│
│  ├─ classify(prompt) → trivial | small | medium | large │
│  └─ thresholds.preferLocalFor: lint/format/test/search  │
├─────────────────────────────────────────────────────────┤
│  Orchestrator  (decompose → batch by deps → schedule)   │
│  ├─ Planner LLM decomposes goal → SubTasks[]            │
│  └─ Scheduler (hardware-aware p-limit, preserves order) │
├─────────────────────────────────────────────────────────┤
│  Agent Loop  (provider.chat ↔ tool executor)            │
│  ├─ Tools: read_file, write_file, edit_file, bash,      │
│  │        glob, grep, list_dir                           │
│  └─ Max 25 tool turns, exact-string edits               │
├─────────────────────────────────────────────────────────┤
│  Providers  (OpenAI-compatible)                         │
│  ├─ LM Studio  http://localhost:1234/v1  (+ fs scan)    │
│  ├─ Ollama     http://localhost:11434 (+ /api/tags)     │
│  ├─ llama.cpp  http://localhost:8080/v1                 │
│  └─ Frontier   OpenAI / Anthropic (optional)            │
├─────────────────────────────────────────────────────────┤
│  Hardware Detector  •  Scheduler                        │
│  cores × overcommit, free mem / perAgent → maxParallel │
│  Apple Silicon bonus, clamp 1..16                       │
└─────────────────────────────────────────────────────────┘

数据流:

User prompt
  → Router.classify → pick provider+model (local for small, frontier for large)
  → If parallel & non-trivial: Orchestrator.decompose → 2-6 SubTasks
  → Scheduler.runAll(SubTasks) with maxParallel = f(cores, RAM)
  → Each SubTask → Agent(provider, model, ToolExecutor) → tool loop
  → Synthesis agent merges results
  → Final summary

提供商

提供商

默认 URL

发现机制

备注

LM Studio

http://localhost:1234/v1

/v1/models + 扫描 ~/.lmstudio/models/**/*.gguf

支持 reasoning_content(Gemma)

Ollama

http://localhost:11434

原生使用 /api/tags,回退到 /v1/models

需要先运行 ollama pull <model>

llama.cpp

http://localhost:8080

/health + /v1/models

通过 llama-server 加载任意 GGUF

OpenAI

https://api.openai.com/v1

API

设置 OPENAI_API_KEY

Anthropic

https://api.anthropic.com

API

设置 ANTHROPIC_API_KEY

所有提供商都使用带 tools(函数调用)的 OpenAI 兼容 Chat Completions 接口,并自动规范化 reasoning_content(Qwen/Gemma)。

添加自定义端点

// lmstudio-ollama-mcp.json
{
  "providers": {
    "my-local": { "type": "openai", "baseUrl": "http://192.168.1.10:1234/v1", "enabled": true }
  }
}

并行子代理

通过规划器 LLM(有前沿模型则用前沿模型,否则用本地模型)将复杂目标拆分为 2–6 个独立子任务。执行受硬件能力约束:

// hardware/detector.ts — recommendParallelism()
cpuLimit = floor(cores * overcommit) - 1
memLimit = floor((totalGb*1024 - 2048) / perAgentMb)
maxParallel = min(cpuLimit, memLimit) + appleSiliconBonus
// clamp: 1..8 default, up to 16 on 64GB machines
lmstudio-ollama-mcp --parallel 8 "migrate codebase from Jest to Vitest"
# Decomposed:
#  t1 Explore & plan  →  search (routed to local 7B)
#  t2 Implement       →  code   (routed to local or frontier)
#  t3 Verify          →  test   (routed to local)
# Runner: Scheduler.runAll with p-limit = 8

带有 dependsOn 的任务按拓扑顺序分批运行——第 N 批只有等第 N-1 批完成后才会启动。

对本地模型友好: 简单任务(lintformatsummarizeexplain始终路由到本地,无论采用何种策略。


配置

配置解析优先级:DEFAULT < ~/.lmstudio-ollama-mcp/config.json < ./lmstudio-ollama-mcp.json < 环境变量。
旧版配置文件 ~/.forgecode/config.jsonforgecode.json / forge.json 仍会被读取以保持向后兼容(新路径优先)。

lmstudio-ollama-mcp config --show   # resolved JSON
lmstudio-ollama-mcp config --path   # file locations
lmstudio-ollama-mcp init            # scaffold lmstudio-ollama-mcp.json

lmstudio-ollama-mcp.json 配置参考

{
  "version": 1,
  "providers": {
    "lmstudio": { "type": "lmstudio", "baseUrl": "http://localhost:1234/v1", "enabled": true },
    "ollama":   { "type": "ollama",   "baseUrl": "http://localhost:11434",      "enabled": true },
    "llamacpp": { "type": "llamacpp", "baseUrl": "http://localhost:8080",       "enabled": true },
    "openai":   { "type": "openai",   "baseUrl": "https://api.openai.com/v1",   "apiKey": "sk-..." }
  },
  "router": {
    "strategy": "auto", // auto | local-first | frontier-first | local-only
    "frontierProvider": "openai",
    "frontierModel": "gpt-4o-mini",
    "thresholds": {
      "smallTaskMaxTokens": 2000,
      "preferLocalFor": ["lint","format","test","search","summarize","explain"]
    }
  },
  "hardware": {
    "maxParallelAgents": 4,      // auto if omitted
    "maxMemoryPerAgentMb": 1200,
    "cpuOvercommit": 1
  },
  "permissions": {
    "allowBash": true,
    "allowWriteOutsideWorkspace": false,
    "allowNetwork": true
  }
}

策略:

  • auto —— 简单/小型任务 → 本地;中/大型任务 → 前沿模型(若可用),否则本地。(推荐)

  • local-first —— 只有中/大型任务才使用前沿模型。

  • local-only —— 绝不调用前沿模型(完全离线)。

  • frontier-first —— 始终优先使用前沿模型。


工具

代理提供 7 个工具——与 Claude Code 相同的工具集,并限制在工作区沙箱内:

工具

说明

read_file

读取文件(上限 2 MB,超出则用 grep)

write_file

创建/覆盖文件(自动 mkdir -p)

edit_file

精确字符串替换(必须且只能匹配一次)

bash

运行命令(timeout 30s,5 MB 缓冲区)

glob

fast-glob 搜索

grep

正则搜索(跳过 node_modules/dist/.git

list_dir

列出目录内容

安全机制:除非设置 permissions.allowWriteOutsideWorkspace=true,否则会阻止路径逃逸;危险命令(rm -rf /)会被拒绝;过大的输出会被截断(30k)。


对比:何时使用哪种模型

任务

为何本地模型更优

示例

Lint / format / grep

0.2 秒 vs 2 秒 RTT

lmstudio-ollama-mcp "format src/**/*.ts with prettier"

解释 / 总结

私有代码库保留在本地

lmstudio-ollama-mcp "explain how auth works"

小改动

无需排队,零成本

lmstudio-ollama-mcp "add zod validation to src/config/schema.ts"

大型重构

前沿模型规划,本地模型并行执行

lmstudio-ollama-mcp "migrate to ESM"

复杂推理

需要 70B / 前沿模型

lmstudio-ollama-mcp --model openai:gpt-4o "design CRDT sync"


开发

npm install
npm run build        # tsc
npm test             # vitest
npm run dev -- doctor

项目结构:

src/
  cli/            commander CLI + commands (doctor, models, config, init)
  config/         Zod schema + layered store (global ↔ project)
  hardware/       detector (cores/RAM/GPU) + p-limit scheduler
  providers/      base + openai-compatible + lmstudio/ollama/llamacpp + registry + router
  core/           Agent (tool loop) + Orchestrator (decompose + parallel)
  tools/          definitions + executor (fs/glob/grep/bash)
  utils/          logger, format
tests/            vitest suites (hardware, tools, router, config, providers)
docs/             GitHub Pages landing (WizardZ-inspired, lime/black)

路线图

  • 流式输出(--stream

  • MCP(Model Context Protocol)服务器——将本地模型作为 MCP 工具开放给其他代理

  • 持久化记忆(.lmstudio-ollama-mcp/memory.md

  • lmstudio-ollama-mcp plan——仅演练分解,不实际执行

  • 视觉模型(Gemma 12B 多模态),用于截图驱动的 UI 工作

  • hooks——工具执行前/后的钩子

  • Windows / Linux GPU(CUDA/Vulkan)调度器提示


贡献

欢迎提交 PR。请保持核心原则:本地优先、依赖最少、硬件感知、拒绝 AI 垃圾内容

npm run build && npm test

关键词

lm-studio lmstudio ollama llama.cpp local-llm local-first coding-agent autonomous-agent claude-code codex sub-agents parallel-agents mcp model-context-protocol hardware-aware openai-compatible gguf agentic dev-tools ai-coding on-device-ai privacy


许可证

MIT — 参见 LICENSE

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

UpdatingMaintainers
UpdatingResponse time
Release cycle
0Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Cross-agent artifact workspace with provenance across Claude Code, Codex, Cursor, LangGraph.

  • Coding agents from Claude Code, Cursor and Codex claim jobs and lock files on one shared board.

  • Coding agents build full-stack apps in persistent workspaces and share them by link.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fthsrbst/lmstudio-ollama-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server