Skip to content

fix: support 'mcp' as command-line argument#241

Open
Jah-yee wants to merge 1 commit intoaidenybai:mainfrom
Jah-yee:main
Open

fix: support 'mcp' as command-line argument#241
Jah-yee wants to merge 1 commit intoaidenybai:mainfrom
Jah-yee:main

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 13, 2026

Summary

This PR fixes issue #240 where running npx -y grab@latest add mcp fails with "Invalid agent: mcp".

Changes

  • Add 'mcp' to AGENTS array in templates.ts so it passes the argument validation
  • Add 'mcp' to AGENT_NAMES for display purposes
  • Simplify AgentIntegration type (mcp is now part of Agent)
  • Add MCP handling in add.ts when passed as argument - calls promptMcpInstall() similar to interactive mode
  • Update script template functions (NEXT_APP_ROUTER_SCRIPT_WITH_AGENT, etc.) to handle 'mcp' specially - returns base script without agent-specific package
  • Filter 'mcp' from PROVIDERS (no npm package needed, similar to 'ami')
  • Update success message for non-interactive mode

Testing

The fix allows users to run:

npx -y grab@latest add mcp

to install MCP server for React Grab.

Fixes #240


Note

Low Risk
Low risk: scoped to CLI validation/template generation and adds a special-case MCP install path, with no changes to core runtime or security-sensitive logic.

Overview
Fixes grab add mcp by treating mcp as a first-class agent in AGENTS/AGENT_NAMES and validating it like other integrations.

Updates add to special-case mcp in non-interactive/arg-driven flows by running promptMcpInstall() (server configuration only) and marking it installed, while excluding mcp from PROVIDERS and ensuring script/template helpers don’t emit agent-specific client imports for mcp.

Written by Cursor Bugbot for commit 5aec9ee. This will update automatically on new commits. Configure here.


Summary by cubic

Allow mcp as a grab add argument and set up the MCP server in non-interactive mode, fixing the “Invalid agent: mcp” error. Templates and providers treat MCP as server-only (no client package).

  • Bug Fixes
    • Accept mcp in AGENTS/AGENT_NAMES; simplify AgentIntegration.
    • In add.ts, run promptMcpInstall() when mcp is passed and record it as installed.
    • Exclude mcp from PROVIDERS (@react-grab/<agent>) and skip agent imports in all script/template helpers.
    • npx -y grab@latest add mcp now works. Fixes MCP Install fails with "Invalid agent" #240.

Written for commit 5aec9ee. Summary will update on new commits.

- Add 'mcp' to AGENTS array in templates.ts
- Add 'mcp' to AGENT_NAMES
- Simplify AgentIntegration type (mcp is now part of Agent)
- Add MCP handling in add.ts when passed as argument
- Update script template functions to handle 'mcp' specially
- Filter 'mcp' from PROVIDERS (no npm package needed)
- Update success message for non-interactive mode

Fixes: aidenybai#240
@pullfrog
Copy link
Contributor

pullfrog bot commented Mar 13, 2026

Error

agent completed without reporting progress

Pullfrog  | Rerun failed job ➔View workflow run | Triggered by Pullfrogpullfrog.com𝕏

@vercel
Copy link
Contributor

vercel bot commented Mar 13, 2026

Someone is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

logger.log("Restart your agents to activate.");
logger.break();
projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
}
Copy link

Choose a reason for hiding this comment

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

Missing early exit after MCP installation causes unintended behavior

High Severity

After the MCP-specific installation block completes successfully at line 130, the code falls through to the generic agent installation flow instead of exiting. This causes getPackagesToInstall("mcp", false) at line 418 to return ["@react-grab/mcp"], which then gets installed as a local dev dependency via npm install -D @react-grab/mcp — this is unintended since MCP uses npx -y @react-grab/mcp --stdio on-demand. The user also sees duplicate success messages and a confusing "Adding MCP." spinner after configuration already completed.

Fix in Cursor Fix in Web

"ami",
"droid",
"copilot",
"mcp",
Copy link

Choose a reason for hiding this comment

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

MCP appears in interactive legacy agent selection list

Medium Severity

Adding "mcp" to AGENTS means it now appears in availableAgents used by the interactive agent selection prompt (the "legacy" flow in add.ts). If a user chooses "Legacy" connection mode and then selects "MCP" from the agent list, promptMcpInstall() is never called — the code instead tries a standard package installation flow, which is incorrect for MCP.

Fix in Cursor Fix in Web

Copy link
Contributor

