renderCopilotMCPConfigWithContext generates custom MCP server configuration for Copilot CLI 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)
| 44 | // renderCopilotMCPConfigWithContext generates custom MCP server configuration for Copilot CLI |
| 45 | // This version includes workflowData to determine if localhost URLs should be rewritten |
| 46 | func (e *CopilotEngine) renderCopilotMCPConfigWithContext(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool, workflowData *WorkflowData) error { |
| 47 | copilotMCPLog.Printf("Rendering custom MCP config for tool: %s", toolName) |
| 48 | |
| 49 | // Determine if localhost URLs should be rewritten to host.docker.internal |
| 50 | // This is needed when firewall is enabled (agent is not disabled) |
| 51 | rewriteLocalhost := shouldRewriteLocalhostToDocker(workflowData) |
| 52 | copilotMCPLog.Printf("Localhost URL rewriting for tool %s: enabled=%t", toolName, rewriteLocalhost) |
| 53 | |
| 54 | // Use the shared renderer with copilot-specific requirements |
| 55 | renderer := MCPConfigRenderer{ |
| 56 | Format: "json", |
| 57 | IndentLevel: " ", |
| 58 | RequiresCopilotFields: true, |
| 59 | RewriteLocalhostToDocker: rewriteLocalhost, |
| 60 | GuardPolicies: deriveWriteSinkGuardPolicyFromWorkflow(workflowData), |
| 61 | } |
| 62 | |
| 63 | yaml.WriteString(" \"" + toolName + "\": {\n") |
| 64 | |
| 65 | // Use shared renderer for the server configuration |
| 66 | if err := renderSharedMCPConfig(yaml, toolName, toolConfig, renderer); err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | if isLast { |
| 71 | yaml.WriteString(" }\n") |
| 72 | } else { |
| 73 | yaml.WriteString(" },\n") |
| 74 | } |
| 75 | |
| 76 | return nil |
| 77 | } |
no test coverage detected