Skip to content

feat(mcp): add remote discovery and single-call tool execution - #51

Open
wklken wants to merge 5 commits into
TencentBlueKing:masterfrom
wklken:codex/mcp-phase-one
Open

wklken wants to merge 5 commits into
TencentBlueKing:masterfrom
wklken:codex/mcp-phase-one

Conversation

@wklken

@wklken wklken commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

新增 bk-cli mcp <server>,按独立 mcp.json 配置连接远程 Streamable HTTP server,支持 --list 离线列出已配置服务,以及检查、完整工具发现、动态帮助、具名参数/完整 JSON 调用和离线预览。MCP 认证只来自选定 server 的 headers,不加载 context 凭据、tenant 或 stage。

  • 配置显式使用 type: "http",校验整个文件;条目错误指出 server、字段和原因,凭据值不回显。header 字符串原样发送,不做环境变量展开。支持 Bearer、应用 code/secret + ticket 或 token、独立 access_token,以及通用 headers;认证形态错误独立返回 invalid_mcp_auth 并说明支持格式。--list 成功仅代表结构有效。
  • 官方 Go SDK 固定到 12e768b461fd06ea80b0d87e14ac7fa0d24c606a(v1.8.1-0.20261022085357-12e768b461fd),兼容测试覆盖 2025-03-26、2025-06-18、2025-11-25、2026-07-28。该提交包含 structuredContent 修复,Schema/元数据仍由 HTTP 边界保留原始 JSON 数字,覆盖参数、目录、结果、envelope 和 jq 简单字段提取。
  • SDK 负责协议和会话,CLI 关闭多轮输入与自动重发,每次最多一次 tools/call。完整分页检测循环/重名/上限,null 游标视为结束;单 JSON/SSE 事件 16 MiB、累计目录 32 MiB、100 页,默认 60 秒总预算,SIGINT/SIGTERM 可取消。失败后仍允许预算内的 DELETE 清理;清理、通知及回复请求不覆盖业务响应头或错误,Mcp-Session-Id 始终脱敏。
  • 合法 JSON-RPC 错误(含 HTTP 400 等响应)使用 mcp_rpc_error,在 data.rpc_error 保留服务端 code/message;普通 HTTP 失败用 mcp_http_error,认证/权限/重定向保留专用分类;--check 阶段状态与错误类别一致。保留工具错误和未支持的 input_required/sampling/elicitation/task 状态。SSE 的 EOF 事件与 CRLF 字节上限遵循固定 SDK 行为;可判定的完整原始结果不会仅因 SDK 解码失败被标为 unknown。调用结果丢失时输出 data.execution_state: "unknown";jq/输出失败不触发重发。离线 dry-run 只接受完整 body,与 --help 互斥,零网络并标注未验证远端。参数值以 - 开头时使用 --name=value,避免短选项被吞作工具参数;--body - 继续支持 stdin。
  • 同步中英文 README、设计/用户指南、AGENTS、中文 MCP skill 和五组 Docker 集成场景。现有 API/system 请求契约不变。

验证:Go 1.25.8;make fmt、make lint、make test(28 suites)、make build、Windows amd64 交叉构建、相关 race 检查通过。本轮 10 项修复具有修改前失败、修改后通过的证据;SIGTERM 通过本地 mock + 子进程信号验证。MCP-001 至 MCP-005 Docker 场景通过,HTTP helper 提取后再次执行 MCP-003 CASE,覆盖 SSE EOF 结果保留和 HTTP 400 RPC 错误。internal/mcpclient 覆盖率 95.5%。独立复核未发现新增缺陷。

make test-cover 未整体通过:未改动的 internal/update 覆盖率为 88.5%,低于 90% 门槛;基线 9f834ab08438090ee9bee3111ff5158f94847c55 干净副本也为 88.5%。本 PR 不修改该包或阈值。真实服务联调未执行,认证与协议兼容以本地 mock 为证;集成测试文档提供人工验收清单。ok:true 不证明任意业务成功或异步任务完成。

Closes #42.

@wklken wklken changed the title feat(mcp): add configuration and lossless argument foundations for #42 feat(mcp): add remote discovery and single-call tool execution Oct 22, 2026
Comment thread README.md Outdated
Comment thread skills/bk-cli-mcp/SKILL.md Outdated
Comment thread skills/bk-cli-mcp/SKILL.md
Comment thread docs/user-guide.md Outdated
Comment thread docs/user-guide.md Outdated
Retain server RPC code/message, distinguish invalid authentication from
configuration errors, and report safe server/field diagnostics. Allow
bounded DELETE cleanup without replacing operation response headers and
mask session IDs. Accept null pagination cursors and reject help combined
with offline preview before network access.

Keep explicit HTTP configuration and existing authentication combinations.
Add regression and integration coverage for the six reviewed findings.
Flush SDK-compatible SSE events at EOF and count complete CRLF sequences.
Reject implicit flag tokens as values before network access, classify raw
results before SDK decoding errors, and preserve RPC errors in HTTP error
responses. Separate auxiliary request state and align check-stage labels
with connection errors. Distinguish HTTP failures and handle SIGTERM.

Add regression and integration coverage for the verified review findings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): 支持基于 mcp.json 的 MCP 工具检查、发现与调用(一期设计)

1 participant