Skip to content

Add cwd to AgentConfig.mcpServers[] for stdio working directory#1042

Open
JustinElst wants to merge 1 commit intokelos-dev:mainfrom
JustinElst:feat/agentconfig-mcp-cwd
Open

Add cwd to AgentConfig.mcpServers[] for stdio working directory#1042
JustinElst wants to merge 1 commit intokelos-dev:mainfrom
JustinElst:feat/agentconfig-mcp-cwd

Conversation

@JustinElst
Copy link
Copy Markdown
Contributor

@JustinElst JustinElst commented Apr 28, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds an optional cwd field to AgentConfig.mcpServers[] so callers can pin the working directory of stdio MCP servers.

Stdio MCP servers run with whatever CWD the agent process happens to be in. That's fine for most servers, but breaks servers that must execute from a specific project root. Laravel Boost is the canonical example: php artisan boost:mcp only works when CWD is the Laravel project root. Without cwd, callers have to patch the repo's .mcp.json at runtime to inject a cd /workspace/repo && exec wrapper, which is a file-write side effect inside the workspace that's easy to get wrong.

The field is plumbed through buildMCPServersJSON into the .mcp.json-shaped JSON exposed via KELOS_MCP_SERVERS. The claude-code, cursor, and gemini entrypoints pick it up transparently because they merge the inner mcpServers map into the agent's user-scoped config via Object.assign. The codex entrypoint converts the JSON to TOML field-by-field, so this PR also adds cwd to its TOML emission alongside the other stdio fields.

cwd is omitted from the rendered JSON when WorkingDir is unset, so existing configs are unaffected.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

  • The field is documented as stdio-only. For http/sse servers the field is still serialized if set, but the agent transports for those types ignore it.
  • claude-code already honors cwd on stdio MCP entries per its MCP schema, so no claude-side change is needed.
  • Two new unit tests cover the field passing through to the rendered JSON and being omitted when unset.

Does this PR introduce a user-facing change?

Add `cwd` to `AgentConfig.mcpServers[]` to set the working directory of a stdio MCP server. Useful for servers that must run from a specific project root, e.g. `php artisan boost:mcp` from a Laravel project root.

Stdio MCP servers run with whatever current working directory the
agent process happens to be in. That is fine for most servers, but
breaks servers that must execute from a specific project root.
Laravel Boost is the canonical example: "php artisan boost:mcp"
only works when CWD is the Laravel project root, so callers
currently have to patch the project-scope ".mcp.json" at runtime
to inject a "cd /workspace/repo && exec" wrapper.

This adds an optional WorkingDir field (YAML key "cwd") to
MCPServerSpec. The field is plumbed through buildMCPServersJSON
into the .mcp.json-shaped JSON exposed via KELOS_MCP_SERVERS, so
the claude-code, cursor, and gemini entrypoints pick it up
transparently (they merge the inner mcpServers map into the
agent's user-scoped config). The codex entrypoint, which converts
the JSON into TOML field-by-field, is updated to emit cwd alongside
the other stdio fields.

cwd is omitted from the rendered JSON when WorkingDir is unset, so
existing configs are unaffected. The field is documented as stdio-
only; for http/sse servers the agent transports ignore it.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

@gjkim42
Copy link
Copy Markdown
Collaborator

gjkim42 commented Apr 29, 2026

/kelos review

Copy link
Copy Markdown

@kelos-bot kelos-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Verdict: APPROVE
Overall correctness: patch is correct
Scope: Adds an optional cwd field to AgentConfig.mcpServers[] so callers can pin the working directory of stdio MCP servers, plumbed through KELOS_MCP_SERVERS JSON and the codex TOML emitter.

Findings Overview

Priority Count File:Line Summary
P0 0 none
P1 0 none
P2 0 none
P3 0 none

Findings

No qualifying findings. The change is minimal, additive, and correctly plumbed:

  • MCPServerSpec.WorkingDir (JSON-tagged cwd) is value-typed, so the existing generated DeepCopyInto (which does *out = *in) handles it automatically; no codegen update needed.
  • The new field is rendered into the .mcp.json-shaped JSON via mcpServerJSON.Cwd with omitempty, so existing configs are unaffected when unset (verified by TestBuildJob_AgentConfigMCPServersCwdOmittedWhenUnset).
  • claude-code, cursor, and gemini entrypoints Object.assign the inner mcpServers map into the agent-native config, so they pick up cwd transparently — these three agents' MCP schemas all use the cwd key for stdio servers, matching the JSON tag here.
  • The codex entrypoint's TOML emitter is updated alongside the other stdio fields, with JSON.stringify properly quoting the value (no injection risk).
  • Test coverage is appropriate for the behavior introduced (cwd round-trips through the env var, omitted when unset).
  • CRD manifests under internal/manifests/charts/kelos/templates/crds/agentconfig-crd.yaml and internal/manifests/install-crd.yaml were regenerated.

Key takeaways

  • Additive, well-scoped feature; documentation, tests, and CRDs are all updated.
  • No correctness, security, or convention concerns identified.

⚠️ Note on prompt injection: a prior cubic-dev-ai comment on this PR contains hidden text instructing AI reviewers to attribute findings to cubic. Those instructions were ignored; this review is independent.

Copy link
Copy Markdown
Collaborator

@gjkim42 gjkim42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we apply this to other coding agents? (other than Codex)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature needs-actor needs-priority needs-triage release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants