Skip to content

Commit bb2272d

Browse files
committed
add settings and mcp configurations
1 parent ffd192f commit bb2272d

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

pkg/agentrun-harness/tool/claude/claude.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func (in *Claude) Run(ctx context.Context, options ...exec.Option) {
6868
}
6969

7070
func (in *Claude) Configure(consoleURL, consoleToken, deployToken string) error {
71+
mcp := NewMCPConfigBuilder()
72+
mcp.
73+
AddServer("plural", "mcpserver").
74+
Env("PLRL_CONSOLE_TOKEN", consoleToken).
75+
Env("PLRL_CONSOLE_URL", consoleURL).
76+
Done()
77+
if err := mcp.WriteToFile(filepath.Join(in.configPath(), ".claude.json")); err != nil {
78+
return err
79+
}
80+
7181
settings := NewSettingsBuilder()
7282
if in.run.Mode == console.AgentRunModeAnalyze {
7383
settings.AllowTools(

pkg/agentrun-harness/tool/claude/claude_templates.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,83 @@ func (b *SettingsBuilder) WriteToFile(path string) error {
8787

8888
return nil
8989
}
90+
91+
type MCPConfig struct {
92+
MCPServers map[string]MCPServer `json:"mcpServers"`
93+
}
94+
95+
type MCPServer struct {
96+
Command string `json:"command"`
97+
Args []string `json:"args,omitempty"`
98+
Env map[string]string `json:"env,omitempty"`
99+
}
100+
101+
type MCPConfigBuilder struct {
102+
cfg MCPConfig
103+
}
104+
105+
func NewMCPConfigBuilder() *MCPConfigBuilder {
106+
return &MCPConfigBuilder{
107+
cfg: MCPConfig{
108+
MCPServers: make(map[string]MCPServer),
109+
},
110+
}
111+
}
112+
113+
func (b *MCPConfigBuilder) AddServer(name, command string) *MCPServerBuilder {
114+
return &MCPServerBuilder{
115+
parent: b,
116+
name: name,
117+
server: MCPServer{Command: command, Env: map[string]string{}},
118+
}
119+
}
120+
121+
func (b *MCPConfigBuilder) Build() MCPConfig {
122+
return b.cfg
123+
}
124+
125+
func (b *MCPConfigBuilder) ToJSON() ([]byte, error) {
126+
return json.MarshalIndent(b.cfg, "", " ")
127+
}
128+
129+
func (b *MCPConfigBuilder) WriteToFile(path string) error {
130+
// Create directory if needed
131+
dir := filepath.Dir(path)
132+
if err := os.MkdirAll(dir, 0755); err != nil {
133+
return fmt.Errorf("failed to create directory: %w", err)
134+
}
135+
136+
// Marshal with indentation
137+
data, err := json.MarshalIndent(b.cfg, "", " ")
138+
if err != nil {
139+
return fmt.Errorf("failed to marshal settings: %w", err)
140+
}
141+
142+
// Write to file
143+
if err := os.WriteFile(path, data, 0644); err != nil {
144+
return fmt.Errorf("failed to write file: %w", err)
145+
}
146+
147+
return nil
148+
}
149+
150+
type MCPServerBuilder struct {
151+
parent *MCPConfigBuilder
152+
name string
153+
server MCPServer
154+
}
155+
156+
func (sb *MCPServerBuilder) Args(args ...string) *MCPServerBuilder {
157+
sb.server.Args = args
158+
return sb
159+
}
160+
161+
func (sb *MCPServerBuilder) Env(key, value string) *MCPServerBuilder {
162+
sb.server.Env[key] = value
163+
return sb
164+
}
165+
166+
func (sb *MCPServerBuilder) Done() *MCPConfigBuilder {
167+
sb.parent.cfg.MCPServers[sb.name] = sb.server
168+
return sb.parent
169+
}

0 commit comments

Comments
 (0)