Repository navigation
feat(mcp): Go 控制平面的 MCP Server v1 - #73
Merged
Merged
Conversation
stdio-only JSON-RPC 2.0 服务端(协议 2025-06-18):initialize 握手与 capability 诚实声明、tools/list+tools/call(read_file/list_workspace 经 Tool Gateway 转发)、resources/list+resources/read(run 摘要与公开活动投影)、ping、notifications/cancelled。 边界:4 MiB/UTF-8/严格解码、请求 id 会话内唯一(重放拒绝)、并发上限、单请求超时、capability TTL;并发请求在 stdio 读循环注册、握手同步化以保证取消确定性;审计经 RecordMCPAudit 写入 run_events(closed 事件类型,不落 Secret/raw output);client 无法携带 executable/path/credential/权限档位。
MCP Server v1 的协议/边界/审计决策记录、usage.md 的 MCP 章节(stdio 接线与 client 配置示例)、configs/mcp-client.example.json 启动器示例。
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Issue #52(epic #36 的首个子任务):为 Go 控制平面提供 MCP Server v1,让编辑器/桌面 Agent 等本地客户端以标准 MCP 协议接入,但绝不形成绕过 CLI/HTTP/Run 生命周期的第二控制平面。协议与边界:stdio-only(newline-delimited JSON-RPC 2.0)、协议版本 2025-06-18、capability 声明 == 实现。
本次改动
internal/mcp包:protocol.go(4 MiB/UTF-8/严格解码、错误码)、messages.go(initialize 握手、tools/resources 消息与严格 params 解码)、server.go(stdio 循环、并发注册、TTL、重放拒绝、cancelled)、tools.go(read_file/list_workspace 经 Tool Gateway 转发,只回传 redaction 后的 status/exit_code/bounded metadata)、resources.go(cyberagent://run/summary与cyberagent://run/activity只读投影)。RecordMCPAudit:审计写入既有 run_events(source=mcp_server,closed 事件类型 mcp.initialized/resource_read/tool_denied/tool_completed),payload 有界化,Secret/raw output 绝不入事件;无需新 schema 迁移。cyberagent mcp serve --run --workspace [--max-concurrent 8] [--call-timeout 30s] [--session-ttl 24h]CLI;每个进程实例绑定一个 Run + Workspace Scope。notifications/cancelled真实可达且确定性可测。测试覆盖
internal/mcp/server_test.go:握手 gating 与 capabilities、catalog、malformed/oversized/重复 id 重放拒绝、工具转发+审计、undeclared tool 拒绝、TTL 过期、单请求超时、cancelled 取消、并发上限。internal/store/mcp_audit_test.go:审计事件落库、payload 有界化(不泄漏 raw output)、非法事件类型与缺失 Run 拒绝。验证结果
go build ./...、go vet ./...通过。go test -timeout 30m ./...全绿(含 analyzer conformance env 配置)。go test -race ./internal/mcp/ ./internal/store/ -run 'TestMCP|TestRecordMCPAudit'通过。generate:api/typecheck/test/build 通过(本 PR 无 web 代码变更)。安全边界与非目标
Closes #52