Skip to content

fix: forward RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE to spawned agent MCP config#583

Merged
khaliqgant merged 8 commits into
mainfrom
fix/relaycast-mcp-workspace-forwarding
Mar 18, 2026
Merged

fix: forward RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE to spawned agent MCP config#583
khaliqgant merged 8 commits into
mainfrom
fix/relaycast-mcp-workspace-forwarding

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Mar 18, 2026

Copy link
Copy Markdown
Member

Summary

  • PR fix: ensure spawned Claude agents get proper MCP config #581 fixed RELAY_API_KEY missing from spawned agent --mcp-config JSON, but RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE were still read via std::env::var inside relaycast_server_config
  • In agent-relay up mode, the broker process does not have these vars in its own env — they only exist in worker_env passed to child processes
  • This meant spawned agents' --mcp-config JSON was missing workspace context, so relaycast MCP tools couldn't resolve the correct workspace

Changes

Thread workspaces_json and default_workspace as explicit parameters through the MCP config building chain instead of reading from std::env::var:

  • src/snippets.rs: New params on relaycast_server_config, merge_relaycast_with_project_mcp(_inner), and configure_relaycast_mcp_with_token; public configure_relaycast_mcp wrapper passes None, None for backward compat
  • src/main.rs: Both WorkerRegistry::spawn paths (PTY + Headless) now extract RELAY_WORKSPACES_JSON / RELAY_DEFAULT_WORKSPACE from self.worker_env and pass them through
  • src/spawner.rs: spawn_wrap_with_token now extracts the same vars from env_vars and passes them through

Tests

5 new tests added (63 total, all pass):

  • relaycast_server_config_includes_workspaces_json_when_provided
  • relaycast_server_config_includes_default_workspace_when_provided
  • relaycast_server_config_empty_workspace_vars_omitted
  • merge_relaycast_injects_workspace_vars
  • configure_relaycast_mcp_with_token_passes_workspace_vars

Test plan

  • cargo build — clean
  • cargo test --lib -- snippets — 63 passed, 0 failed
  • Verified via workflows/fix-mcp-spawn.yaml DAG workflow (diagnose → implement → build-check → run-tests → review)

🤖 Generated with Claude Code


Open with Devin

…wned agent MCP config

PR #581 injected RELAY_API_KEY into the --mcp-config JSON for spawned agents,
but RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE were still read via
std::env::var inside relaycast_server_config. In "up" mode, the broker process
does not have these vars in its own env — they only exist in worker_env passed
to child processes.

Thread workspaces_json and default_workspace explicitly through:
- relaycast_server_config: new params replace std::env::var reads
- merge_relaycast_with_project_mcp(_inner): pass-through params added
- configure_relaycast_mcp_with_token: new params, callers updated
- WorkerRegistry::spawn (PTY + Headless): extract from self.worker_env
- Spawner::spawn_wrap_with_token: extract from env_vars

Adds 5 new tests (63 total pass).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

khaliqgant and others added 2 commits March 18, 2026 10:43
Codex, OpenCode, and Gemini/Droid paths were reading RELAY_WORKSPACES_JSON
and RELAY_DEFAULT_WORKSPACE from std::env::var instead of using the
function parameters. This broke workspace forwarding for agents spawned
from the broker's 'up' mode where these vars only exist in worker_env.

- Codex: use workspaces_json/default_workspace params
- OpenCode: add params to ensure_opencode_config signature
- Gemini/Droid: add params to gemini_droid_mcp_add_args and
  configure_gemini_droid_mcp signatures
- Update all call sites and test fixtures

All 505 tests pass.
devin-ai-integration[bot]

This comment was marked as resolved.

khaliqgant and others added 2 commits March 18, 2026 10:54
…on_with_token

Cursor path was missed in the initial fix — ensure_cursor_mcp_config
and relaycast_mcp_config_json_with_token now accept and forward
workspaces_json/default_workspace params. All CLI paths (Claude,
Codex, OpenCode, Gemini, Droid, Cursor) consistently use function
parameters instead of std::env::var.
devin-ai-integration[bot]

This comment was marked as resolved.

- Add RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE to env var list
- Document workspace variable forwarding rule: always use function
  params, never std::env::var()
- Add table of all functions that accept workspace params
- Add Cursor to CLI Provider Support Matrix
@khaliqgant khaliqgant merged commit 45b8aa4 into main Mar 18, 2026
39 of 40 checks passed
@khaliqgant khaliqgant deleted the fix/relaycast-mcp-workspace-forwarding branch March 18, 2026 10:38
khaliqgant added a commit that referenced this pull request Mar 25, 2026
…wned agent MCP config (#583)

* fix: forward RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE to spawned agent MCP config

PR #581 injected RELAY_API_KEY into the --mcp-config JSON for spawned agents,
but RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE were still read via
std::env::var inside relaycast_server_config. In "up" mode, the broker process
does not have these vars in its own env — they only exist in worker_env passed
to child processes.

Thread workspaces_json and default_workspace explicitly through:
- relaycast_server_config: new params replace std::env::var reads
- merge_relaycast_with_project_mcp(_inner): pass-through params added
- configure_relaycast_mcp_with_token: new params, callers updated
- WorkerRegistry::spawn (PTY + Headless): extract from self.worker_env
- Spawner::spawn_wrap_with_token: extract from env_vars

Adds 5 new tests (63 total pass).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* style: auto-format Rust code with cargo fmt

* fix: use function params instead of std::env::var for workspace vars

Codex, OpenCode, and Gemini/Droid paths were reading RELAY_WORKSPACES_JSON
and RELAY_DEFAULT_WORKSPACE from std::env::var instead of using the
function parameters. This broke workspace forwarding for agents spawned
from the broker's 'up' mode where these vars only exist in worker_env.

- Codex: use workspaces_json/default_workspace params
- OpenCode: add params to ensure_opencode_config signature
- Gemini/Droid: add params to gemini_droid_mcp_add_args and
  configure_gemini_droid_mcp signatures
- Update all call sites and test fixtures

All 505 tests pass.

* style: auto-format Rust code with cargo fmt

* fix: thread workspace vars through Cursor and relaycast_mcp_config_json_with_token

Cursor path was missed in the initial fix — ensure_cursor_mcp_config
and relaycast_mcp_config_json_with_token now accept and forward
workspaces_json/default_workspace params. All CLI paths (Claude,
Codex, OpenCode, Gemini, Droid, Cursor) consistently use function
parameters instead of std::env::var.

* style: auto-format Rust code with cargo fmt

* docs: update mcp-injection rule with workspace var forwarding pattern

- Add RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE to env var list
- Document workspace variable forwarding rule: always use function
  params, never std::env::var()
- Add table of all functions that accept workspace params
- Add Cursor to CLI Provider Support Matrix

* fix: suppress clippy::too_many_arguments for workspace-forwarding functions

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant