Repository navigation
fix(cli): use broker-aware agent-relay MCP for local persona spawns - #214
Conversation
The local CLI path (agentworkforce agent) was using the weaker @relaycast/mcp (npm package, self-registration) while the cloud path already used the broker binary's mcp-args --register for pre-minted tokens. This meant locally spawned personas couldn't reliably access relay MCP tools. Extract shared relay MCP resolution into packages/runtime/src/relay-mcp.ts and wire the broker-aware path into cli.ts runInteractive, with fallback to @relaycast/mcp when the broker is unavailable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
Warning Review limit reached
More reviews will be available in 26 minutes and 39 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the broker-aware relay MCP resolution logic by moving it from the cloud runtime defaults into a new shared module (packages/runtime/src/relay-mcp.ts), allowing both the cloud harness runner and the local CLI to reuse the same implementation. Additionally, the CLI has been updated to support broker-aware relay MCP injection for both Claude and Codex harnesses. Feedback on these changes highlights a potential crash in resolveAgentRelayBrokerMcpArgs if spawnAndCapture rejects, as the call is not wrapped in a try/catch block to handle execution failures gracefully.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const result = await spawnAndCapture({ | ||
| bin: broker, | ||
| args: brokerArgs, | ||
| cwd: args.cwd, | ||
| env: args.env, | ||
| timeoutMs: 15_000 | ||
| }); | ||
| if (result.exitCode !== 0) { | ||
| args.log('warn', 'harness.relay_mcp.broker_args_failed', { | ||
| broker, | ||
| exitCode: result.exitCode, | ||
| stderr: redactRelayBrokerOutput(result.stderr.trim(), args.relayMcp) | ||
| }); | ||
| return undefined; | ||
| } | ||
|
|
||
| let parsed: unknown; | ||
| try { | ||
| parsed = JSON.parse(result.output); | ||
| } catch (err) { | ||
| args.log('warn', 'harness.relay_mcp.broker_args_invalid_json', { | ||
| broker, | ||
| error: err instanceof Error ? err.message : String(err) | ||
| }); | ||
| return undefined; | ||
| } | ||
| if (!isBrokerMcpArgsOutput(parsed) || parsed.args.length === 0) { | ||
| args.log('warn', 'harness.relay_mcp.broker_args_invalid_shape', { broker }); | ||
| return undefined; | ||
| } | ||
| if (parsed.sideEffectFiles?.length) { | ||
| args.log('debug', 'harness.relay_mcp.side_effect_files', { | ||
| files: parsed.sideEffectFiles | ||
| }); | ||
| } | ||
| return parsed.args; |
There was a problem hiding this comment.
If spawnAndCapture rejects (for example, if the broker binary is missing, fails to execute, or throws a synchronous error during spawning), resolveAgentRelayBrokerMcpArgs will throw an unhandled exception. Since there is no try/catch block wrapping this call in either the CLI (packages/cli/src/cli.ts) or the cloud runtime (packages/runtime/src/cloud-defaults.ts), this will cause the entire process to crash instead of gracefully falling back to @relaycast/mcp as intended.
Wrapping the execution block in a try/catch ensures that any spawn or parsing failures are caught, logged as warnings, and gracefully return undefined to trigger the fallback path.
try {
const result = await spawnAndCapture({
bin: broker,
args: brokerArgs,
cwd: args.cwd,
env: args.env,
timeoutMs: 15_000
});
if (result.exitCode !== 0) {
args.log('warn', 'harness.relay_mcp.broker_args_failed', {
broker,
exitCode: result.exitCode,
stderr: redactRelayBrokerOutput(result.stderr.trim(), args.relayMcp)
});
return undefined;
}
let parsed: unknown;
try {
parsed = JSON.parse(result.output);
} catch (err) {
args.log('warn', 'harness.relay_mcp.broker_args_invalid_json', {
broker,
error: err instanceof Error ? err.message : String(err)
});
return undefined;
}
if (!isBrokerMcpArgsOutput(parsed) || parsed.args.length === 0) {
args.log('warn', 'harness.relay_mcp.broker_args_invalid_shape', { broker });
return undefined;
}
if (parsed.sideEffectFiles?.length) {
args.log('debug', 'harness.relay_mcp.side_effect_files', {
files: parsed.sideEffectFiles
});
}
return parsed.args;
} catch (err) {
args.log('warn', 'harness.relay_mcp.broker_args_failed', {
broker,
error: err instanceof Error ? err.message : String(err)
});
return undefined;
}|
Reviewed the PR diff and traced the relay MCP extraction/wiring through CLI, runtime exports, cloud harness runner, and existing tests. I fixed one demonstrated CI failure outside the PR diff: packages/cli/src/persona-compile.test.ts now isolates Validation run:
Note: |
|
Reviewed PR #214 against the supplied diff/context and traced the relay MCP extraction through CLI/runtime callers and tests. I did not leave source edits: the current checkout already validates for the PR changes. Verification run:
All completed successfully. Note: I cannot report GitHub CI/mergeability state from this sandbox, so I’m not printing |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed. Reviewed PR #214 against Validated locally:
All local checks passed. I’m not printing |
Summary
agentworkforce agent) couldn't access relay MCP tools because the CLI used@relaycast/mcp(npm/self-registration) while the cloud path already used the broker binary'smcp-args --registerfor pre-minted tokenspackages/runtime/src/relay-mcp.tsso both cloud and CLI paths share the same broker-aware logiccli.tsrunInteractivefor Claude and Codex harnesses, with automatic fallback to@relaycast/mcpwhen the broker is unavailableTest plan
agentworkforce agent <persona>locally under a broker — verify Claude Code starts withagent-relayMCP (notrelaycast) in--mcp-config@relaycast/mcpstill works🤖 Generated with Claude Code