codex-workspace-codegraph-mcp
Allows exposing the MCP server and WebUI via Cloudflare Quick Tunnels, providing public URLs for remote access.
Provides tools for Git operations such as status, diff, log, and show within the workspace.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codex-workspace-codegraph-mcp find callers of function 'validate' in the codebase"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Codex Workspace CodeGraph MCP
这是一个不调用 Codex、不调用 OpenAI API、不需要账号、订阅、登录或 API Key 的本地代码操作 MCP。
项目参考 OpenAI Codex 开源仓库的代码工作流设计,自行实现文件读取、文本检索、补丁编辑、命令执行、Git 检查、计划管理、AGENTS.md 分层指令和安全审批;同时整合 CodeGraph 的大型代码库检索能力,以及简体中文 Interactive Feedback Web UI。
功能组成
1. Codex 风格本地代码工具
本项目没有启动或代理 codex 进程。以下功能由本项目独立实现:
工作区边界和符号链接逃逸检查。
AGENTS.md/AGENTS.override.md分层发现。文件读取、批量读取、目录列举、元数据查询。
文件名查找和文本搜索;优先使用
rg,缺失时自动回退。原子文件写入和精确文本替换。
Codex 风格
*** Begin Patch/*** End Patch补丁语法。新增、删除、更新和移动文件的事务式补丁应用。
前台命令执行、超时、输出截断和风险分类。
Git status、diff、log 和 show。
Codex 风格
update_plan状态约束。只读、工作区写入和高风险审批策略。
Codex 仓库仅作为以下设计参考:apply_patch 文件操作格式、复杂任务计划、优先使用快速检索工具、逐层加载项目指令,以及对破坏性操作进行限制。没有复制 Codex 的模型、认证、会话或代理实现。
2. 简体中文 Interactive Feedback
内置独立实现的简体中文 Web UI:
用户文字反馈。
最多四张 PNG、JPEG、WebP 或 GIF 图片附件。
用户主动运行模型预设的验证命令并查看 stdout/stderr。
危险命令、删除和覆盖操作审批。
会话轮询、过期时间和状态显示。
固定 48 小时超时:
172800秒。
MCP 初始化指令、Prompt、Resource、工具描述和 AGENTS.md 中均包含:
每次回答结束前都要调用 interactive_feedback 与用户进行交流 这是你与用户之间的唯一沟通渠道
实际 MCP 工具名为 interactive_feedback。其输入 schema 强制:
{
"timeout": 172800
}MCP 服务端无法获知模型何时“准备输出最终回答”,因此无法从协议层强制拦截最终回答;能否每次严格调用仍取决于 MCP 客户端和模型是否遵循服务端指令。
3. CodeGraph 大型代码库检索
项目依赖 @colbymchenry/codegraph,在目标工作区内启动:
codegraph serve --mcpCodeGraph 返回的工具通过 stdio JSON-RPC 动态代理,不在本项目中硬编码。默认请求暴露:
explore,node,search,callers,callees,impact,files,status另外提供:
codegraph_project_initcodegraph_project_synccodegraph_project_status
CodeGraph 在本地解析和索引代码,不需要 OpenAI 或其他模型 API。
Related MCP server: MCP Local LLM Server
运行要求
Node.js 22.5 或更高版本。
用于 CodeGraph 安装和首次运行的 npm 网络访问。
使用公网隧道时需要网络访问 Cloudflare。
不需要 Codex、ChatGPT、OpenAI API、账号或订阅。
方式一:作为 stdio MCP 直接使用
发布 npm 后,在目标代码库目录运行:
npx -y codex-workspace-codegraph-mcp@latest或显式指定工作区:
npx -y codex-workspace-codegraph-mcp@latest --workspace /absolute/path/to/repository通用 MCP 客户端配置:
{
"mcpServers": {
"codex-workspace": {
"command": "npx",
"args": [
"-y",
"codex-workspace-codegraph-mcp@latest",
"--workspace",
"/absolute/path/to/repository"
],
"env": {
"CWMCP_SANDBOX": "workspace-write",
"CWMCP_APPROVAL_POLICY": "on-request",
"CODEGRAPH_MCP_TOOLS": "explore,node,search,callers,callees,impact,files,status"
}
}
}
}stdio 模式的 MCP JSON-RPC 写入 stdout,运行日志和反馈 URL 仅写入 stderr。
方式二:一键启动 MCP、WebUI 和两个 Cloudflare Tunnel
在需要操作的代码库目录执行:
npx -y codex-workspace-codegraph-mcp@latest tunnel --workspace .本地源码运行:
npm install
npm run tunnel -- --workspace .也可以直接运行脚本:
./scripts/start.sh --workspace .Windows PowerShell:
.\scripts\start.ps1 --workspace .启动器会:
生成随机访问令牌。
启动
127.0.0.1:8765的 HTTP MCP。启动
127.0.0.1:8766的反馈 WebUI。检查
cloudflared;缺失时从 Cloudflare 官方 GitHub Release 自动下载到~/.codex-workspace-mcp/bin/。分别为 MCP 和 WebUI 启动 TryCloudflare Quick Tunnel。
在控制台输出本地和公网 URL。
按
Ctrl+C时停止 MCP、WebUI 和两个 tunnel。
示例输出:
MCP 本地 URL: http://127.0.0.1:8765/mcp/<token>
WebUI 本地 URL: http://127.0.0.1:8766/?token=<token>
MCP 公网 URL: https://example-a.trycloudflare.com/mcp/<token>
WebUI 公网 URL: https://example-b.trycloudflare.com/?token=<token>端口可修改:
npx -y codex-workspace-codegraph-mcp@latest tunnel \
--workspace . \
--mcp-port 9001 \
--web-port 9002已有 cloudflared 时可以显式指定:
npx -y codex-workspace-codegraph-mcp@latest tunnel \
--cloudflared /usr/local/bin/cloudflared禁止自动下载:
npx -y codex-workspace-codegraph-mcp@latest tunnel --no-download启动器会使用一个临时空配置文件,避免用户目录中的 ~/.cloudflared/config.yaml 干扰 Quick Tunnel。
Quick Tunnel 限制
Cloudflare 官方将 Quick Tunnel 定位为测试和开发用途,不提供 SLA,并且当前不支持 Server-Sent Events。远程 MCP 因此使用无 SSE 的 JSON-RPC HTTP POST。需要 SSE、稳定域名、访问控制或生产可靠性时,应创建正式 Cloudflare Tunnel,并分别把域名路由到 MCP 与 WebUI 本地端口。
远程 MCP 地址和 WebUI 地址中包含同一个随机访问令牌。URL 等同于密码,不应发布到日志、Issue、截图或公共聊天。
HTTP MCP
不启动 Cloudflare 时,可以直接运行本地 HTTP MCP:
npx -y codex-workspace-codegraph-mcp@latest \
--transport http \
--workspace . \
--mcp-port 8765 \
--web-port 8766控制台会输出:
http://127.0.0.1:8765/mcp/<token>HTTP 端点接受 JSON-RPC 2.0 POST。也可使用:
Authorization: Bearer <token>健康检查:
GET /health首次建立 CodeGraph 索引
在目标仓库目录执行:
npx -y @colbymchenry/codegraph init .或者让模型调用:
codegraph_project_init { "path": "." }之后大型代码库问题优先调用 codegraph_explore。索引需要手动同步时调用:
codegraph_project_sync { "path": "." }基础工具清单
工作区和读取
workspace_infoworkspace_instructionsread_fileread_many_fileslist_directoryfile_metadatafind_filessearch_text
编辑
write_fileedit_fileapply_patchcreate_directorymove_pathdelete_path
命令、Git 和计划
exec_commandgit_statusgit_diffgit_loggit_showupdate_planget_plan
反馈和集成
interactive_feedbackintegration_statuscodegraph_project_initcodegraph_project_synccodegraph_project_statusCodeGraph 动态返回的全部工具
apply_patch 示例
*** Begin Patch
*** Update File: src/example.js
@@
-export function value() {
- return 1;
-}
+export function value() {
+ return 2;
+}
*** Add File: test/example.test.js
+import test from 'node:test';
+// ...
*** End Patch支持:
*** Add File: path
*** Delete File: path
*** Update File: path
*** Move to: new-path
@@ optional context label
context
-old
+new所有路径必须相对工作区。补丁在写入前会先解析并验证;写入失败时尝试恢复原始文件。
沙箱和审批
默认值:
CWMCP_SANDBOX=workspace-write
CWMCP_APPROVAL_POLICY=on-requestCWMCP_SANDBOX:
read-only:拒绝文件写入和可能修改状态的命令。workspace-write:允许工作区内文件操作;这是默认值。
CWMCP_APPROVAL_POLICY:
on-request:仅高风险命令、删除和覆盖操作通过 WebUI 审批。untrusted:除明显只读命令外均审批。always:所有exec_command均审批。never:无法通过 WebUI 批准高风险操作,直接拒绝。
路径校验同时检查词法路径和真实路径,防止 ../ 与工作区内符号链接指向外部目录。
环境变量
变量 | 默认值 | 说明 |
| 当前目录 | 允许访问的工作区根目录 |
|
|
|
|
| MCP HTTP 监听地址 |
|
| MCP HTTP 端口 |
|
| WebUI 监听地址 |
|
| WebUI 端口 |
| 随机值 | HTTP MCP 和 WebUI 访问令牌 |
| 空 | 额外允许的浏览器 Origin,逗号分隔;默认仅接受同源和本机 Origin |
|
| 沙箱模式 |
|
| 审批策略 |
|
| 普通命令超时 |
|
| stdout/stderr 输出上限 |
|
| 单文件读取上限 |
|
| 设为 |
|
| CodeGraph 可执行文件 |
| 完整列表 | CodeGraph MCP 工具列表 |
| 自动查找 | cloudflared 可执行文件 |
|
| 设为 |
本地开发和验证
npm install
npm run verify验证包括:
所有 JavaScript 文件语法检查。
工作区路径穿越和符号链接逃逸测试。
AGENTS.md分层加载测试。Codex 风格补丁解析、写入和失败保护测试。
MCP 初始化、工具列表和固定 48 小时反馈 schema。
CodeGraph stdio 工具动态代理。
HTTP MCP 令牌认证、Origin 校验和 MCP 协议版本校验。
一键启动器同时输出两个 tunnel URL。
stdio MCP 烟雾测试。
上传 GitHub
git init
git add .
git commit -m "Initial release"
git branch -M main
git remote add origin https://github.com/YOUR_GITHUB_USERNAME/codex-workspace-codegraph-mcp.git
git push -u origin main先修改 package.json 中的 repository.url。
发布 npm
检查包名:
npm view codex-workspace-codegraph-mcp若名称被占用,改为作用域包:
{
"name": "@YOUR_NPM_USERNAME/codex-workspace-codegraph-mcp"
}发布:
npm login
npm run verify
npm publish --access public发布后:
npx -y codex-workspace-codegraph-mcp@latest --workspace .
npx -y codex-workspace-codegraph-mcp@latest tunnel --workspace .使用作用域包时替换包名即可。
上游参考
OpenAI Codex:Apache-2.0。用于研究代码代理工作流、补丁语法和项目指令发现。
MCP Feedback Enhanced:MIT。用于研究反馈工作流需求;本项目的 WebUI 和服务端为独立实现。
CodeGraph:MIT。作为 npm 运行时依赖和 MCP 子服务使用。
Cloudflared:由 Cloudflare 发布;仅在用户运行 tunnel 子命令时查找或下载。
详见 THIRD_PARTY_NOTICES.md、SECURITY.md 和 docs/ARCHITECTURE.md。
Available Tools
34 toolsapply_patch应用 Codex 风格补丁ADestructive
应用以 *** Begin Patch / *** End Patch 包裹的 Add、Delete、Update、Move 文件补丁。路径只能相对工作区;所有操作先验证,失败时尝试回滚。
Inputs: patch (required).
codegraph_calleesCodeGraph: codegraph_calleesARead-onlyIdempotent
List functions that calls. For the full flow, use codegraph_explore.
Inputs: symbol (required), projectPath (required), file, limit.
codegraph_callersCodeGraph: codegraph_callersARead-onlyIdempotent
List functions that call . For the full flow, use codegraph_explore.
Inputs: symbol (required), projectPath (required), file, limit.
codegraph_exploreCodeGraph: codegraph_exploreARead-onlyIdempotent
PRIMARY TOOL — call FIRST for almost any question OR before an edit: how does X work, architecture, a bug, where/what is X, surveying an area, or the symbols you are about to change. Returns the verbatim source of the relevant symbols grouped by file in ONE capped call (Read-equivalent — treat the shown source as already Read; do NOT re-open those files), plus the call path among them. Query can be a natural-language question OR a bag of symbol/file names. Usually the ONLY call you need — more accurate context, in far fewer tokens and round-trips than a search/Read/Grep loop.
Inputs: query (required), projectPath (required), maxFiles.
codegraph_filesCodeGraph: codegraph_filesARead-onlyIdempotent
Indexed file tree with language + symbol counts. Faster than Glob for project layout.
Inputs: projectPath (required), path, format, pattern, +2 more.
codegraph_impactCodeGraph: codegraph_impactARead-onlyIdempotent
List symbols affected by changing . Use before a refactor.
Inputs: symbol (required), projectPath (required), file, depth.
codegraph_nodeCodeGraph: codegraph_nodeARead-onlyIdempotent
Two modes. (1) READ A FILE — use INSTEAD of the Read tool: pass file (a path or basename) with no symbol and it returns that file's current on-disk source with line numbers, exactly the shape Read gives you (<n>\t<line>, safe to Edit from), narrowable with offset/limit just like Read — PLUS a one-line note of which files depend on it. Same bytes as Read, faster (served from the index), with the blast radius attached. Use it whenever you would Read a source file. (2) ONE SYMBOL you can name — its location, signature, verbatim source (includeCode=true) and caller/callee trail in one call, so before changing it you see what calls it and what your edit would break. For an AMBIGUOUS name it returns EVERY matching definition's body in one call (so you never Read a file to find the right overload); pass file/line to pin one. Use codegraph_explore for several related symbols or the full flow.
Inputs: projectPath (required), file, line, limit, +4 more.
codegraph_project_init初始化 CodeGraphC
在工作区或其子目录执行 codegraph init .,建立本地代码知识图谱索引。
Inputs: path.
codegraph_project_statusCodeGraph 状态CRead-only
执行 codegraph status,并返回 MCP 子进程状态。
Inputs: path.
codegraph_project_sync同步 CodeGraphB
在指定目录执行 codegraph sync,同步已有索引。
Inputs: path.
codegraph_searchCodeGraph: codegraph_searchARead-onlyIdempotent
Quick symbol search by name. Returns locations only (no code). Use codegraph_explore instead to get the actual source / understand an area in one call.
Inputs: query (required), projectPath (required), kind, limit.
codegraph_statusCodeGraph: codegraph_statusARead-onlyIdempotent
Index health check (files / nodes / edges). Skip unless debugging.
Inputs: projectPath (required).
create_directory创建目录A
递归创建工作区目录。
Inputs: path (required).
delete_path删除路径ADestructive
删除工作区内文件或目录。始终通过 interactive_feedback 请求批准。禁止删除工作区根目录。
Inputs: path (required), recursive.
edit_file精确替换文件内容ADestructive
仅在 old_text 出现次数与 expected_occurrences 完全一致时替换,避免误改。
Inputs: path (required), new_text (required), old_text (required), expected_occurrences.
exec_command执行命令ADestructive
在工作区执行前台命令。优先传 argv 数组;字符串命令通过系统 shell 执行。高风险命令通过 interactive_feedback 审批。
Inputs: command (required), cwd, env, shell, +2 more.
file_metadata文件元数据BRead-only
返回文件或目录的类型、大小、修改时间和权限。
Inputs: path (required).
find_files查找文件ARead-only
按路径片段和扩展名递归查找文件;自动跳过常见构建目录。
Inputs: path, limit, pattern, extensions.
get_plan读取执行计划ARead-only
返回当前内存中的执行计划。
Inputs: no named parameters.
git_diffGit 差异BRead-only
返回工作树或暂存区差异,可限制路径。
Inputs: cwd, path, stat, staged.
git_logGit 日志CRead-only
返回最近提交日志。
Inputs: cwd, path, limit.
git_show查看 Git 对象BRead-only
查看指定提交或对象,可限制文件路径。
Inputs: cwd, path, revision.
git_statusGit 状态ARead-only
返回 git status --short --branch。
Inputs: cwd.
integration_status集成状态BRead-only
返回本地工作区、反馈 Web UI 和 CodeGraph 集成状态。
Inputs: no named parameters.
interactive_feedback简体中文交互反馈A
在最终回答前通过唯一沟通渠道向用户展示工作摘要并等待反馈。timeout 固定为 172800 秒。每次回答结束前都要调用 interactive_feedback 与用户进行交流 这是你与用户之间的唯一沟通渠道。
Inputs: summary (required), timeout (required), cwd, details, +1 more.
list_directory列出目录BRead-only
列出工作区目录的直接子项。
Inputs: path, include_hidden.
move_path移动或重命名ADestructive
在工作区内移动或重命名文件/目录。覆盖目标时需要用户在 interactive_feedback 中批准。
Inputs: to (required), from (required), overwrite.
read_file读取文件BRead-only
读取工作区内文本文件,可指定行范围并返回行号。
Inputs: path (required), end_line, max_bytes, start_line, +1 more.
read_many_files批量读取文件ARead-only
一次读取多个工作区文本文件。单次最多 20 个。
Inputs: paths (required), max_bytes_per_file.
search_text搜索文本BRead-only
在工作区搜索文本。优先使用 ripgrep,缺失时使用 Node 回退实现。
Inputs: query (required), glob, path, limit, +2 more.
update_plan更新执行计划AIdempotent
维护 Codex 风格任务计划。未全部完成时必须且只能有一个 in_progress;完成后所有步骤为 completed。
Inputs: steps (required), explanation.
workspace_info工作区信息ARead-only
返回工作区根目录、沙箱模式、审批策略和服务状态。
Inputs: no named parameters.
workspace_instructions读取项目指令ARead-only
按照 Codex 风格,从工作区根目录到目标目录逐层加载 AGENTS.override.md 或 AGENTS.md。修改代码前应先调用。
Inputs: cwd.
write_file写入文件ADestructive
以原子替换方式创建或完整写入文本文件。已有文件默认允许覆盖;精确修改优先使用 edit_file 或 apply_patch。
Inputs: path (required), content (required), overwrite, create_only.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 34 tools
Several tool clusters overlap—file writing (write_file/edit_file/apply_patch), file reading (read_file/read_many_files/codegraph_node/codegraph_explore), and codegraph queries (search/node/callers/callees/impact)—creating potential misselection. However, detailed descriptions and explicit 'use codegraph_explore instead' guidance help an agent choose correctly.
All names are snake_case, and mutating actions generally use verb_noun (write_file, edit_file, move_path, create_directory, update_plan), while read judgements use noun_phrases (git_status, workspace_info, codegraph_files). Minor deviations like interactive_feedback and codegraph_node are noticeable but not confusing.
With 34 tools, this is a very heavy surface for one MCP server. The wide scope—file ops, git, planning, and codegraph—explains the quantity, but the number still exceeds the range where a tool set is easy to navigate, and many tools could be consolidated.
The file workspace lifecycle is well covered (create, read, update, delete, move, list, search), and the codegraph side offers init, sync, search, impact, callers, callees, node, and explore. Missing git write operations (add, commit, push) and a dedicated file copy tool are workaroundable via exec_command.
Maintenance
Related MCP Connectors
A MCP server built for developers enabling Git based project management with project and personal…
One MCP server for all your MCP servers: code mode, per-tool permissions, approvals and audit.
An MCP server that gives your AI access to the source code and docs of all public github repos
Repository knowledge graph MCP server for codebase understanding and debugging.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA modular MCP server that provides tools for file operations, regex-based code searching, and structural analysis of functions and classes across multiple programming languages. It also includes AI-powered features for intelligently updating files according to architectural changes.-
- AlicenseCqualityCmaintenanceA privacy-first MCP server that provides local LLM-enhanced tools for code analysis, security scanning, and automated task execution using backends like Ollama and LM Studio. It enables symbol-aware code reviews and workspace exploration while ensuring that all code and analysis remain strictly on your local machine.36ISC
- FlicenseAqualityDmaintenanceA local-first MCP server providing secure workspace file operations, offline full-text search, and web search/fetch capabilities without requiring API keys.10-
- AlicenseNot gradedqualityDmaintenanceA production-grade MCP server for local git repositories that provides tools for code search, git history analysis, complexity metrics, test discovery, and dependency management.MIT