实战案例
三个由浅入深的任务,覆盖本教程:陌生仓库上手、Plan Mode 多文件功能、以及规则 + MCP 的团队工作流。把提示词贴进 Agent;命令按你的仓库改。不要在生产仓库关着审查跑这些练习。
案例 1:上手陌生仓库
目标: 两小时内能指出入口、测试命令和一处安全的小改动——不靠猜。
准备: 用 Git 克隆任意你不熟的中小型开源库,在 Cursor 里打开仓库根。
git clone <repo-url> unfamiliar-repo
cd unfamiliar-repo
cursor .
git clone <repo-url> unfamiliar-repo
cd unfamiliar-repo
cursor .
Ctrl+I / Cmd+I,按顺序发送:
Explain this codebase. Point me to the main entry points, key modules,
and anything I should read before making changes.
Quote the exact commands this repo uses for install, test, lint, and
dev server. Prefer package.json / Makefile / pyproject.toml / go.mod.
Do not invent scripts.
然后在本机跑它引用的安装与测试(示例):
# 以仓库读到的为准
npm ci
npm test
若测试因缺少密钥失败,把错误贴回 Agent:These tests failed on a clean clone. Which env vars are required? Do not weaken tests.
再要三处小改进,只批准一处(见 快速上手)。审查 diff,再跑同一组测试。
完成标准:
案例 2:用 Plan Mode 做多文件功能
目标: 加一个不改鉴权的只读 /health(或等价)端点,并带上仓库风格的测试。
准备: 选一个已有 HTTP 层的应用(Express、FastAPI、Rails、Go net/http…)。新建分支:
git checkout -b practice/health-endpoint
Shift+Tab 进入 Plan Mode,发送:
Add a public health endpoint that returns JSON { "ok": true }.
Constraints:
- Reuse the existing HTTP stack and folder layout
- Do not change authentication or existing routes
- Do not add dependencies
- Follow existing test style
Research the repo, ask clarifying questions, and write a plan that lists
every file, the test command, and rollback. Do not edit files until I approve.
审计划:
- 文件是否只有路由 + 测试(外加框架要求的注册处)?
- 测试命令是否已存在?
- 有没有「顺手重构」?
把计划 Save to workspace,例如 docs/plans/health-endpoint.md。批准构建。构建后:
Run only the commands listed in the plan. Paste stdout and exit codes.
If a check failed, fix it without expanding scope.
自己再跑一遍。若实现偏了:Restore 检查点或 git restore .,收紧计划,再构建(见 Plan Mode)。
完成标准:
PowerShell 快速探测(端口按项目改):
Invoke-RestMethod http://127.0.0.1:3000/health
curl -s http://127.0.0.1:3000/health
案例 3:MCP + 规则的团队工作流
目标: 新同事(或未来的你)克隆后,Agent 自动遵守同一套规范,并能安全调用一台 MCP 服务器。
3a. 检入规则与共享说明
在仓库根:
New-Item -ItemType Directory -Force -Path .cursor\rules, docs\plans | Out-Null
mkdir -p .cursor/rules docs/plans
.cursor/rules/team.mdc:
---
alwaysApply: true
---
- Read AGENTS.md before the first edit in a session
- Do not add dependencies without asking
- Never commit `.env`, credentials, or `mcp.json` secrets
- Prefer Plan Mode when a task will touch more than five files
根目录 AGENTS.md:
# Agent instructions
- Install: use the commands already documented in README
- Test: use the existing script (do not invent a new runner)
- Public API changes require a plan saved under docs/plans/
提交这些文件。新开一条 Agent 聊天,故意说:Add lodash for a one-liner. 合格的 Agent 应当拒绝或先问——因为规则禁止擅自加依赖。
3b. 项目 MCP(无密钥)
把无密钥的服务器放进 .cursor/mcp.json。需要 token 的用 ${env:NAME},不要把 token 检入。示例形状(命令换成你们真实、已审查过的服务器):
{
"mcpServers": {
"docs": {
"command": "npx",
"args": ["-y", "mcp-server"],
"env": {
"API_KEY": "${env:API_KEY}"
}
}
}
}
插值与传输见 MCP 集成;协议细节见 MCP 教程。
在 Customize 里启用服务器,Output → MCP Logs 确认已连接。然后:
Use only the enabled MCP tools to fetch the current issue/doc titled
"<name>". Summarize acceptance criteria. Do not edit product code.
Then draft a Plan Mode plan that implements those criteria with our
AGENTS.md constraints.
3c. 团队约定
完成标准:
反模式
下一步