Skip to content

feat(cli): add agent-relay mcp-args subcommand#759

Merged
khaliqgant merged 2 commits intomainfrom
feat/mcp-args-subcommand
Apr 20, 2026
Merged

feat(cli): add agent-relay mcp-args subcommand#759
khaliqgant merged 2 commits intomainfrom
feat/mcp-args-subcommand

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Apr 20, 2026

Expose configure_relaycast_mcp_with_token as a CLI subcommand so external consumers (cloud SandboxedStepExecutor, debugging tools) can get identical MCP wiring without reimplementing it. Delegates to the existing Rust function — zero duplication. Includes parity test asserting subcommand output matches the broker internal build_mcp_args for the same inputs. Unblocks deletion of the TypeScript MCP branching AgentWorkforce/cloud#226 added. Generated by workflows/add-mcp-args-subcommand.ts (claude plan → codex implement → cargo-test-fix-rerun → claude review).


Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@github-actions
Copy link
Copy Markdown
Contributor

Preview deployed!

Environment URL
Web https://pr-759.agentrelay.net

This preview will be cleaned up when the PR is merged or closed.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 099f01d492

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli_mcp_args.rs Outdated
Comment on lines +48 to +49
cmd.workspaces_json.as_deref(),
cmd.default_workspace.as_deref(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back to workspace env vars when flags are omitted

mcp-args currently forwards cmd.workspaces_json/cmd.default_workspace directly, so when those flags are omitted the call uses None even if RELAY_WORKSPACES_JSON and RELAY_DEFAULT_WORKSPACE are set in the environment. That diverges from the existing internal MCP wiring path (WorkerRegistry::build_mcp_args), which forwards those env values, and causes external env-driven callers to lose multi-workspace context in the generated MCP args. Add the same env fallback behavior here to preserve parity.

Useful? React with 👍 / 👎.

MCP Args Subcommand Bot and others added 2 commits April 20, 2026 15:46
Match WorkerRegistry::build_mcp_args in the broker: when callers drive
the subcommand via env (cloud's SandboxedStepExecutor exports these
from orchestrator-managed secrets), RELAY_AGENT_TOKEN /
RELAY_WORKSPACES_JSON / RELAY_DEFAULT_WORKSPACE must feed through even
if not repeated on the CLI. Without this the authority delegation
silently dropped per-worker identity in env-driven callers.

Adds a test that sets the env vars, passes None for the equivalent
flags, and asserts each sentinel value lands in the generated claude
mcp config JSON.

Addresses PR #759 Codex P2 review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@khaliqgant
Copy link
Copy Markdown
Member Author

Addressed review feedback + fixed the failing E2E.

Codex P2 — env fallback for RELAY_*

mcp-args now falls back to RELAY_AGENT_TOKEN / RELAY_WORKSPACES_JSON / RELAY_DEFAULT_WORKSPACE when the equivalent --flag is omitted, matching WorkerRegistry::build_mcp_args. Cloud's SandboxedStepExecutor exports these from orchestrator-managed secrets and didn't repeat them on the CLI, so without this the authority delegation silently dropped per-worker identity.

Added env_vars_fill_in_when_cli_flags_omitted in src/cli_mcp_args.rs which sets all five RELAY_* vars, passes None for the matching fields, and asserts each sentinel value lands in the claude mcp config JSON.

E2E Integration Test failure — rebased onto current main

The PR was branched from e480d106 (v4.0.31) before #758 (onAgentActivityChanged hook) merged. The diff made it look like #759 was reverting #758's SDK changes, which caused agent-relay history to hang for 5 min in CI. Rebased onto current origin/main so the branch is now two clean commits (a6d0f777 subcommand + f2f43a25 env fallback) on top of main.

Local cargo test --bin agent-relay-broker -- mcp_args → 11 passed, 2 ignored (droid/gemini require external binaries).

@khaliqgant khaliqgant merged commit 494d5c0 into main Apr 20, 2026
47 checks passed
@khaliqgant khaliqgant deleted the feat/mcp-args-subcommand branch April 20, 2026 14:10
khaliqgant added a commit that referenced this pull request Apr 20, 2026
* feat(cli): add --register flag to mcp-args subcommand

Composes RelaycastHttpClient::register_agent_token with
configure_relaycast_mcp_with_token so external consumers (cloud's
SandboxedStepExecutor) can mint an at_live_* token and build MCP args
in a single exec, without reimplementing relaycast registration.

Output JSON gains an optional agentToken field, populated only when
--register is used. --register + --agent-token are mutually exclusive.

Follow-up to #759.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(mcp-args): address PR #760 review findings

- Validate local inputs (cwd + --existing-args JSON) BEFORE the
  --register call. A POST to /v1/agents/spawn rotates the agent's
  token on the relaycast backend, so we must not fire it when the
  request is going to fail locally anyway. (Codex P2)

  Adds register_does_not_hit_network_when_local_validation_fails:
  invalid --existing-args + --register asserts the mock spawn endpoint
  receives zero hits.

- Serialize RELAY_* env-var tests behind a module-level Mutex and
  introduce an EnvGuard RAII helper that snapshots + restores env on
  drop. Previously register_without_api_key_returns_clear_error,
  register_without_base_url_returns_clear_error,
  register_happy_path_embeds_minted_token, and
  env_vars_fill_in_when_cli_flags_omitted mutated process-global env
  without serialization; under parallel #[tokio::test] execution they
  raced, and none of them restored prior values on panic. (Codex P2)

- Correct the .trajectories/index.json entry so `path` points at the
  canonical /Users/khaliqgant/Projects/AgentWorkforce/relay location
  instead of the worktree directory, matching all other 522 entries.
  (Devin)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: MCP Register Flag Bot <agent@agent-relay.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.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