/cloudbase-ai-toolkit:codebuddy-ide-mcp-upgradefrom cloudbase-ai-toolkit
Upgrades the CloudBase MCP bundled inside CodeBuddy IDE (genie extension) and syncs tool whitelists on MCP release. Covers unpacking, rebuilding, whitelist generation, safe injection, verification, and rollback.
Ships in cloudbase-ai-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
toolWhiteList / systemPrompt / attatchPromptCodeBuddy IDE 的内置 CloudBase MCP 由 genie 扩展承载,改一处不生效,必须同时改两个文件:
| 文件 | 内容 | 等价来源 |
|---|---|---|
Contents/Resources/app/extensions/genie/integration-mcp/tcb/index.cjs | MCP Server bundle | 仓库 mcp/dist/cli.cjs 改名 |
Contents/Resources/app/extensions/genie/out/extension/index.js | 内嵌的 tcb 集成配置(webpack module,ir.exports=JSON.parse('{...}')) | 无仓库对版,需就地解包 |
默认 IDE 路径:/Applications/CodeBuddy CN.app。同目录还有 anydev、eop、lighthouse 三个集成,别改错。
加载与启动契约:
// TcbIntegration
mcpServer: {
path: path.join("integration-mcp", "tcb", "index.cjs"),
envMapper: (r) => ({ TENCENTCLOUD_SECRETID: r.tmp_secret_id,
TENCENTCLOUD_SECRETKEY: r.tmp_secret_key,
TENCENTCLOUD_SESSIONTOKEN: r.token }),
toolWhiteList: config.toolWhiteList,
}
// StdioClientTransport
{ command: process.execPath, args: [mcpPath],
env: { ...envMapper(), INTEGRATION_IDE: "CodeBuddy",
ELECTRON_RUN_AS_NODE: "1", WORKSPACE_FOLDER_PATHS } }
不传任何命令行参数(--cloud-mode / --integration-ide 都没用),凭据全靠环境变量,MCP 侧 mcp/src/auth.ts 直接读 TENCENTCLOUD_SECRETID/SECRETKEY。
配置内嵌在 21MB 的 out/extension/index.js 里,用 JSON.parse('...') 包着,必须按 JS 字符串语义 eval 才能解析:
const i = s.indexOf('"id":"tcb"');
const st = s.lastIndexOf("JSON.parse('", i) + 12;
let cursor = st, cfg;
for (;;) {
cursor = s.indexOf("')", cursor + 1);
try { cfg = JSON.parse(eval("'" + s.slice(st, cursor) + "'")); break; } catch {}
}
拿到后先数一遍白名单,并和仓库 scripts/tools.json 比对。九成问题出在这里:白名单停留在旧版本,里面全是已被 MCP 改名的死条目。
cd <repo>/mcp && npm run build:webpack # 产物 dist/cli.cjs,约 4.6 MiB
只跑 build:webpack,不要跑 npm run build(会触发 prebuild 的 rm -rf dist,可能被 safe-delete hook 拦截)。
白名单真源是 scripts/tools.json,不要手写清单。配置改动落在:
toolWhiteList ← tools.json 全部工具名(全量,不要裁剪,理由见「白名单裁剪的前提已不存在」)systemPrompt.login / .logout、userPrompt.*、attatchPrompt.* ← 提示词id、displayName、description、descriptionMap、types、ruleZipUrl、loginOnlyChinese、loginType、toolTimeout)保持原值(1)PG 模式 = Supabase 同构,不是「多了一种数据库」
判定为 PG 环境后,认证、存储、权限、迁移四项全部改道:
| 能力层 | Supabase | CloudBase PG 模式 | 工具 |
|---|---|---|---|
| 数据库 | Postgres | PostgreSQL | queryPgDatabase / managePgDatabase |
| Schema 变更 | Migration | applyMigration(须带 migrationVersion) | managePgDatabase |
| 行级授权 | RLS Policies | RLS | managePgDatabase + rls-patterns.md |
| 存储 | Storage Buckets | pgstore(与 legacy COS 是两套系统) | queryPgStorage(不是 queryStorage) |
| 认证 | anon/service key | 应用认证(publishable key / API key) | queryAppAuth / manageAppAuth |
PG 环境里引导错路径(用 NoSQL/MySQL 工具,或用 queryStorage 而非 queryPgStorage)是最高频的跑偏方式。
(2)提示词看配重,不看总长
systemPrompt.login 约 10.6k 字符 ≈ 3.5k token,在 Tool Search + 长上下文下不构成负担。为「看起来短」删引导 = 丢掉关键分叉点的判断质量。改完提示词用这个脚本量化配重,别靠感觉:
node -e '
const s=require("fs").readFileSync("config/prompts/systemPrompt.login.md","utf8"),L=s.split("\n");
let c="(开头)",a={[c]:0},o=[c];
for(const l of L){if(/^## /.test(l)){c=l.slice(3);if(!(c in a)){a[c]=0;o.push(c)}continue}
if(/^### /.test(l)){c=l.slice(4);if(!(c in a)){a[c]=0;o.push(c)}continue}a[c]+=l.length+1}
for(const k of o)console.log(String(a[k]).padStart(6),(a[k]/s.length*100).toFixed(1).padStart(5)+"% ",k.slice(0,50))'
node scripts/apply-to-ide.mjs --dry-run # 只看差异
node scripts/apply-to-ide.mjs # 备份到 backup/<时间戳>/ 后写入
node scripts/patch-tool-timeout.mjs --timeout 300000 # 接通 toolTimeout(见 Pitfalls)
写配置的替换逻辑:生成紧凑 JSON(JSON.stringify(cfg),无裸换行),再按 JS 单引号字符串转义(先 \\ 再 '),替换 JSON.parse('...') 区间。转义顺序错了会破坏 JS 字符串。
边界语义(踩过坑,勿改错):start = raw 起点(slice(0, start) 里已包含 JSON.parse('),end = ') 之后。所以替换时只能拼 escaped raw + '),绝不能再拼一次 JSON.parse('。
node scripts/verify-ide-config.mjs # 从 IDE 回读配置,逐字段比对
node scripts/verify-bundle.mjs # 按 IDE 方式启动 bundle,拉 tools/list
verify-bundle.mjs 复刻 IDE 的启动参数(stdio + INTEGRATION_IDE=CodeBuddy + ELECTRON_RUN_AS_NODE=1 + 临时密钥占位值),比对三件事:暴露的工具是否全在白名单内、白名单是否有悬空条目、PG 工具是否注册。
node scripts/rollback-ide.mjs --latest
白名单漂移是「IDE 里 CloudBase 功能不足」的唯一根因,不是 MCP 能力问题。线上实测:21 条白名单里 12 条是已被 MCP 删除或改名的死条目,用户实际只能用 9 个。
因此 MCP 每次发版(工具增删改名)都必须重新生成 IDE 侧白名单,否则新版本 MCP 发得再勤,IDE 里还是老的。
发版 checklist:
scripts/tools.json 是否已更新(工具清单真源)scripts/build-config.mjs 重新生成 IDE 配置,产出新 toolWhiteList建议把这个 checklist 挂到 MCP 发版流程里(release workflow 或发版 checklist 文档),不要靠人工记忆。 靠人记的后果就是这次的 12 条死条目。
defer_loading。toolWhiteList 的唯一理由就是省上下文,这个前提现在没了。tools.json 全量生成。继续裁剪的唯一后果就是随 MCP 发版漂移成死条目。out/extension/index.js —— 那里搜不到 ToolSearch 字符串(实测 0 命中)。Tool Search 属 Agent CLI 内核层,证据在 CLI 进程参数(--tools 白名单含 ToolSearch)和 mcp-config 的 defer_loading 里。') 序列,必须用「eval + JSON.parse 能否成功」来判断结束位置,不能用第一个 ')。"id":"tcb" 做锚点。 全文 toolWhiteList 出现 13 次,用 toolWhiteList 搜会抓到 eop(EdgeOne)的配置块——症状是解出来的 raw 只有 1,015 字符(正常应 ~16,000)。msg-push)不在 DEFAULT_PLUGINS 里,白名单写了也不会注册,需注入 CLOUDBASE_MCP_PLUGINS_ENABLED=msg-push。白名单 40 条、实际暴露 38 条是正常现象,不是 bug。曾发生的事故:替换时重复拼接 JSON.parse(' 前缀,生成 JSON.parse('JSON.parse('{...}'),第二个 ' 提前闭合字符串,整文件 SyntaxError。但 verify 脚本的 JSON 字段比对全部显示 ✅ —— 因为定位用 lastIndexOf("JSON.parse('"),恰好命中了第二个前缀,照样能解析出正确 JSON。
铁律:改动这种大打包产物后,必须对整文件做真实编译:
import vm from "node:vm";
try { new vm.Script(source, { filename: "index.js" }); }
catch (e) { /* 立即回滚备份 */ }
exit 1,只打印 ❌ 而不改变退出码等于没有检查node --check <file>,不要只信自己的脚本toolTimeout 未接通,实际只有 60 秒TcbIntegration 的配置对象没有 toolTimeout 字段(EopIntegration 传了)callTool 用 this.config.toolTimeout → undefinedconst Sn = sn?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC,而 DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4"toolTimeout":120000 从未生效,实际 60 秒就掐断 PG applyMigration / CloudRun 部署修复(scripts/patch-tool-timeout.mjs):
TcbIntegration 配置对象补 toolTimeout:hn.toolTimeout(锚点 attatchPrompt:hn.attatchPrompt,loginOnlyChinese:hn.loginOnlyChinese},全文唯一 1 处)((ir?.tools) || []).filter((ir) => this.config.mcpServer.toolWhiteList.includes(ir.name))
遍历的是 server 实际返回的 tools/list,白名单只做 includes 判定。多出的条目静默跳过、不报错、不产生悬空工具。所以白名单按 tools.json 全量下发是安全的,插件后续启用也无需再改配置。
mcp/src/server.ts 用 ide === "CodeBuddy" 判定 logging capability,大小写敏感;IDE 传的正是 "CodeBuddy",别改成小写。executeReadOnlySQL、createFunction、uploadFiles、writeSecurityRule 等),新 bundle 里这些名字已全部消失,提示词里如果还在引用就会引导模型调用不存在的工具。交付前必须同时满足:
node --check "<genie>/out/extension/index.js" 通过(最关键,能抓住回读校验掩盖的语法错误)apply-to-ide.mjs 输出「语法有效」+「回读校验通过」verify-ide-config.mjs 结构完整性三项 ✅ + 七个字段 ✅,echo $? 为 0verify-bundle.mjs 显示「所有暴露的工具都在白名单内」且 PG 三件套(queryPgDatabase / managePgDatabase / queryPgStorage)已注册verify-ide-config.mjs 反向测试:喂已知损坏文件必须 exit 1脚本只能证明「bundle 与配置文件本身是对的」,证明不了 IDE 加载后用户真的能用。重启后逐项跑:
| # | 用例 | 预期 |
|---|---|---|
| E1 | 完全退出后重启 IDE | 集成面板正常渲染,无 SyntaxError、genie 扩展不报错 |
| E2 | 集成面板连接 CloudBase | 登录成功,显示环境信息 |
| E3 | 让 Agent 列出可用的 CloudBase 工具 | 数量与新白名单一致(不是旧版数量) |
| E4 | PG 环境让 Agent 建表 | 走 managePgDatabase 的 applyMigration,提示词先引导读 postgresql-development-cloudbase 规则 |
| E5 | 执行一条只读 SQL | 走 queryMysqlDatabase(不再是 executeReadOnlySQL) |
| E6 | 部署一个 Node.js 云函数 | 走 manageFunctions(不再是 createFunction) |
| E7 | PG 模式下访问存储 | 走 queryPgStorage 而非 queryStorage |
| E8 | 查看/修改安全规则 | 走 queryPermissions / managePermissions(不再是 writeSecurityRule) |
| E9 | PG 执行耗时 >1 分钟的迁移 | 不中断,5 分钟超时生效(验证 toolTimeout 修复) |
| E10 | 正常对话观察上下文占用 | 工具全量放开后无明显膨胀(验证 Tool Search 结论) |
验证时的两个坑:
Authorization cache loaded for tcb, tempKey expires at: <过去时间>,必须在集成面板重新登录,MCP 才起来。tools/list 属正常,别据此判定 bundle 没生效。日志位置:~/Library/Application Support/CodeBuddy CN/logs/<时间戳>/window1/exthost/Tencent-Cloud.coding-copilot/腾讯云代码助手.log(搜 [Integration] / tcb)。
如果要顺带评估 MCP 工具层本身,这几项是实测通过的基线,达不到说明有回归:
queryPgDatabase(action=sql) 必须拦截 DELETE / UPDATE / DROP / 多语句注入,且返回带 nextActions 的可执行建议managePgDatabase(execute)、manageFunctions(deleteFunction) 缺 confirm 时必须拒绝queryPermissions 应返回「不支持 PostgreSQL 类型环境」,而不是假装成功首次实操的完整交付物(文档 + 配置 + 脚本)模板在 CloudBase-MCP 仓库的 specs/cb-ide-mcp-upgrade/(worktree chore/cb-ide-mcp-upgrade)。
凡「改配置 + 再打独立 patch」的两步流程,patch 改的标量必须回流到配置生成脚本。
实例:本任务里 toolTimeout 先从 120000 提到 300000 是靠 patch-tool-timeout.mjs 单独 patch 的,而 build-config.mjs 生成的 tcb-config.new.json 里仍是 120000。交付物自带旧值,IDE 侧直接拿配置去用就会退回两分钟。
自查项:
Markdown 交付物不要放在点开头的隐藏目录下。git worktree 常用 .worktrees/<name>/,预览器常因安全策略拒绝加载隐藏目录资源,表现是「文件能读到、点击却打不开/报错」。
交付前做两件事:
~/Projects/cb-ide-mcp-upgrade/),present_files 指向该路径present_files 第一个传它(HTML 会同时开预览面板 + 列 artifact card,最稳)渲染脚本在本 skill 的 scripts/render-html.mjs,依赖 marked:
mkdir -p /tmp/mdrender && cd /tmp/mdrender
echo '{"name":"mdrender","private":true}' > package.json
npm install marked
NODE_PATH=/tmp/mdrender/node_modules node <skill>/scripts/render-html.mjs \
"<交付目录>/README.md" "<交付目录>/README.html" "文档标题"
注意:npm install 别在 ~/.workbuddy/binaries/node/workspace 里跑——没有 package.json 时 npm 会向上找到 ~/node_modules 并因 ENOTEMPTY 失败。装到带 package.json 的临时目录最省事。
产物自带侧边目录导航(从 h2/h3 生成)、表格与代码高亮样式、@media print 打印规则(可直接导出 PDF 交给外部团队)。
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
codebuddy, mcp-upgrade, ide-integration, tool-whitelist, cloudbase
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: agents.0: Invalid string: must end with ".md", agents.1: Invalid string: must end with ".md", agents.2: Invalid string: must end with ".md", agents.3: Invalid string: must end with ".md", agents.4: Invalid string: must end with ".md", agents.5: Invalid string: must end with ".md", agents.6: Invalid string: must end with ".md"
.claude-plugin/plugin.json: agents.0: Invalid string: must end with ".md", agents.1: Invalid string: must end with ".md", agents.2: Invalid string: must end with ".md", agents.3: Invalid string: must end with ".md", agents.4: Invalid string: must end with ".md", agents.5: Invalid string: must end with ".md", agents.6: Invalid string: must end with ".md"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
13 skills in this plugin
/api-contract-reviewUse when auditing CloudBase cloud API wrappers, MCP tools, generated action metadata, or related docs for outdated or incorrect action names, parameters, casing, request shapes, or missing contract tests, especially during periodic quality review or before preparing corrective PRs./cloud-api-recipe-authoringAuthor or revise a cloud-api-operations recipe (config/source/skills/cloud-api-operations/references/recipes/). Encodes why the long tail of control-plane capabilities is deliberately NOT wrapped as MCP/CLI tools, the API-first admission test for whether a capability deserves a recipe, the negative and positive lists, the fixed recipe structure, the writing rules distilled from writing-for-agents, the user-facing copy red lines, and the product regeneration/verification pipeline. Also routes contributors (and their agents) to the contribution flow and the pre-PR self-test protocol in references/contributing.md. Use when adding a recipe, judging whether a scenario belongs in the recipe set, updating the recipes index, re-checking existing recipes against the admission test, or onboarding someone who wants to submit one./codebase-auditPerform a full codebase review, categorize findings by severity, file GitHub issues, then fix each issue in an isolated git worktree and submit PRs. Use this skill when the user asks to audit the codebase, do a comprehensive code review, find and fix security/quality/reliability issues, or run a proactive health check across the entire repository./doc-freshness-reviewUse when auditing repository documentation for drift, stale statements, broken references, or README mismatches, especially across published docs under `doc/` and key entry surfaces such as `README.md` (English default), `README.zh-CN.md`, `mcp/README.md`, and `mcp/README.zh-CN.md` during periodic maintenance or before preparing corrective PRs./docs-workflowsDocumentation and extension workflows derived from local slash commands (docs, explanation, issues, prototypes, tutorials, MCP design review)./git-workflowsReusable git delivery workflows derived from local slash commands (commit, push, PR, release notes, GitHub Actions failure triage with worktree-based fixes, and isolating your own changes from a shared dirty workspace).Other plugins' skills for the same job