local-coder
Enables Codex to delegate coding tasks to a locally hosted Qwen model through an MCP tool, which can read, write, patch, test, and inspect git diffs inside an allowed workspace.
README
Local Coder MCP Agent
This project packages a local coding agent workflow:
- A Qwen coding model runs locally behind an OpenAI-compatible
/v1/chat/completionsAPI. - A Python worker talks to that local API with the OpenAI SDK.
- A
local-coderMCP server exposesdelegate_to_local_coderto Codex. - Codex delegates implementation tasks to the local worker, then reviews tests and diffs itself.
No model weights are included. Use your own local model directory through MODEL_DIR.
Architecture
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
The worker can list files, read files, write files, patch exact text, run pytest, run a small allowlist of commands, search text, inspect git status, and inspect git diff. It refuses paths outside the selected workspace.
Install
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
Edit .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=local
ALLOWED_WORKSPACE_ROOT is the directory tree the worker is allowed to edit.
For multiple roots, use ALLOWED_WORKSPACE_ROOTS separated by : on macOS/Linux.
Start The Model Server
For an MLX model on Apple Silicon:
source .venv/bin/activate
./scripts/start_qwen3_coder_server.sh
The script starts:
python -m mlx_lm.server \
--model "${MODEL_DIR}" \
--host 127.0.0.1 \
--port 8080 \
--max-tokens 4096 \
--temp 0
Any OpenAI-compatible server works if it exposes
http://127.0.0.1:8080/v1/chat/completions, or if you update
LOCAL_CODER_BASE_URL.
Start The MCP Server Manually
source .venv/bin/activate
./scripts/start_local_coder_mcp.sh
Normally Codex starts the MCP server for you from config.toml.
Configure Codex MCP
Copy the local-coder block from config.example.toml into your Codex
config.toml, then replace placeholders with local values:
[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}"
Use real local paths only in your private Codex config, never in committed files.
Delegate A Task From Codex
Example prompt to 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.
The included examples/sandbox folder is a tiny pytest project for smoke tests.
Common Errors
Workspace is not inside an allowed root
Set ALLOWED_WORKSPACE_ROOT or ALLOWED_WORKSPACE_ROOTS so the requested
workspace is inside an approved directory. This is intentional: the worker
should not be allowed to edit arbitrary local files.
Worker exceeded maximum number of steps
Increase max_steps for larger tasks, or split the task into smaller steps.
Good local-worker tasks are specific and verifiable.
Model returned no usable text
The local model server returned a response without usable content,
reasoning_content, reasoning, or thinking. Try:
- Confirm the server implements OpenAI-compatible chat completions.
- Set
LOCAL_CODER_ENABLE_THINKING=false. - Reduce task size.
- Test the server with a direct
/v1/chat/completionsrequest.
Connection failed
Confirm the model server is running, the port matches LOCAL_CODER_BASE_URL,
and no firewall or proxy is intercepting localhost traffic.
Security Notes
- Do not commit
.env, private Codex config files, model weights, logs, keys, or generated caches. - Keep
ALLOWED_WORKSPACE_ROOTnarrow. - The local worker can edit and run limited commands inside allowed workspaces; review every diff before accepting changes.
- Keep the API server bound to
127.0.0.1unless you have a separate network security plan. - This repository intentionally uses placeholders such as
${HOME},${MODEL_DIR},${PROJECT_ROOT}, and${ALLOWED_WORKSPACE_ROOT}.
Run Checks
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.py
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。