ACP / MCP

This commit is contained in:
2026-06-12 11:44:19 +08:00
parent 2a9661a6ef
commit 4ea4adfd8e
47 changed files with 2558 additions and 240 deletions
+45 -6
View File
@@ -1,17 +1,56 @@
package handlers
// session/new method types (spec §5.4).
// session/new method types (spec §5.4 + ACP v1 schema/v1/schema.json)。
//
// mcpServers 元素是 untagged union:
// - stdio:无 type 判别字段(v1 规定;带 type 会被部分 agent 忽略),
// name/command/args/env 全必填(空数组可)
// - http / sse:type 为 "http"/"sse" 判别符,name/url/headers 必填
//
// env / headers 均为 [{name,value}] 数组(非对象)。
type SessionNewParams struct {
Cwd string `json:"cwd"`
McpServers []string `json:"mcpServers"` // MVP: no MCP, send empty slice
Cwd string `json:"cwd"`
McpServers []any `json:"mcpServers"` // McpServerStdio | McpServerHTTP
}
type SessionNewResult struct {
SessionID string `json:"sessionId"`
}
// BuildSessionNewParams returns standard session/new params.
func BuildSessionNewParams(cwd string) SessionNewParams {
return SessionNewParams{Cwd: cwd, McpServers: []string{}}
// EnvVariable / HttpHeader 是 ACP wire 的 name-value 对。
type EnvVariable struct {
Name string `json:"name"`
Value string `json:"value"`
}
type HttpHeader struct {
Name string `json:"name"`
Value string `json:"value"`
}
// McpServerStdio 是 stdio 传输的 MCP server(基线,所有 agent 必须支持)。
type McpServerStdio struct {
Name string `json:"name"`
Command string `json:"command"`
Args []string `json:"args"`
Env []EnvVariable `json:"env"`
}
// McpServerHTTP 是 http / sse 传输的 MCP server。Type 必须为 "http" 或 "sse",
// 仅当 agent 在 initialize 中声明对应 mcpCapabilities 时才可下发。
type McpServerHTTP struct {
Type string `json:"type"`
Name string `json:"name"`
URL string `json:"url"`
Headers []HttpHeader `json:"headers"`
}
// BuildSessionNewParams returns standard session/new params.
// servers 为 nil 时发送空数组(mcpServers 是协议必填字段)。
func BuildSessionNewParams(cwd string, servers []any) SessionNewParams {
if servers == nil {
servers = []any{}
}
return SessionNewParams{Cwd: cwd, McpServers: servers}
}