我如何用 MCP 替换了我的预发布环境

发布: (2025年12月14日 GMT+8 17:37)
5 分钟阅读
原文: Dev.to

Source: Dev.to

概览

在 2025 年的某个时点,我变成了超额就业的状态,身兼五份工作。我对老板们坦诚相告,他们的反应或是好奇、或是 amused,或是毫不在意。我保留这些工作几个月,期间没有被任何一份解雇。

我使用的技术栈

  • GKE + Cloud Run 作为后端
  • ECS + Fargate + SQS + Lambda + CDKTF + Cloud Build
  • 基于 Argo 的 Kubernetes
  • Next.js + Prisma + PostgreSQL
  • React + Lambda + CDK + Modal

不论使用哪套栈,始终会碰到同一个问题:演示工作并分享供审阅的链接非常困难。软件开发本身就很乱,团队会做出不完全符合单一统一栈的选择,即便是尝试为每个 PR 创建临时环境的项目,也会在细节上卡壳,使得预览难以使用和维护。

我基本上只想给人们一个指向我 localhost 的链接。起初我使用 ngrok,但它最终失效,于是我开始自己构建工具。这些工具逐渐演变成 Autodock —— 一个 MCP 服务器,只需一个提示就能为你的 AI 编码工具提供完整的预演环境。若需要更多信息,可参考文档

设置

我使用 Claude Code 作为主力工具,但对任何支持 MCP 的编码代理,步骤都是相同的。

claude mcp add --transport http autodock https://autodock.io/api/mcp/streamable-http

在代理内部运行 /mcp 并选择 autodock。首次使用时按 Enter 登录或注册,即可进入。

启动

Autodock Dev Box 预装了一整套开发者工具:

  • 通过 mise 提供的语言nodepythongorust
  • 基础设施dockerterraformkubectllocalstack
  • AI 工具claude-codeaiderollama
  • 通过 playwright 提供的浏览器
  • 实用工具ripgreplibfaketimehttpiejq

我经常使用项目 InboxPilot 来演示 Autodock,但任何仓库都可以。

在 Claude 中输入:

> Please launch an autodock dev box for this project

助手会回应:

● autodock - env.launch (MCP)(name: "inboxpilot")
  ⎿  Your Autodock box is ready. Please offer to execute these steps for the user:
     1) Download and save the SSH key (link expires in 10 minutes):
        mkdir -p ~/.autodock/ssh && chmod 700 ~/.autodock/ssh
     … +37 lines
● Your Autodock dev box is ready.

Environment Details:
- Name: inboxpilot
- Slug: chilly-mollusk
- Status: ready
- URL: https://chilly-mollusk.autodock.io
- Auto‑stop: 30 minutes

To SSH directly:
ssh root@chilly-mollusk.autodock.io -i ~/.autodock/ssh/chilly-mollusk.pem

随后助手会提供后续步骤(同步代码、运行命令、暴露端口)。我选择同步项目。

同步

Autodock 将 localhost 视为唯一的真相来源。你的代理在本地编码,但会定期同步,使更新即时可用(例如通过 HMR)。

> Could you please sync inboxpilot to the dev box?

助手输出(为简洁起见已截断):

● autodock - env.sync (MCP)(projectName: "inboxpilot")
  ⎿  Environment: inboxpilot (push: local→remote)
     Project: inboxpilot → /workspace/inboxpilot
     SSH: root@chilly-mollusk.autodock.io:22
● Bash(rsync -avz --delete -e "ssh -i ~/.autodock/ssh/chilly-mollusk.pem -p 22 -o StrictHostKeyChecking=accept-new" ./ \
      root@chilly-mollusk.autodock.io:/workspace/inboxpilot)
  ⎿  sending incremental file list
     created directory /workspace/inboxpilot
     … +113 lines
● Synced successfully.

● Bash(find . -name '.env*' -type f 2>/dev/null | head -20)
  ⎿  ./backend/.env
     ./backend/.env.example
     ./frontend/.env.local
● Bash(grep -h "localhost" ./backend/.env ./frontend/.env.local 2>/dev/null || echo "No localhost references found")
  ⎿  DATABASE_URL=postgresql://postgres:postgres@localhost:5432/inboxpilot
     CLERK_AUTHORIZED_PARTIES=["http://localhost:3000","https://3000--sparkling-vulture.autodock.io"]
     CORS_ORIGINS=["http://localhost:3000","https://3000--sparkling-vulture.autodock.io"]
     SMTP_HOST=localhost

● I see the .env files have references to a previous dev box (sparkling‑vulture). Let me patch them for the new chilly‑mollusk environment and sync.

● Bash(ssh -i ~/.autodock/ssh/chilly-mollusk.pem root@chilly-mollusk.autodock.io \
      "cat > /workspace/inboxpilot/backend/.env  /workspace/inboxpilot/frontend/.env.local << 'EOF'
NEXT_PUBLIC_API_URL=https://8000--chilly-mollusk.autodock.io
EOF")
● Sync complete.

Summary:
- Synced all project files to /workspace/inboxpilot on the dev box
- Patched .env files with updated URLs for chilly‑mollusk
- Next steps:
  * Install dependencies (`npm install` for frontend, `poetry install` for backend)
  * Start services (PostgreSQL, backend API on port 8000, frontend on port 3000)

从这里你可以继续开发、测试,并将实时 URL(例如 https://8000--chilly-mollusk.autodock.io)分享给审阅者——全部无需离开本地编辑器。

Back to Blog

相关文章

阅读更多 »