Skip to content

Conversation

rholinshead
Copy link
Member

@rholinshead rholinshead commented Sep 29, 2025

Description

Spun up a windows VM to test mcp-agent deploy and found a couple more issues:

  • another path fix
  • fix for wrangler command via npx: we need to use shell for the subprocess.run and point to our cache dir instead of expecting some global npm path

Testing

make lint
make format
make tests

Spun up windows VM and deployed successfully:

C:\Users\guestlastmileai\Desktop\Projects\mcp-agent>uv run mcp-agent deploy MCPAgentServerTemporalWindows -c examples\mcp_agent_server\temporal
INFO: Using API at https://mcp-agent.com/api
INFO: Checking for existing app ID for 'MCPAgentServerTemporalWindows'...
SUCCESS: Found existing app with ID: app_ef676a9f-4040-4aee-be61-d2a94ace9b71 for name 'MCPAgentServerTemporalWindows'
Do you want deploy an update to the existing app ID: app_ef676a9f-4040-4aee-be61-d2a94ace9b71? [Y/n]:
INFO: Will deploy an update to app ID: app_ef676a9f-4040-4aee-be61-d2a94ace9b71
INFO: Both 'mcp_agent.secrets.yaml' and 'mcp_agent.deployed.secrets.yaml' found in
C:\Users\guestlastmileai\Desktop\Projects\mcp-agent\examples\mcp_agent_server\temporal.
Do you want to reuse the previously deployed secrets in 'mcp_agent.deployed.secrets.yaml'? [Y/n]:
INFO: Using existing 'mcp_agent.deployed.secrets.yaml'.
╭──────────────────────────────────────────────── MCP Agent Deployment ────────────────────────────────────────────────╮
│ App: MCPAgentServerTemporalWindows (ID: app_ef676a9f-4040-4aee-be61-d2a94ace9b71)                                    │
│ Configuration:                                                                                                       │
│ C:\Users\guestlastmileai\Desktop\Projects\mcp-agent\examples\mcp_agent_server\temporal\mcp_agent.config.yaml         │
│ Secrets file:                                                                                                        │
│ C:\Users\guestlastmileai\Desktop\Projects\mcp-agent\examples\mcp_agent_server\temporal\mcp_agent.secrets.yaml        │
│ Deployed secrets file:                                                                                               │
│ C:\Users\guestlastmileai\Desktop\Projects\mcp-agent\examples\mcp_agent_server\temporal\mcp_agent.deployed.secrets.ya │
│ ml                                                                                                                   │
│                                                                                                                      │
╰──────────────────────────────────────────────────── LastMile AI ─────────────────────────────────────────────────────╯
INFO: Skipping secrets processing...
╭────────────────────────────────────────────────── Deployment Ready ──────────────────────────────────────────────────╮
│ Ready to deploy MCP Agent with processed configuration                                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
WARNING: Found a __main__ entrypoint in main.py. This will be ignored in the deployment.
INFO: Deploying from git commit 253cd9b8* on branch main
▰▱▱▱▱▱▱ ✅ Bundled successfully
INFO: Deployment API configured with up to 3 attempts
▹▹▸▹▹ ✅ MCP App deployed successfully!
INFO: App ID: app_ef676a9f-4040-4aee-be61-d2a94ace9b71
INFO: App URL: https://1a4qo6jwow9r9apofsl21pzbnr0pxfo6.deployments.mcp-agent.com
INFO: App Status: ONLINE
  • Ran basic agent workflow via inspector

Also deployed successfully from mac (uv run mcp-agent deploy MCPAgentServerTemporal -c examples/mcp_agent_server/temporal)

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows deployment reliability by configuring npm’s global prefix in the deployment cache and enabling shell execution for commands on Windows.
    • Streamlined environment setup and command invocation to reduce platform-specific issues.
    • Minor improvement to secrets path handling for consistency.
  • Tests

    • Reformatted assertions for clarity; no changes to test behavior.
  • Refactor

    • Simplified environment updates and command construction for clearer, more maintainable deployment logic.

Copy link

coderabbitai bot commented Sep 29, 2025

Walkthrough

Updates deploy command path construction to use pathlib join, refactors Wrangler wrapper to centralize env updates, introduce Windows-specific npm prefix handling and shell execution, and minor test assertion reformatting without logic changes.

Changes

Cohort / File(s) Summary
Deploy CLI path join
src/mcp_agent/cli/cloud/commands/deploy/main.py
Replaces f-string Path construction with pathlib operator (config_dir / MCP_DEPLOYED_SECRETS_FILENAME) for transformed secrets path.
Wrangler wrapper env and subprocess
src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py
Centralizes env updates via env_updates; adds Windows-specific npm prefix directory and npm_config_prefix; builds cmd list explicitly; uses shell=True on Windows for npx behavior; preserves existing error handling via _handle_wrangler_error.
Deploy tests formatting
tests/cli/commands/test_deploy_command.py
Reformats assertions to single-line with parenthesized messages; no logic changes.
Wrangler wrapper tests formatting
tests/cli/commands/test_wrangler_wrapper.py
Collapses multi-line assertions to single-line forms; no functional changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant D as Deploy CLI
  participant W as WranglerWrapper
  participant P as subprocess.run
  participant WR as Wrangler (npx)

  U->>D: invoke deploy
  D->>W: prepare and run wrangler deploy
  Note over W: Build env_updates (API keys, etc.)
  alt Windows
    W->>W: Set npm_config_prefix to cache\\npm-global
    W->>P: run(cmd, env, shell=True)
  else Non-Windows
    W->>P: run(cmd, env, shell=False)
  end
  P->>WR: execute "npx wrangler deploy ..."
  WR-->>P: exit code / output
  alt error
    P-->>W: non-zero return
    W->>W: _handle_wrangler_error(...)
  else success
    P-->>W: success
  end
  W-->>D: result
  D-->>U: deployment status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • petersonbill64
  • saqadri

