From b9522ae3bf0f24c0a2558c4e4abb7936626c118c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Salavisa?= Date: Sat, 7 Feb 2026 11:35:39 +0000 Subject: [PATCH] fix: pass MCP configuration to Claude Code via --mcp-config flag (#205) --- .../adapter/transport/streamjson/adapter.go | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/apps/backend/internal/agentctl/server/adapter/transport/streamjson/adapter.go b/apps/backend/internal/agentctl/server/adapter/transport/streamjson/adapter.go index 6474eb7101..118e9bf113 100644 --- a/apps/backend/internal/agentctl/server/adapter/transport/streamjson/adapter.go +++ b/apps/backend/internal/agentctl/server/adapter/transport/streamjson/adapter.go @@ -147,9 +147,51 @@ func (a *Adapter) PrepareEnvironment() (map[string]string, error) { } // PrepareCommandArgs returns extra command-line arguments for the agent process. -// For stream-json, no extra args are needed - MCP is configured via config files. +// For stream-json (Claude Code), MCP configuration is passed via --mcp-config flag. func (a *Adapter) PrepareCommandArgs() []string { - return nil + if len(a.cfg.McpServers) == 0 { + return nil + } + + // Build MCP configuration in Claude Code format + // Format: { "server-name": { "command": "...", "args": [...] } } + mcpConfig := make(map[string]interface{}) + for _, server := range a.cfg.McpServers { + serverDef := make(map[string]interface{}) + + // Handle different transport types + if server.Command != "" { + // stdio transport + serverDef["command"] = server.Command + if len(server.Args) > 0 { + serverDef["args"] = server.Args + } + } else if server.URL != "" { + // SSE/HTTP transport + serverDef["url"] = server.URL + if server.Type != "" { + serverDef["type"] = server.Type + } + } + + mcpConfig[server.Name] = serverDef + } + + // Convert to JSON string + configJSON, err := json.Marshal(mcpConfig) + if err != nil { + a.logger.Warn("failed to marshal MCP config, skipping", + zap.Error(err), + zap.Int("server_count", len(a.cfg.McpServers))) + return nil + } + + a.logger.Info("prepared MCP configuration for Claude Code", + zap.Int("server_count", len(a.cfg.McpServers)), + zap.String("config", string(configJSON))) + + // Return --mcp-config flag with JSON string + return []string{"--mcp-config", string(configJSON)} } // Connect wires up the stdin/stdout pipes from the running agent subprocess.