Rename bundled MCP server to Agent Relay MCP#1005
Conversation
📝 WalkthroughWalkthroughThis PR completes the Agent Relay MCP module naming and refactoring by exporting an ChangesAgent Relay MCP module rename, implementation, and integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
web/content/docs/agent-relay-mcp.mdxParsing error: Expression expected. web/content/docs/plugin-claude-code.mdxParsing error: Expression expected. 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 renames the bundled Relay MCP implementation to Agent Relay MCP, updates configuration files, tests, and documentation to reflect the change, and adds compatibility shims for legacy relaycast-named imports and environment variables. The reviewer's feedback correctly points out a potential runtime crash when accessing the private _requestHandlers property on mcpServer.server without a defensive check, and provides a robust code suggestion to resolve the issue.
| const handlers = ( | ||
| mcpServer.server as unknown as { | ||
| _requestHandlers: Map< | ||
| string, | ||
| (req: unknown, extra: unknown) => Promise<{ tools?: Array<Record<string, unknown>> }> | ||
| >; | ||
| } | ||
| )._requestHandlers; | ||
| const origToolsListHandler = handlers.get('tools/list'); | ||
| if (origToolsListHandler) { | ||
| mcpServer.server.setRequestHandler(ListToolsRequestSchema, async (req, extra) => { | ||
| const result = await origToolsListHandler(req, extra); | ||
| if (result?.tools) { | ||
| result.tools = result.tools.map((tool) => { | ||
| const { execution, outputSchema, _meta, ...clean } = tool; | ||
| void execution; | ||
| void outputSchema; | ||
| void _meta; | ||
| return clean; | ||
| }); | ||
| } | ||
| return result; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Accessing the private _requestHandlers property on mcpServer.server is risky because it relies on internal implementation details of @modelcontextprotocol/sdk which could change or be renamed in future versions. To prevent potential runtime crashes (e.g., TypeError: Cannot read properties of undefined (reading 'get')), add a defensive check to ensure handlers is defined before calling .get().
const handlers = (
mcpServer.server as unknown as {
_requestHandlers?: Map<
string,
(req: unknown, extra: unknown) => Promise<{ tools?: Array<Record<string, unknown>> }>
>;
}
)._requestHandlers;
if (handlers) {
const origToolsListHandler = handlers.get('tools/list');
if (origToolsListHandler) {
mcpServer.server.setRequestHandler(ListToolsRequestSchema, async (req, extra) => {
const result = await origToolsListHandler(req, extra);
if (result?.tools) {
result.tools = result.tools.map((tool) => {
const { execution, outputSchema, _meta, ...clean } = tool;
void execution;
void outputSchema;
void _meta;
return clean;
});
}
return result;
});
}
}|
Preview deployed!
This preview will be cleaned up when the PR is merged or closed. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/broker/src/snippets.rs (1)
274-289:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd RELAYCAST_MCP_COMMAND fallback for compatibility in broker-side config generation.
relaycast_server_config()now only checksAGENT_RELAY_MCP_COMMAND, so legacy environments that still setRELAYCAST_MCP_COMMANDsilently lose their custom MCP command.Suggested fix
- if let Ok(custom_cmd) = std::env::var("AGENT_RELAY_MCP_COMMAND") { + if let Ok(custom_cmd) = std::env::var("AGENT_RELAY_MCP_COMMAND") + .or_else(|_| std::env::var("RELAYCAST_MCP_COMMAND")) + { let parts: Vec<&str> = custom_cmd.split_whitespace().collect(); if let Some((cmd, args_slice)) = parts.split_first() { server.insert("command".into(), Value::String(cmd.to_string()));🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/broker/src/snippets.rs` around lines 274 - 289, The code in relaycast_server_config (snippet building `server` map) only checks AGENT_RELAY_MCP_COMMAND and drops legacy RELAYCAST_MCP_COMMAND; update the logic to first try std::env::var("AGENT_RELAY_MCP_COMMAND"), and if that is not set then try std::env::var("RELAYCAST_MCP_COMMAND"), parsing either value into `cmd` and `args` exactly as the current split_first flow does, and only default to "npx" when neither env var exists so legacy environments keep their custom MCP command.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/cli/lib/broker-lifecycle.ts`:
- Around line 454-462: ensureBundledAgentRelayMcpCommand is currently
overwriting the legacy RELAYCAST_MCP_COMMAND fallback when
AGENT_RELAY_MCP_COMMAND is empty; modify the function to first check
deps.env.RELAYCAST_MCP_COMMAND (and use it to set
deps.env.AGENT_RELAY_MCP_COMMAND if present and non-empty) before calling
buildBundledAgentRelayMcpCommand, and only fall back to
buildBundledAgentRelayMcpCommand when RELAYCAST_MCP_COMMAND is absent; keep
using buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript,
deps.fs.existsSync) and only assign its return value to
deps.env.AGENT_RELAY_MCP_COMMAND if neither AGENT_RELAY_MCP_COMMAND nor
RELAYCAST_MCP_COMMAND are set.
---
Outside diff comments:
In `@crates/broker/src/snippets.rs`:
- Around line 274-289: The code in relaycast_server_config (snippet building
`server` map) only checks AGENT_RELAY_MCP_COMMAND and drops legacy
RELAYCAST_MCP_COMMAND; update the logic to first try
std::env::var("AGENT_RELAY_MCP_COMMAND"), and if that is not set then try
std::env::var("RELAYCAST_MCP_COMMAND"), parsing either value into `cmd` and
`args` exactly as the current split_first flow does, and only default to "npx"
when neither env var exists so legacy environments keep their custom MCP
command.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9619e8d1-73a6-43d9-9e23-de9d77ce2565
📒 Files selected for processing (27)
.agentworkforce/trajectories/completed/2026-05/traj_paoj645u94py/summary.md.agentworkforce/trajectories/completed/2026-05/traj_paoj645u94py/trajectory.json.agentworkforce/trajectories/completed/2026-05/traj_s5eyi5jw2q1u/summary.md.agentworkforce/trajectories/completed/2026-05/traj_s5eyi5jw2q1u/trajectory.json.mcp.jsonCHANGELOG.mdREADME.mdcrates/broker/src/snippets.rspackages/cli/package.jsonpackages/cli/src/cli/agent-relay-mcp.startup.test.tspackages/cli/src/cli/agent-relay-mcp.test.tspackages/cli/src/cli/agent-relay-mcp.tspackages/cli/src/cli/bootstrap.tspackages/cli/src/cli/commands/core.test.tspackages/cli/src/cli/lib/agent-relay-mcp-command.tspackages/cli/src/cli/lib/broker-lifecycle.tspackages/sdk-py/src/agent_relay/communicate/adapters/claude_sdk.pypackages/sdk/.mcp.jsonpackages/sdk/src/__tests__/communicate/adapters/claude-sdk.test.tsplugins/codex-relay-skill/README.mdplugins/codex-relay-skill/SKILL.mdplugins/gemini-relay-extension/README.mdscripts/watch-cli-tools.shweb/components/docs/DocsNav.tsxweb/content/docs/agent-relay-mcp.mdxweb/content/docs/plugin-claude-code.mdxweb/lib/docs-nav.ts
| function ensureBundledAgentRelayMcpCommand(deps: CoreDependencies): void { | ||
| if (deps.env.AGENT_RELAY_MCP_COMMAND?.trim()) { | ||
| return; | ||
| } | ||
|
|
||
| const command = buildBundledRelaycastMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync); | ||
| const command = buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync); | ||
| if (command) { | ||
| deps.env.RELAYCAST_MCP_COMMAND = command; | ||
| deps.env.AGENT_RELAY_MCP_COMMAND = command; | ||
| } |
There was a problem hiding this comment.
Preserve legacy MCP override fallback before auto-populating AGENT_RELAY_MCP_COMMAND.
This now ignores an existing RELAYCAST_MCP_COMMAND override and replaces behavior with bundled default, which breaks backward compatibility for existing setups.
Suggested fix
function ensureBundledAgentRelayMcpCommand(deps: CoreDependencies): void {
if (deps.env.AGENT_RELAY_MCP_COMMAND?.trim()) {
return;
}
+ if (deps.env.RELAYCAST_MCP_COMMAND?.trim()) {
+ deps.env.AGENT_RELAY_MCP_COMMAND = deps.env.RELAYCAST_MCP_COMMAND;
+ return;
+ }
const command = buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync);
if (command) {
deps.env.AGENT_RELAY_MCP_COMMAND = command;
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function ensureBundledAgentRelayMcpCommand(deps: CoreDependencies): void { | |
| if (deps.env.AGENT_RELAY_MCP_COMMAND?.trim()) { | |
| return; | |
| } | |
| const command = buildBundledRelaycastMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync); | |
| const command = buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync); | |
| if (command) { | |
| deps.env.RELAYCAST_MCP_COMMAND = command; | |
| deps.env.AGENT_RELAY_MCP_COMMAND = command; | |
| } | |
| function ensureBundledAgentRelayMcpCommand(deps: CoreDependencies): void { | |
| if (deps.env.AGENT_RELAY_MCP_COMMAND?.trim()) { | |
| return; | |
| } | |
| if (deps.env.RELAYCAST_MCP_COMMAND?.trim()) { | |
| deps.env.AGENT_RELAY_MCP_COMMAND = deps.env.RELAYCAST_MCP_COMMAND; | |
| return; | |
| } | |
| const command = buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript, deps.fs.existsSync); | |
| if (command) { | |
| deps.env.AGENT_RELAY_MCP_COMMAND = command; | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/cli/src/cli/lib/broker-lifecycle.ts` around lines 454 - 462,
ensureBundledAgentRelayMcpCommand is currently overwriting the legacy
RELAYCAST_MCP_COMMAND fallback when AGENT_RELAY_MCP_COMMAND is empty; modify the
function to first check deps.env.RELAYCAST_MCP_COMMAND (and use it to set
deps.env.AGENT_RELAY_MCP_COMMAND if present and non-empty) before calling
buildBundledAgentRelayMcpCommand, and only fall back to
buildBundledAgentRelayMcpCommand when RELAYCAST_MCP_COMMAND is absent; keep
using buildBundledAgentRelayMcpCommand(deps.execPath, deps.cliScript,
deps.fs.existsSync) and only assign its return value to
deps.env.AGENT_RELAY_MCP_COMMAND if neither AGENT_RELAY_MCP_COMMAND nor
RELAYCAST_MCP_COMMAND are set.
Summary: Rename the bundled MCP implementation, tests, and helper to agent-relay-mcp; remove the stale relaycast-named entrypoint/helper; add AGENT_RELAY_MCP_COMMAND; update tracked MCP configs and docs to use agent-relay mcp. Also move the Agent Relay MCP tools table out of the root README and Claude plugin page into a dedicated Agent Relay MCP docs reference, with docs nav and cross-links.
Tests: vitest agent-relay-mcp tests; vitest core.test.ts; tsc --noEmit -p packages/cli/tsconfig.json; cargo test relaycast_server_config_includes_agent_result_vars; cargo test opencode_creates_config_file_and_returns_agent_flag; npm --prefix packages/cli run build; npm --prefix web run build; git diff --check; prettier --check supported changed files; cargo fmt --check.