Skip to content
Development
Command

/deploy-forged-mcp

Deploy an MCP server generated by forge-from-openapi --target=mcp-server; detect transport, deploy, smoke-test, print .claude.json snippet

From plugin
heymegabyte-claude-skills
2153 skills27 agents53 commands
Install
> /plugin marketplace add heymegabyte/claude-skills

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/deploy-forged-mcp

Context preview

What this command does when you run it.

Deploy an MCP server generated by forge-from-openapi --target=mcp-server; detect transport, deploy, smoke-test, print .claude.json snippet

Command definition

deploy-forged-mcp.md
description: Deploy an MCP server generated by forge-from-openapi --target=mcp-server; detect transport, deploy, smoke-test, print .claude.json snippet
argument-hint: <mcp-server-dir>
allowed-tools: Bash, Read, Write, Edit

Deploy a forged MCP server. Detects transport from `wrangler.toml` presence, deploys via Wrangler (http) or builds locally (stdio), smoke-tests with MCP Inspector, and outputs a ready-to-paste `.claude.json` registration block.

**When to use** — immediately after `/forge-from-openapi` produces an `mcp-server-dir`; when redeploying after schema changes.

**Inputs** — `$ARGUMENTS`: relative or absolute path to the MCP server directory.

---

Step 1 — Resolve and validate the directory

MCP_DIR="${ARGUMENTS%/}"   # strip trailing slash
ls "$MCP_DIR" 2>/dev/null || echo "NOTFOUND"
  • If NOTFOUND: emit `✗ Directory not found: $MCP_DIR` and stop.
  • Required: `package.json` + one of `src/index.ts`, `index.ts`, `dist/index.js`.
  • Optional: `wrangler.toml` / `wrangler.jsonc` → **http** transport; absence → **stdio**.
  • Read `package.json`: extract `name`, `scripts.build`, `scripts.start`/`scripts.dev`.

---

Step 2 — Detect transport

ls "$MCP_DIR/wrangler.toml" "$MCP_DIR/wrangler.jsonc" 2>/dev/null | head -1
  • Found → `TRANSPORT=http`; not found → `TRANSPORT=stdio`.
  • Emit: `Transport detected: $TRANSPORT`

---

Step 3A — Deploy (http / Cloudflare Workers)

Only when `TRANSPORT=http`:

cd "$MCP_DIR" && npm install 2>&1
cd "$MCP_DIR" && npx wrangler deploy 2>&1
  • Parse output for `https://<worker-name>.<account>.workers.dev` or `Published <name> (https://...)`.
  • Extract `DEPLOYED_URL`; if not found post-success, construct from `wrangler.toml` `name` field.
  • Emit: `Deployed: $DEPLOYED_URL`

---

Step 3B — Build (stdio)

Only when `TRANSPORT=stdio`:

cd "$MCP_DIR" && npm install 2>&1

If `scripts.build` exists:

cd "$MCP_DIR" && npm run build 2>&1
ls "$MCP_DIR/dist/index.js" 2>/dev/null \
  || ls "$MCP_DIR/build/index.js" 2>/dev/null \
  || ls "$MCP_DIR/index.js" 2>/dev/null \
  || echo "ENTRY_MISSING"
  • If `ENTRY_MISSING`: emit `✗ Build completed but entry point not found. Check package.json "main" field.` and stop.
  • Emit: `Build complete: $ENTRY_PATH`

---

Step 4 — Smoke test with MCP Inspector

**http transport:**

npx --yes @modelcontextprotocol/inspector \
  --transport http \
  --url "$DEPLOYED_URL/mcp" \
  --json 2>&1 | head -60

**stdio transport:**

npx --yes @modelcontextprotocol/inspector \
  --transport stdio \
  --command "node $ENTRY_PATH" \
  --json 2>&1 | head -60
  • Parse `tools[]`; on empty or failure: emit `✗ Smoke test failed: <error>`, print raw output, continue to Step 5.
  • On success: emit `✓ Smoke test passed: <N> tools listed` + bullet list of tool names.

---

Step 5 — Print .claude.json registration block

Read `~/.claude.json` for indentation shape; use default if absent.

**http:**

{
  "mcpServers": {
    "<server-name>": {
      "type": "http",
      "url": "<DEPLOYED_URL>/mcp"
    }
  }
}

**stdio:**

{
  "mcpServers": {
    "<server-name>": {
      "type": "stdio",
      "command": "node",
      "args": ["<ABSOLUTE_ENTRY_PATH>"]
    }
  }
}

`<server-name>` = `name` from `package.json` (strip `@scope/` prefix). Print labelled:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Paste into ~/.claude.json › mcpServers:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
<json block>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
After adding: run /audit-mcp-fleet --id <server-name> to confirm registration.

---

Step 6 — Final summary

Deploy Summary — <server-name>
  Transport:    http | stdio
  Deployed URL: https://... (http only)
  Entry point:  /path/to/dist/index.js (stdio only)
  Build:        ✓ | ✗
  Smoke test:   ✓ 12 tools | ✗ failed
  Next step:    paste .claude.json snippet above, then restart Claude Code

On any failure: emit `✗ Deployment incomplete — see errors above before registering.`

---

**Verification** — After pasting and restarting, run `/audit-mcp-fleet --id <server-name>`.

**See**

  • `/forge-from-openapi` — generates the MCP server this deploys
  • `/audit-mcp-fleet` — post-deploy health + drift check
  • `19-mcp-authoring/` — MCP server authoring patterns and Cloudflare Workers transport
  • `rules/secret-provisioning.md` — provision API key env vars via wrangler secrets
Read more
Ships withheymegabyte-claude-skills

14-category autonomous product-building OS for 32+ AI coding tools. One-line prompts → deployed products.

Get the whole plugin

Other commands on heymegabyte-claude-skills.