AtomCode MCP (Model Context Protocol) 分析报告
基于二进制字符串提取、API 端点测试和 CLI 文档分析 2026-06-22
1. MCP 实现状态
当前状态:已实现但未配置。 mcp.json 不存在,/mcp/status 返回空服务器列表。
/mcp/status → {"servers": []}2. MCP 配置路径
| 优先级 | 路径 | 说明 |
|---|---|---|
| 1 | .mcp.json | 项目本地配置 |
| 2 | ~/.atomcode/mcp.json | 全局配置(通过 CLI --global 写入) |
| 3 | ~/global.mcp.json | 另一全局路径 |
| 特殊 | mcp_auth.toml | OAuth token 存储(与 auth.toml 同级) |
3. mcp.json 配置结构
json
{
"mcpServers": {
"<server-name>": {
"command": "npx @playwright/mcp@latest", // stdio 类型
"args": ["--arg1", "--arg2"],
"env": {
"KEY": "VALUE"
},
"timeout_ms": 5000,
"autoApprove": ["tool_name1", "tool_name2"],
"trust": "allow|ask|deny",
// 远程/OAuth 类型
"url": "https://api.githubcopilot.com/mcp",
"headers": {
"Authorization": "Bearer ..."
},
// OAuth 配置(标准 OAuth+PKCE)
"oauth": {
"client_id": "...",
"client_secret_env": "ENV_VAR_NAME",
"scopes": ["repo", "read:org", "notifications"]
}
}
}
}3.1 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
command | string | stdio MCP 服务器的可执行文件 |
args | string[] | 命令行参数 |
env | object | 环境变量 |
timeout_ms | integer | 超时(毫秒) |
autoApprove | string[] | 自动审批的工具列表 |
trust | string | allow(信任)、ask(询问)、deny(拒绝) |
url | string | 远程 MCP 服务器 URL |
headers | object | HTTP 请求头 |
oauth.client_id | string | OAuth 客户端 ID |
oauth.client_secret_env | string | 含 client_secret 的环境变量名 |
oauth.scopes | string[] | OAuth 授权范围 |
4. 服务器类型
4.1 stdio(本地进程)
command + args → MCP 子进程(stdin/stdout JSON-RPC)4.2 HTTP(远程服务器)
url + headers → HTTP MCP 请求4.3 OAuth 认证远程
url + OAuth PKCE 流程 → 自动 token 管理5. GitHub MCP 集成
5.1 配置方式
bash
atomcode mcp add-github-oauth \
--client-id <ID> \
--client-secret-env <ENV_VAR>5.2 OAuth 端点
授权: https://github.com/login/oauth/authorize
Token: https://github.com/login/oauth/access_token
MCP: https://api.githubcopilot.com/mcp5.3 环境变量
ATOMCODE_GITHUB_MCP_CLIENT_ID — GitHub OAuth client ID5.4 流程
atomcode mcp add-github-oauth
→ 浏览器打开 GitHub OAuth 授权页
→ 用户授权
→ 本地收到 OAuth callback
→ 换取 access_token
→ 存储到 mcp_auth.toml
→ MCP 服务器就绪6. MCP CLI 命令
| 命令 | 说明 |
|---|---|
atomcode mcp add <name> --command ... --args ... | 添加 stdio MCP 服务器 |
atomcode mcp add-github-oauth | 添加 GitHub OAuth MCP |
atomcode mcp login <server-name> | 完成 OAuth 登录 |
atomcode mcp logout <server-name> | 清除 OAuth 凭证 |
atomcode mcp reload | 重新加载 MCP 配置 |
atomcode mcp status | 显示 MCP 状态 |
--global | 写入 ~/.atomcode/mcp.json |
7. MCP API 端点
| 端点 | 方法 | 说明 |
|---|---|---|
/mcp/status | GET | MCP 状态(服务器列表) |
/mcp/reload | POST | 重新加载配置 |
/mcp/tools | GET/POST | 工具列表 |
/mcp/servers | GET/POST | 服务器列表 |
/mcp/login | GET/POST | OAuth 登录 |
/mcp/logout | GET/POST | OAuth 登出 |
/mcp/list | GET/POST | 列表信息 |
8. OAuth 技术细节
支持完整的 OAuth 2.0 + PKCE:
authorization_code grant type
code_challenge_method: S256
code_verifier: 随机 128 字符
client_secret: 可选(动态注册或预注册)
redirect_uri: 本地回调服务器错误处理
| 错误 | 说明 |
|---|---|
MCP OAuth requires a pre-registered client_id | 服务端不支持动态注册 |
Failed to exchange MCP OAuth code | code 交换失败 |
OAuth token is expired and has no refresh token | token 过期且无 refresh |
OAuth state mismatch | CSRF 保护触发 |
OAuth authorization server metadata request failed | 元数据获取失败 |
9. MCP 工具命名与权限
MCP 工具在系统中以 mcp__<server>__<tool> 格式注册,与本地工具并列。
SPA 对 MCP 工具有特殊的审批 UI:
javascript
// 前端有 "allow_persist" 按钮专门用于 MCP 工具
e.tool_name.startsWith('mcp__') && (button "allow_persist")autoApprove 数组用于设置自动审批的工具名。
逆向命令索引
bash
# 提取 MCP 相关结构体
strings atomcode.bin.bak | grep -E "struct JsonRpc|struct InitializeResult|struct McpOAuthToken|struct McpToolDefinition|struct CallToolResult" | sort -u
# 输出:
# struct CallToolResult with 2 elements
# struct InitializeResult with 3 elements
# struct JsonRpcError with 2 elements
# struct JsonRpcResponse with 4 elements
# struct McpOAuthToken with 11 elements
# struct McpToolDefinition with 3 elements
# 提取 MCP 源文件
strings atomcode.bin.bak | grep "^crates/atomcode-core/src/mcp/" | sort -u
# 输出: 6 个 (transport_http, transport_stdio, config, oauth, registry, tool_adapter)
# 提取 MCP 配置格式
strings atomcode.bin.bak | grep -iE "mcpServers|autoApprove|mcp\.json" | sort -u | head -5
# 输出: mcpServers autoApprove is not an array mcp.json .mcp.json10. 同类工具对比
| 特性 | AtomCode MCP | Claude Code MCP |
|---|---|---|
| stdio 支持 | ✅ | ✅ |
| HTTP 远程 | ✅ | ✅ |
| OAuth PKCE | ✅ | ✅ |
| GitHub MCP | ✅ | ✅ |
| autoApprove | ✅ | ✅ |
| mcp.json 兼容 | ✅ Claude Code 兼容 | 原生 |
| 工具命名 | mcp__name__tool | name__tool |