@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.

3 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/cli/src/commands/add.ts">

<violation number="1" location="packages/cli/src/commands/add.ts:129">
P1: Adding 'mcp' via command-line argument triggers a false 'already installed' prompt because the code updates `projectInfo.installedAgents` with 'mcp' before checking `if (installedAgents.length > 0)`. This causes the prompt to trigger even on fresh installation. If the user selects 'Replace', the just-installed MCP agent gets immediately uninstalled.</violation>

<violation number="2" location="packages/cli/src/commands/add.ts:129">
P1: Missing early exit after MCP installation. The success path within this `if (validAgent === "mcp")` block falls through to the generic agent installation flow below, which will attempt standard package installation for "mcp" and display duplicate success messages. The failure path correctly calls `process.exit(1)`, so the success path should similarly exit.</violation>
</file>

<file name="packages/cli/src/utils/templates.ts">

<violation number="1" location="packages/cli/src/utils/templates.ts:11">
P2: Adding `"mcp"` to the `AGENTS` array means it will appear in the interactive legacy agent selection prompt. If a user selects "MCP" through the interactive legacy flow, the code follows the standard package installation path instead of calling `promptMcpInstall()`. Consider filtering `"mcp"` out of the interactive agent choices (similar to how it's filtered from `PROVIDERS`), or adding MCP-specific handling in the interactive legacy flow.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

);
logger.log("Restart your agents to activate.");
logger.break();
projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P1: Adding 'mcp' via command-line argument triggers a false 'already installed' prompt because the code updates projectInfo.installedAgents with 'mcp' before checking if (installedAgents.length > 0). This causes the prompt to trigger even on fresh installation. If the user selects 'Replace', the just-installed MCP agent gets immediately uninstalled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/commands/add.ts, line 129:

<comment>Adding 'mcp' via command-line argument triggers a false 'already installed' prompt because the code updates `projectInfo.installedAgents` with 'mcp' before checking `if (installedAgents.length > 0)`. This causes the prompt to trigger even on fresh installation. If the user selects 'Replace', the just-installed MCP agent gets immediately uninstalled.</comment>

<file context>
@@ -111,6 +110,25 @@ export const add = new Command()
+          );
+          logger.log("Restart your agents to activate.");
+          logger.break();
+          projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
+        }
+
</file context>
Fix with Cubic

);
logger.log("Restart your agents to activate.");
logger.break();
projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P1: Missing early exit after MCP installation. The success path within this if (validAgent === "mcp") block falls through to the generic agent installation flow below, which will attempt standard package installation for "mcp" and display duplicate success messages. The failure path correctly calls process.exit(1), so the success path should similarly exit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/commands/add.ts, line 129:

<comment>Missing early exit after MCP installation. The success path within this `if (validAgent === "mcp")` block falls through to the generic agent installation flow below, which will attempt standard package installation for "mcp" and display duplicate success messages. The failure path correctly calls `process.exit(1)`, so the success path should similarly exit.</comment>

<file context>
@@ -111,6 +110,25 @@ export const add = new Command()
+          );
+          logger.log("Restart your agents to activate.");
+          logger.break();
+          projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
+        }
+
</file context>
Suggested change
projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
projectInfo.installedAgents = [...projectInfo.installedAgents, "mcp"];
process.exit(0);
Fix with Cubic

"ami",
"droid",
"copilot",
"mcp",
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P2: Adding "mcp" to the AGENTS array means it will appear in the interactive legacy agent selection prompt. If a user selects "MCP" through the interactive legacy flow, the code follows the standard package installation path instead of calling promptMcpInstall(). Consider filtering "mcp" out of the interactive agent choices (similar to how it's filtered from PROVIDERS), or adding MCP-specific handling in the interactive legacy flow.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/utils/templates.ts, line 11:

<comment>Adding `"mcp"` to the `AGENTS` array means it will appear in the interactive legacy agent selection prompt. If a user selects "MCP" through the interactive legacy flow, the code follows the standard package installation path instead of calling `promptMcpInstall()`. Consider filtering `"mcp"` out of the interactive agent choices (similar to how it's filtered from `PROVIDERS`), or adding MCP-specific handling in the interactive legacy flow.</comment>

<file context>
@@ -8,11 +8,12 @@ export const AGENTS = [
   "ami",
   "droid",
   "copilot",
+  "mcp",
 ] as const;
 
</file context>
Fix with Cubic

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.

MCP Install fails with "Invalid agent"

1 participant