local-coder
Local Coder MCP Agent
本项目封装了一个本地编码代理工作流:
一个 Qwen 编码模型在本地运行,并通过 OpenAI 兼容的
/v1/chat/completionsAPI 对外提供服务。一个 Python worker 通过 OpenAI SDK 与该本地 API 通信。
一个
local-coderMCP 服务器向 Codex 暴露delegate_to_local_coder。Codex 将实现任务转交给本地 worker,然后由它自行审查测试和 diff。
不包含模型权重。请通过 MODEL_DIR 使用你自己的本地模型目录。
架构
Codex
-> MCP tool: delegate_to_local_coder(task, workspace, max_steps)
-> mcp_servers.local_coder.server
-> workers.coding.worker.CodingWorker
-> OpenAI-compatible local model server
-> restricted file/test/git tools inside the requested workspace该 worker 可以列出文件、读取文件、写入文件、对精确文本打补丁、运行 pytest、运行一个小型命令白名单、搜索文本、检查 git status 和检查 git diff。它会拒绝所选工作区之外的路径。
Related MCP server: cc-in-codex
安装
git clone <your-repo-url>
cd local-coder-mcp-agent
python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -e ".[dev,mlx]"
cp .env.example .env编辑 .env:
MODEL_DIR=${HOME}/models/Qwen3-Coder-30B-A3B-Instruct-4bit
ALLOWED_WORKSPACE_ROOT=${HOME}/AI/projects
LOCAL_CODER_BASE_URL=http://127.0.0.1:8080/v1
LOCAL_CODER_MODEL=default_model
LOCAL_CODER_API_KEY=localALLOWED_WORKSPACE_ROOT 是允许 worker 编辑的目录树。如果有多个根目录,请在 macOS/Linux 上使用以 : 分隔的 ALLOWED_WORKSPACE_ROOTS。
启动模型服务器
在 Apple Silicon 上使用 MLX 模型时:
source .venv/bin/activate
./scripts/start_qwen3_coder_server.sh脚本会启动:
python -m mlx_lm.server \
--model "${MODEL_DIR}" \
--host 127.0.0.1 \
--port 8080 \
--max-tokens 4096 \
--temp 0任何 OpenAI 兼容的服务器都可以工作,只要它暴露了 http://127.0.0.1:8080/v1/chat/completions,或者你更新 LOCAL_CODER_BASE_URL。
手动启动 MCP 服务器
source .venv/bin/activate
./scripts/start_local_coder_mcp.sh通常情况下,Codex 会从 config.toml 中为你自动启动 MCP 服务器。
配置 Codex MCP
将 config.example.toml 中的 local-coder 块复制到你的 Codex config.toml 中,然后把占位符替换为本地值:
[mcp_servers.local-coder]
enabled = true
command = "${PROJECT_ROOT}/.venv/bin/python"
args = ["-m", "mcp_servers.local_coder.server"]
cwd = "${PROJECT_ROOT}"
[mcp_servers.local-coder.env]
LOCAL_CODER_BASE_URL = "http://127.0.0.1:8080/v1"
LOCAL_CODER_MODEL = "default_model"
LOCAL_CODER_API_KEY = "local"
ALLOWED_WORKSPACE_ROOT = "${ALLOWED_WORKSPACE_ROOT}"只能在你的私有 Codex 配置中使用真实本地路径,绝不要放入已提交批准的文件中。
从 Codex 委派任务
给 Codex 的示例提示:
Use the local-coder MCP server and specifically call delegate_to_local_coder.
Workspace:
${ALLOWED_WORKSPACE_ROOT}/sandbox
Task:
Add multiply(a: int, b: int) -> int to calculator.py.
Requirements:
- Do not change add(), subtract(), or divide().
- Add pytest coverage for multiply().
- Run all tests.
- Inspect git diff before finishing.
After the local worker completes the task, review its changes yourself.
Do not implement the change yourself unless the local worker fails.随附的 examples/sandbox 文件夹是一个用于冒烟测试的小型 pytest 项目。
常见错误
工作区不在允许的根目录内
设置 ALLOWED_WORKSPACE_ROOT 或 ALLOWED_WORKSPACE_ROOTS,使请求的工作区位于允许目录内。这是有意为之:不应允许 worker 编辑任意本地文件。
Worker 超过了最大操作步骤
对于更大的任务,请增加 max_steps,或将任务拆分为更小的步骤。好的本地 worker 任务应当具体且可验证。
模型没有返回可用的文本
本地模型服务器返回的响应中没有可用的 content、reasoning_content、reasoning 或 thinking。请尝试:
确认服务器实现了 OpenAI 兼容的 chat completions 接口。
设置
LOCAL_CODER_ENABLE_THINKING=false。缩小任务规模。
直接使用
/v1/chat/completions请求测试服务器。
连接失败
确认模型服务器正在运行,并检查服务器上的端口与 LOCAL_CODER_BASE_URL 是否匹配,且没有防火墙或代理拦截 localhost 流量。
安全说明
不要提交
.env、私有 Codex 配置文件、模型权重、日志、密钥或生成的缓存。让
ALLOWED_WORKSPACE_ROOT保持在一个较小的允许目录范围内。本地 worker 可以在允许的的范围内编辑文件并运行受限命令;接受任何更改前,请检查每个 diff。
保持 API 服务器绑定到
127.0.0.1,除非你有独立的网络安全方案。本仓库有意使用诸如
${HOME}、${MODEL_DIR}、${PROJECT_ROOT}和${ALLOWED_WORKSPACE_ROOT}之类的占位符。
运行检查
python -m pytest -q
python -m py_compile \
mcp_servers/local_coder/server.py \
workers/coding/client.py \
workers/coding/parser.py \
workers/coding/tools.py \
workers/coding/worker.pyMaintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceEnables ChatGPT to inspect and edit local projects through a secure MCP interface, offering workspace management, file operations, git integration, and safe command execution.4MIT
- AlicenseBqualityCmaintenanceEnables Codex to manage a local Claude Code companion through MCP, implementing a dual-agent workflow where Codex handles reasoning and review while Claude Code performs engineering tasks.181MIT
- AlicenseNot gradedqualityDmaintenanceEnables Codex to delegate code reviews, coding tasks, image/video generation, and background investigations to Grok via MCP tools.10Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables Codex to delegate bounded work to external LLMs through role-based MCP tools, with worker health checks and audit logging.MIT
Related MCP Connectors
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/starmania7/local-coder-mcp-agent'
If you have feedback or need assistance with the MCP directory API, please join our Discord server