renderCustomMCPConfigWrapperWithContext generates custom MCP server configuration wrapper with workflow context This version includes workflowData to determine if localhost URLs should be rewritten
(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool, workflowData *WorkflowData)
| 19 | // renderCustomMCPConfigWrapperWithContext generates custom MCP server configuration wrapper with workflow context |
| 20 | // This version includes workflowData to determine if localhost URLs should be rewritten |
| 21 | func renderCustomMCPConfigWrapperWithContext(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool, workflowData *WorkflowData) error { |
| 22 | mcpCustomLog.Printf("Rendering custom MCP config wrapper with context for tool: %s", toolName) |
| 23 | fmt.Fprintf(yaml, " \"%s\": {\n", toolName) |
| 24 | |
| 25 | // Determine if localhost URLs should be rewritten to host.docker.internal |
| 26 | // This is needed when firewall is enabled (agent is not disabled) |
| 27 | rewriteLocalhost := shouldRewriteLocalhostToDocker(workflowData) |
| 28 | |
| 29 | // Use the shared MCP config renderer with JSON format |
| 30 | renderer := MCPConfigRenderer{ |
| 31 | IndentLevel: " ", |
| 32 | Format: "json", |
| 33 | RewriteLocalhostToDocker: rewriteLocalhost, |
| 34 | GuardPolicies: deriveWriteSinkGuardPolicyFromWorkflow(workflowData), |
| 35 | } |
| 36 | |
| 37 | err := renderSharedMCPConfig(yaml, toolName, toolConfig, renderer) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | |
| 42 | if isLast { |
| 43 | yaml.WriteString(" }\n") |
| 44 | } else { |
| 45 | yaml.WriteString(" },\n") |
| 46 | } |
| 47 | |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | // renderCustomMCPEnvVars normalizes custom MCP env values for the target output |
| 52 | // format before serialization. |