You've already forked agentic-coding-workflow
ACP / MCP
This commit is contained in:
@@ -31,6 +31,18 @@ type InitializeResult struct {
|
||||
AuthMethods []any `json:"authMethods,omitempty"`
|
||||
}
|
||||
|
||||
// McpCapabilities 从 agentCapabilities.mcpCapabilities 解析 http/sse 支持声明
|
||||
// (ACP v1:均默认 false;stdio 是基线无需声明)。字段缺失或形状异常按 false 处理。
|
||||
func (r InitializeResult) McpCapabilities() (httpOK, sseOK bool) {
|
||||
caps, ok := r.AgentCapabilities["mcpCapabilities"].(map[string]any)
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
httpOK, _ = caps["http"].(bool)
|
||||
sseOK, _ = caps["sse"].(bool)
|
||||
return httpOK, sseOK
|
||||
}
|
||||
|
||||
// BuildInitializeParams returns standard initialize params.
|
||||
func BuildInitializeParams(version string) InitializeParams {
|
||||
return InitializeParams{
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user