在上一篇,我聊了 Kiro 的 Spec 系統如何讓「計劃」和「執行」貼得更近。
今天,我要用一個實際案例,帶你看看我如何用 Kiro 的 Spec 功能,把一個大目標——在 FastAPI 專案中加入 MCP(Model Context Protocol)Server 支援——拆解、規劃,最後逐步完成(關於這個MCP 之後會再寫一篇專文介紹)。
這篇不只是功能介紹,而是把我實際走過的流程、Kiro 生成的內容,以及中途互動的細節全都還原給你。
我給 Kiro 的第一個 Prompt 很直接:
Add MCP server support to this FastAPI backend using fastapi_mcp. Include basic setup, example tools, authentication, and minimal docs/tests.
這句話就像是丟給 Kiro 一個大方向,接下來它進入 Requirements 階段,自動生成了一份完整的 requirements.md
。
Kiro 會將需求轉換為 EARS 格式 的 User Story + Acceptance Criteria。以下擷取部分(完整內容更長):
**User Story:** As an AI assistant or MCP client, I want to connect to QueryPal's MCP server, so that I can access database exploration capabilities programmatically.
#### Acceptance Criteria
1. WHEN an MCP client connects to the server THEN the system SHALL establish a secure connection using the MCP protocol
2. WHEN the connection is established THEN the system SHALL provide a list of available tools and their schemas
3. IF authentication is required THEN the system SHALL validate credentials before allowing access
4. WHEN the client disconnects THEN the system SHALL clean up resources and close the connection gracefully
它還自動涵蓋了:
💡 互動亮點
在這個階段,我臨時想到要加入 enable/disable write operations 的功能(用環境變數控制 MCP 是否允許資料寫入)。我只用一句話補充給 Kiro,它就把這個需求加進了 Requirements 的相關章節,並且後續會反映到 Design 與 Tasks 中。
批准需求後,Kiro 進入 Design 階段,掃描專案並生成 design.md
。它的重點包括:
fastapi_mcp
自動將 FastAPI endpoint 轉換為 MCP 工具config.py
)routes/mcp.py
)
系統架構圖
接下來,Kiro 自動生成 tasks.md
,將設計拆解成一個個可執行的任務。例如前三項:
- [x] 1. Set up MCP configuration and directory structure
- Create MCP configuration module with env var support
- Create basic MCP directory structure (config.py, schemas.py, auth.py, server.py)
- Update requirements.txt to ensure fastapi_mcp dependency is configured
- [x] 2. Create MCP request/response schemas
- Define Pydantic models for MCP request/response
- Implement validation for database/collection names and query params
- Write unit tests for schema validation
- [x] 3. Implement MCP authentication integration
- Integrate with Azure AD authentication
- Handle authentication failures
- Write unit tests for authentication scenarios
🛠 使用心得
tasks.md
狀態。整個過程下來,我發現 Kiro 的 Spec 系統有幾個很強的點:
如果用一句話形容這次經驗:
Kiro 就像是能規劃、能追蹤、還能自己動手做的專案助理。
Copilot 在即時輔助、補全上很強,但 Kiro 在 規劃 + 落地執行 這件事上的確更像一個合作夥伴。
尤其當需求變更時,它的反應和更新流程讓我少了很多自己對任務清單手動修補的麻煩。
下一篇,我會把這個 MCP Server 的其中一個任務完整走一遍,看看從點擊「開始」到功能完成,中間發生了什麼事。