-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathmcp.go
More file actions
85 lines (77 loc) · 2.24 KB
/
mcp.go
File metadata and controls
85 lines (77 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package acpio
import (
"slices"
"github.com/coder/acp-go-sdk"
"golang.org/x/xerrors"
)
// AgentapiMcpConfig represents the Claude MCP JSON format where mcpServers is a map
// with server names as keys.
type AgentapiMcpConfig struct {
McpServers map[string]AgentapiMcpServer `json:"mcpServers"`
}
// AgentapiMcpServer represents a single MCP server in Claude's format.
type AgentapiMcpServer struct {
// Type can be "stdio", "sse" or "http"
Type string `json:"type"`
// Stdio transport fields
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
// HTTP | SSE transport fields
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
// convertAgentapiMcpToAcp converts a Claude MCP server config to the ACP format.
func (a *AgentapiMcpServer) convertAgentapiMcpToAcp(name string) (acp.McpServer, error) {
serverType := a.Type
acpMCPServer := acp.McpServer{}
if serverType == "stdio" {
if a.Command == "" {
return acp.McpServer{}, xerrors.Errorf("stdio server %q missing command", name)
}
// Convert env map to []EnvVariable
var envVars []acp.EnvVariable
for key, value := range a.Env {
envVars = append(envVars, acp.EnvVariable{
Name: key,
Value: value,
})
}
acpMCPServer.Stdio = &acp.McpServerStdio{
Name: name,
Command: a.Command,
Args: a.Args,
Env: envVars,
}
} else if slices.Contains([]string{"http", "sse"}, serverType) {
if a.URL == "" {
return acp.McpServer{}, xerrors.Errorf("http server %q missing url", name)
}
// Convert headers map to []HttpHeader
var headers []acp.HttpHeader
for key, value := range a.Headers {
headers = append(headers, acp.HttpHeader{
Name: key,
Value: value,
})
}
if serverType == "sse" {
acpMCPServer.Sse = &acp.McpServerSse{
Name: name,
Type: "sse",
Url: a.URL,
Headers: headers,
}
} else {
acpMCPServer.Http = &acp.McpServerHttp{
Name: name,
Type: "http",
Url: a.URL,
Headers: headers,
}
}
} else {
return acp.McpServer{}, xerrors.Errorf("unsupported server type %q for server %q", serverType, name)
}
return acpMCPServer, nil
}