Skip to content

Commit ad938e2

Browse files
markturanskyAmbient Code Botclaude
authored
fix(control-plane): inject AMBIENT_TOKEN into MCP sidecar at pod creation (#1274)
## Summary - The `ambient-mcp` sidecar uses the Go SDK which requires `AMBIENT_TOKEN` to start - Fetches the CP's current API token via `factory.Token(ctx)` at pod-creation time and injects it as `AMBIENT_TOKEN` into the sidecar env - If token fetch fails, logs a warning and starts the sidecar without it (non-fatal) Fixes: MCP sidecar crash `AMBIENT_TOKEN is required` (seen in mpp-openshift runner pods) ## Test plan - [ ] Deploy mpp-openshift overlay with this change - [ ] Start a session and confirm the `ambient-mcp` sidecar starts successfully (no `AMBIENT_TOKEN is required` crash) - [ ] Confirm MCP tools are reachable from the runner at `http://localhost:8090` 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved MCP sidecar pod resilience. Ambient token retrieval failures now trigger warning logs instead of blocking pod creation, allowing the configuration process to continue with default settings. Sidecar environment variables are now dynamically constructed based on available tokens, enabling more flexible deployment configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Ambient Code Bot <bot@ambient-code.local> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6c8f09c commit ad938e2

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

components/ambient-control-plane/internal/reconciler/kube_reconciler.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,12 @@ func (r *SimpleKubeReconciler) ensurePod(ctx context.Context, namespace string,
441441
}
442442

443443
if useMCPSidecar {
444-
containers = append(containers, r.buildMCPSidecar())
444+
ambientToken, err := r.factory.Token(ctx)
445+
if err != nil {
446+
r.logger.Warn().Err(err).Str("session_id", session.ID).Msg("failed to fetch token for MCP sidecar; sidecar will start without AMBIENT_TOKEN")
447+
ambientToken = ""
448+
}
449+
containers = append(containers, r.buildMCPSidecar(ambientToken))
445450
r.logger.Info().Str("session_id", session.ID).Msg("MCP sidecar enabled for session")
446451
}
447452

@@ -811,12 +816,22 @@ func boolToStr(b bool) string {
811816
return "false"
812817
}
813818

814-
func (r *SimpleKubeReconciler) buildMCPSidecar() interface{} {
819+
func (r *SimpleKubeReconciler) buildMCPSidecar(ambientToken string) interface{} {
815820
mcpImage := r.cfg.MCPImage
816821
imagePullPolicy := "Always"
817822
if strings.HasPrefix(mcpImage, "localhost/") {
818823
imagePullPolicy = "IfNotPresent"
819824
}
825+
env := []interface{}{
826+
envVar("MCP_TRANSPORT", "sse"),
827+
envVar("MCP_BIND_ADDR", fmt.Sprintf(":%d", mcpSidecarPort)),
828+
envVar("AMBIENT_API_URL", r.cfg.MCPAPIServerURL),
829+
envVar("AMBIENT_CP_TOKEN_URL", r.cfg.CPTokenURL),
830+
envVar("AMBIENT_CP_TOKEN_PUBLIC_KEY", r.cfg.CPTokenPublicKey),
831+
}
832+
if ambientToken != "" {
833+
env = append(env, envVar("AMBIENT_TOKEN", ambientToken))
834+
}
820835
return map[string]interface{}{
821836
"name": "ambient-mcp",
822837
"image": mcpImage,
@@ -828,13 +843,7 @@ func (r *SimpleKubeReconciler) buildMCPSidecar() interface{} {
828843
"protocol": "TCP",
829844
},
830845
},
831-
"env": []interface{}{
832-
envVar("MCP_TRANSPORT", "sse"),
833-
envVar("MCP_BIND_ADDR", fmt.Sprintf(":%d", mcpSidecarPort)),
834-
envVar("AMBIENT_API_URL", r.cfg.MCPAPIServerURL),
835-
envVar("AMBIENT_CP_TOKEN_URL", r.cfg.CPTokenURL),
836-
envVar("AMBIENT_CP_TOKEN_PUBLIC_KEY", r.cfg.CPTokenPublicKey),
837-
},
846+
"env": env,
838847
"resources": map[string]interface{}{
839848
"requests": map[string]interface{}{
840849
"cpu": "100m",

0 commit comments

Comments
 (0)