Poem

A hop and a skip through paths we align,
With slashes that join in pathlib’s design.
On Windows I burrow a npm nook,
Shell true for npx—now the command took.
Tests tidied neat, like clover in row—
Deploy, dear friends, and watch it grow! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.16% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Fix/windows bundle paths tested" is partially related to the changeset. The changes do address Windows-specific path handling issues, including replacing string-based path construction with pathlib operators and adding Windows-specific npm/Wrangler configuration with conditional shell execution. However, the title is somewhat vague with the "tested" suffix and doesn't clearly convey the main technical change. A developer scanning history might understand this fixes Windows issues but wouldn't immediately grasp that it specifically addresses npm path configuration and subprocess invocation on Windows. The title captures a real aspect of the change but could be more specific about the primary fix.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/windows-bundle-paths-tested

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.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@rholinshead rholinshead marked this pull request as ready for review September 29, 2025 19:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py (1)

148-156: Consider adding error handling for npm prefix directory creation.

The npm-global directory creation uses mkdir(parents=True, exist_ok=True) which should handle most cases, but filesystem permission issues could cause silent failures.

Consider wrapping the directory creation in a try-except to provide clearer error messages:

 if os.name == "nt":
     # On Windows, configure npm to use a safe prefix within our cache directory
     # to avoid issues with missing global npm directories
     npm_prefix = (
         Path(os.path.expanduser(settings.DEPLOYMENT_CACHE_DIR)) / "npm-global"
     )
-    npm_prefix.mkdir(parents=True, exist_ok=True)
+    try:
+        npm_prefix.mkdir(parents=True, exist_ok=True)
+    except OSError as e:
+        raise CLIError(f"Failed to create npm prefix directory on Windows: {e}") from e
     env_updates["npm_config_prefix"] = str(npm_prefix)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 253cd9b and 92f7b1f.

📒 Files selected for processing (4)
  • src/mcp_agent/cli/cloud/commands/deploy/main.py (1 hunks)
  • src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py (2 hunks)
  • tests/cli/commands/test_deploy_command.py (1 hunks)
  • tests/cli/commands/test_wrangler_wrapper.py (10 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/cli/commands/test_wrangler_wrapper.py (1)
src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py (1)
  • _needs_requirements_modification (35-41)
src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py (1)
src/mcp_agent/cli/cloud/commands/deploy/settings.py (3)
  • wrangler_auth_domain (24-26)
  • wrangler_auth_url (29-31)
  • cloudflare_api_base_url (34-36)
🔇 Additional comments (5)
tests/cli/commands/test_deploy_command.py (1)

455-457: LGTM! Formatting update only.

The assertion has been reformatted to a single line with the message wrapped in parentheses. This is purely a stylistic change with no functional impact.

tests/cli/commands/test_wrangler_wrapper.py (1)

473-475: LGTM! Consistent formatting improvements.

All assertion statements have been reformatted to single-line format with messages in parentheses. These are purely stylistic changes with no impact on test behavior or coverage.

Also applies to: 547-549, 572-577, 653-663, 677-685, 728-730, 846-848, 876-878, 884-886, 953-955, 961-975, 977-983, 994-996, 1000-1002

src/mcp_agent/cli/cloud/commands/deploy/main.py (1)

278-278: Excellent path construction improvement.

Switching from string formatting to pathlib's / operator is more idiomatic and ensures correct path separator handling across Windows and Unix systems. This change aligns with the PR's Windows compatibility goals.

src/mcp_agent/cli/cloud/commands/deploy/wrangler_wrapper.py (2)

136-157: Good refactor for Windows compatibility.

The env_updates structure centralizes environment variable configuration and defers application, making the Windows-specific npm prefix handling cleaner. The Windows npm prefix configuration addresses a common issue where global npm directories may not exist.


315-337: Confirm shell injection mitigation for app_id parameter.

The shell=True flag on Windows (line 334) is necessary for npx to work, but introduces shell injection risk. While app_id comes from the API backend (mcp_app_client.create_app() at line 210-214 in main.py) rather than direct user input, defense-in-depth is recommended.

Two mitigation options:

  1. Use shlex.quote() on POSIX (already imported elsewhere in the codebase):
import shlex
# Quote app_id on POSIX systems
quoted_app_id = shlex.quote(app_id) if os.name != "nt" else app_id
  1. Avoid shell=True entirely by using npx.cmd explicitly on Windows:
npx_cmd = "npx.cmd" if os.name == "nt" else "npx"
cmd = [npx_cmd, "--yes", "[email protected]", ...]
# Then use shell=False

Option 2 is preferred as it eliminates the shell entirely. Consider also documenting that app_id format is controlled by the backend API.

@rholinshead rholinshead merged commit 1d4a393 into main Sep 29, 2025
8 checks passed
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.

2 participants