renderCodexJSONMCPConfigWithContext generates custom MCP server configuration in JSON format for gateway This is used to generate the JSON config file that the MCP gateway reads
(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool, workflowData *WorkflowData)
| 226 | // renderCodexJSONMCPConfigWithContext generates custom MCP server configuration in JSON format for gateway |
| 227 | // This is used to generate the JSON config file that the MCP gateway reads |
| 228 | func (e *CodexEngine) renderCodexJSONMCPConfigWithContext(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool, workflowData *WorkflowData) error { |
| 229 | // Determine if localhost URLs should be rewritten to host.docker.internal |
| 230 | rewriteLocalhost := shouldRewriteLocalhostToDocker(workflowData) |
| 231 | codexMCPLog.Printf("Rendering JSON MCP config for gateway tool: %s (isLast=%v, rewrite_localhost=%v)", toolName, isLast, rewriteLocalhost) |
| 232 | |
| 233 | // Use the shared renderer with JSON format for gateway |
| 234 | renderer := MCPConfigRenderer{ |
| 235 | Format: "json", |
| 236 | IndentLevel: " ", |
| 237 | RewriteLocalhostToDocker: rewriteLocalhost, |
| 238 | GuardPolicies: deriveWriteSinkGuardPolicyFromWorkflow(workflowData), |
| 239 | } |
| 240 | |
| 241 | yaml.WriteString(" \"" + toolName + "\": {\n") |
| 242 | |
| 243 | err := renderSharedMCPConfig(yaml, toolName, toolConfig, renderer) |
| 244 | if err != nil { |
| 245 | codexMCPLog.Printf("Failed to render JSON MCP config for tool %s: %v", toolName, err) |
| 246 | return err |
| 247 | } |
| 248 | |
| 249 | if isLast { |
| 250 | yaml.WriteString(" }\n") |
| 251 | } else { |
| 252 | yaml.WriteString(" },\n") |
| 253 | } |
| 254 | |
| 255 | return nil |
| 256 | } |
no test coverage detected