Cursor で MCP を使用したマルチエージェントワークフローの設定

プロジェクトの複雑さが増すにつれ、単一の AI エージェントでは十分でない場合があります。Cursor は MCP(Model Context Protocol)サーバーを通じてマルチエージェントワークフローをサポートし、複数の専門エージェントがプロジェクトの異なる側面で同時に協力できるようにします。このガイドでは、複数のエージェントを効果的に設定および調整する方法を示します。
マルチエージェント協調とは?
マルチエージェント協調により、以下が可能になります:
- 複雑なタスクを分割 専門エージェント間で(例:1 つはフロントエンド用、1 つはバックエンド用)
- 並行して作業 コードベースの異なる部分で
- 関心事の分離を維持 特定のドメイン専用のエージェントで
- AI アシスタンスを拡張 プロジェクトの成長に合わせて
前提条件
マルチエージェントワークフローを設定する前に:
- Cursor Pro 以上 - マルチエージェント機能には有料プランが必要
- MCP サーバーサポート - Cursor 設定で MCP が有効になっていることを確認
- Git リポジトリ - マルチエージェントワークフローはバージョン管理と最適に機能
ワークツリー設定の設定
.cursor/worktrees.json ファイルはマルチエージェント協調の鍵です。
ステップ 1:設定ファイルの作成
プロジェクトルートに .cursor/worktrees.json を作成します:
{
"worktrees": [
{
"id": "frontend-agent",
"name": "Frontend Agent",
"description": "Handles UI components, styling, and client-side logic",
"directories": ["src/components", "src/pages", "src/styles", "public"],
"rules": [
"Use React and TypeScript",
"Follow the existing component patterns",
"Use Tailwind CSS for styling",
"Ensure responsive design"
]
},
{
"id": "backend-agent",
"name": "Backend Agent",
"description": "Manages API endpoints, database models, and server logic",
"directories": ["src/api", "src/models", "src/middleware", "migrations"],
"rules": [
"Use Express.js with TypeScript",
"Follow RESTful conventions",
"Implement proper error handling",
"Add input validation"
]
},
{
"id": "test-agent",
"name": "Testing Agent",
"description": "Writes and maintains test suites",
"directories": ["tests", "src/__tests__", "cypress"],
"rules": [
"Use Jest for unit tests",
"Use React Testing Library for component tests",
"Aim for 80%+ coverage",
"Write integration tests for API endpoints"
]
}
]
}
ステップ 2:MCP サーバーの設定
MCP サーバーを Cursor 設定に追加します(Cmd/Ctrl + Shift + P → "Cursor Settings"):
{
"mcpServers": {
"task-coordinator": {
"command": "npx",
"args": ["-y", "@cursor-task/coordinator"],
"env": {
"WORKTREE_CONFIG": "./.cursor/worktrees.json"
}
},
"file-sync": {
"command": "npx",
"args": ["-y", "@cursor-task/file-sync"]
}
}
}
マルチエージェントモードの使用
マルチエージェントセッションの開始
- Composer を開く(
Cmd/Ctrl + I) - エージェントセレクターをクリック(Composer の上部)
- "Multi-Agent" モードを選択
- 有効化するエージェントを選択
タスクの割り当て
エージェントは、参照したファイルに基づいて自動的にタスクを取得します:
@src/components/UserProfile.tsx @src/api/users.ts
API からデータを取得して表示するユーザープロファイルページを実装してください。
フロントエンドエージェントは UI を処理し、バックエンドエージェントは API エンドポイントが正しいデータを返すようにしてください。
手動タスクルーティング
特定のエージェントにタスクを指示することもできます:
[@frontend-agent] モバイルハンバーガーメニュー付きのレスポンシブナビゲーションコンポーネントを作成
[@backend-agent] ユーザーロールに基づいてメニュー項目を返す /api/navigation エンドポイントを追加
エージェント間の通信
エージェントは共有タスクファイルシステムを通じて通信します。
タスクファイル
タスクは .cursor/tasks/ で追跡されます:
.cursor/
tasks/
TASK-001-frontend-nav.md
TASK-002-backend-api.md
TASK-003-integration-test.md
各タスクファイルには以下が含まれます:
# TASK-001: Navigation Component
## Status: IN_PROGRESS
## Assigned: frontend-agent
## Dependencies: None
## Description
Create a responsive navigation component...
## Acceptance Criteria
- [ ] Mobile hamburger menu works
- [ ] Desktop horizontal layout
- [ ] Active state highlighting
## Notes
- Use the existing Button component
- Follow the design in Figma (link)
エージェントハンドオフ
1 つのエージェントが別のエージェントが依存するタスクを完了したとき:
## Handoff Notes
Completed by: frontend-agent
Handed to: test-agent
The Navigation component is in src/components/Navigation.tsx.
Props interface is defined. Ready for testing.
マルチエージェントワークフローのベストプラクティス
1. 明確な境界を定義
各エージェントには明確に定義されたスコープが必要です:
{
"id": "database-agent",
"directories": ["src/db", "migrations", "seeds"],
"rules": [
"Only modify files in the assigned directories",
"Run migrations before committing changes",
"Document schema changes in CHANGELOG.md"
]
}
2. 共有契約を使用
エージェントが合意するインターフェースを定義します:
// src/types/shared.ts
// This file is read by ALL agents
export interface ApiResponse<T> {
data: T;
success: boolean;
error?: string;
}
export interface User {
id: string;
email: string;
name: string;
role: 'admin' | 'user';
}
3. 競合解決を実装
エージェントが同じファイルを変更する場合:
{
"conflictResolution": {
"strategy": "last-write-wins",
"notification": true,
"manualReview": ["src/types/shared.ts", "package.json"]
}
}
4. エージェントアクティビティを監視
各エージェントが何をしているかを追跡します:
# アクティブなタスクを表示
cat .cursor/tasks/*.md | grep "Status: IN_PROGRESS"
# 最近のエージェントコミットを確認
git log --oneline --all --grep="agent:" | head -20
例:完全なマルチエージェントワークフロー
3 つのエージェントが協力して機能を構築しましょう:
フェーズ 1:バックエンドエージェント
[@backend-agent] CRUD 操作付きの /api/products エンドポイントを作成。
src/db/index.ts の既存のデータベース接続を使用。
src/types/shared.ts の ApiResponse インターフェースに従う。
フェーズ 2:フロントエンドエージェント(バックエンドコミット後に開始)
[@frontend-agent] /api/products からデータを取得する ProductList コンポーネントを作成。
データ取得には React Query を使用。
レスポンシブグリッドで製品を表示。
フェーズ 3:テストエージェント(フロントエンドコミット後に開始)
[@test-agent] ProductList コンポーネントと /api/products エンドポイントのテストを作成。
エラーステートテストを含める。
カバレッジ 85%+ を目指す。
マルチエージェント問題のトラブルシューティング
| 問題 | 解決策 |
|---|---|
| エージェントが互いの変更を上書き | worktrees.json でより厳格なディレクトリ境界を定義 |
| タスクが取得されない | タスクファイルが .cursor/tasks/ にあり、正しいステータスであることを確認 |
| エージェントが共有ファイルで競合 | ファイルを conflictResolution の manualReview に追加 |
| 1 つのエージェントがアイドル | タスク依存関係が完了としてマークされていることを確認 |
高度な設定:カスタム MCP サーバー
専門的なワークフローには、カスタム MCP サーバーを作成します:
// mcp-server-custom.js
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
const server = new Server({
name: 'custom-task-router',
version: '1.0.0'
}, {
capabilities: {
tools: {}
}
});
server.setRequestHandler('tools/call', async (request) => {
if (request.params.name === 'route-task') {
const { task, agentPool } = request.params.arguments;
// Custom routing logic
const bestAgent = selectBestAgent(task, agentPool);
return {
content: [{
type: 'text',
text: `Task routed to ${bestAgent}`
}]
};
}
});