io.github.shinpr/sub-agents-mcp
平台与服务by shinpr
面向 Cursor 等工具的 MCP server,可将任务委派给不同专长的 AI assistants,提升协作效率。
给 Cursor 补上多智能体协作能力,把任务按专长分派给不同 AI assistants,复杂流程更顺,团队式开发效率提升很明显。
什么是 io.github.shinpr/sub-agents-mcp?
面向 Cursor 等工具的 MCP server,可将任务委派给不同专长的 AI assistants,提升协作效率。
README
Sub-Agents MCP Server
Bring Claude Code–style sub-agents to any MCP-compatible tool.
This MCP server lets you define task-specific AI agents (like "test-writer" or "code-reviewer") in markdown files, and execute them via Cursor CLI, Claude Code, Gemini CLI, or Codex backends.
Why?
Claude Code offers powerful sub-agent workflows—but they're limited to its own environment. This MCP server makes that workflow portable, so any MCP-compatible tool (Cursor, Claude Desktop, Windsurf, etc.) can use the same agents.
Concrete benefits:
- Define reusable agents once, use them across multiple tools
- Share agent definitions within teams regardless of IDE choice
- Leverage Cursor CLI, Claude Code, Gemini CLI, or Codex capabilities from any MCP client
Alternative: Agent Skills
sub-agents-skills offers a lightweight alternative.
| sub-agents-mcp | sub-agents-skills | |
|---|---|---|
| Setup | MCP configuration required | Copy skill files to your environment |
| Features | Session management, error handling | Minimal |
| Stability | More robust | Lightweight |
Choose sub-agents-mcp for production use with reliability features. Choose sub-agents-skills for quick setup in Skill-compatible environments.
Table of Contents
- Prerequisites
- Quick Start
- Usage Examples
- Writing Effective Agents
- Agent Examples
- Configuration Reference
- Session Management
- Troubleshooting
- Design Philosophy
- How It Works
Prerequisites
- Node.js 22 or higher
- One of these execution engines (they actually run the sub-agents):
cursor-agentCLI (from Cursor)claudeCLI (from Claude Code)geminiCLI (from Gemini CLI)codexCLI (from Codex)
- An MCP-compatible tool (Cursor IDE, Claude Desktop, Windsurf, etc.)
Quick Start
1. Create Your First Agent
Create a folder for your agents and add code-reviewer.md:
# Code Reviewer
Review code for quality and maintainability issues.
## Task
- Find bugs and potential issues
- Suggest improvements
- Check code style consistency
## Done When
- All target files reviewed
- Issues listed with explanations
See Writing Effective Agents for more on agent design.
2. Install Your Execution Engine
Pick one based on which tool you use:
For Cursor users:
# Install Cursor CLI (includes cursor-agent)
curl https://cursor.com/install -fsS | bash
# Authenticate (required before first use)
cursor-agent login
For Claude Code users:
# Option 1: Native install (recommended)
curl -fsSL https://claude.ai/install.sh | bash
# Option 2: NPM (requires Node.js 18+)
npm install -g @anthropic-ai/claude-code
Note: Claude Code installs the claude CLI command.
For Gemini CLI users:
# Install Gemini CLI
npm install -g @google/gemini-cli
# Authenticate via browser (required before first use)
gemini
Note: Gemini CLI uses OAuth authentication. Run gemini once to authenticate via browser.
For Codex users:
# Install Codex
npm install -g @openai/codex
3. Configure MCP
Add this to your MCP configuration file:
Cursor: ~/.cursor/mcp.json
Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
{
"mcpServers": {
"sub-agents": {
"command": "npx",
"args": ["-y", "sub-agents-mcp"],
"env": {
"AGENTS_DIR": "/absolute/path/to/your/agents-folder",
"AGENT_TYPE": "cursor" // or "claude", "gemini", or "codex"
}
}
}
}
Important: Use absolute paths only.
- ✅
/Users/john/Documents/my-agents(Mac/Linux) - ✅
C:\\Users\\john\\Documents\\my-agents(Windows) - ❌
./agentsor~/agentswon't work
Restart your IDE and you're ready to go.
4. Fix "Permission Denied" Errors When Running Shell Commands
Sub-agents may fail to execute shell commands with permission errors. This happens because sub-agents can't respond to interactive permission prompts.
Recommended approach:
-
Run your CLI tool directly with the task you want sub-agents to handle:
bash# For Cursor users cursor-agent # For Claude Code users claude # For Gemini CLI users gemini # For Codex CLI users codex -
When prompted to allow commands (e.g., "Add Shell(cd), Shell(make) to allowlist?"), approve them
-
This automatically updates your configuration file, and those commands will now work when invoked via MCP sub-agents
Manual configuration (alternative):
If you prefer to configure permissions manually, edit:
- Cursor:
<project>/.cursor/cli.jsonor~/.cursor/cli-config.json - Claude Code:
.claude/settings.jsonor.claude/settings.local.json
{
"permissions": {
"allow": [
"Shell(cd)",
"Shell(make)",
"Shell(git)"
]
}
}
Note: Agents often run commands as one-liners like cd /path && make build, so you need to allow all parts of the command.
Usage Examples
Just tell your AI to use an agent:
"Use the code-reviewer agent to check my UserService class"
"Use the test-writer agent to create unit tests for the auth module"
"Use the doc-writer agent to add JSDoc comments to all public methods"
Your AI automatically invokes the specialized agent and returns results.
Tip: Always include what you want done in your request—not just which agent to use. For example:
- ✅ "Use the code-reviewer agent to check my UserService class"
- ❌ "Use the code-reviewer agent" (too vague—the agent won't know what to review)
The more specific your task, the better the results.
Writing Effective Agents
The Single Responsibility Principle
Each agent should do one thing well. Avoid "swiss army knife" agents.
| ✅ Good | ❌ Bad |
|---|---|
| Reviews code for security issues | Reviews code, writes tests, and refactors |
| Writes unit tests for a module | Writes tests and fixes bugs it finds |
Essential Structure
# Agent Name
One-sentence purpose.
## Task
- Action 1
- Action 2
## Done When
- Criterion 1
- Criterion 2
Keep Agents Self-Contained
Agents run in isolation with fresh context. Avoid:
- References to other agents ("then use X agent...")
- Assumptions about prior context ("continuing from before...")
- Scope creep beyond the stated purpose
Advanced Patterns
For complex agents, consider adding:
- Scope boundaries: Explicitly state what's out of scope
- Prohibited actions: List common mistakes the agent should avoid
- Output format: Define structured output when needed
Agent Examples
Each .md or .txt file in your agents folder becomes an agent. The filename becomes the agent name (e.g., bug-investigator.md → "bug-investigator").
bug-investigator.md
# Bug Investigator
Investigate bug reports and identify root causes.
## Task
- Collect evidence from error logs, code, and git history
- Generate multiple hypotheses for the cause
- Trace each hypothesis to its root cause
- Report findings with supporting evidence
## Out of Scope
- Fixing the bug (investigation only)
- Making assumptions without evidence
## Done When
- At least 2 hypotheses documented with evidence
- Most likely cause identified with confidence level
- Affected code locations listed
For more advanced patterns (completion checklists, prohibited actions, structured output), see claude-code-workflows/agents. These are written for Claude Code, but the design patterns apply to any execution engine.
Configuration Reference
Required Environment Variables
AGENTS_DIR
Path to your agents folder. Must be absolute.
AGENT_TYPE
Which execution engine to use:
"cursor"- usescursor-agentCLI"claude"- usesclaudeCLI"gemini"- usesgeminiCLI"codex"- usescodexCLI (OpenAI Codex)
Optional Settings
EXECUTION_TIMEOUT_MS
How long agents can run before timing out (default: 5 minutes, max: 10 minutes)
AGENTS_SETTINGS_PATH
Path to custom CLI settings directory for sub-agents.
Each CLI normally reads settings from project-level directories (.claude/, .cursor/, .codex/) or user-level directories (~/.claude/, ~/.cursor/, ~/.codex/). If you want sub-agents to run with different settings (e.g., different permissions or model), specify a separate settings directory here.
Supported CLI types: claude, cursor, codex
Note: Gemini CLI does not support custom settings paths, so this option has no effect when AGENT_TYPE is gemini.
Example with custom settings:
{
"mcpServers": {
"sub-agents": {
"command": "npx",
"args": ["-y", "sub-agents-mcp"],
"env": {
"AGENTS_DIR": "/absolute/path/to/agents",
"AGENT_TYPE": "cursor",
"EXECUTION_TIMEOUT_MS": "600000",
"AGENTS_SETTINGS_PATH": "/absolute/path/to/custom-cli-settings"
}
}
}
}
Security Note
Agents have access to your project directory. Only use agent definitions from trusted sources.
Session Management
Session management allows sub-agents to remember previous executions, which helps when you want agents to build on earlier work or maintain context across multiple calls.
Why Sessions Matter
By default, each sub-agent execution starts with no context. With sessions enabled:
- Agents can reference their earlier work
- You get execution history for debugging
- Related tasks share context
Enabling Sessions
Add these environment variables to your MCP configuration:
{
"mcpServers": {
"sub-agents": {
"command": "npx",
"args": ["-y", "sub-agents-mcp"],
"env": {
"AGENTS_DIR": "/absolute/path/to/agents",
"AGENT_TYPE": "cursor",
"SESSION_ENABLED": "true",
"SESSION_DIR": "/absolute/path/to/session-storage",
"SESSION_RETENTION_DAYS": "1"
}
}
}
}
Configuration options:
SESSION_ENABLED- Set to"true"to enable session management (default:false)SESSION_DIR- Where to store session files (default:.mcp-sessionsin the current working directory)SESSION_RETENTION_DAYS- How long to keep session files based on last modification time in days (default: 1)
Security consideration: Session files contain execution history and may include sensitive information. Use absolute paths for SESSION_DIR.
When to Use Sessions
Sessions work well for:
- Iterative development: "Based on your earlier findings, now fix the issues"
- Multi-step workflows: Breaking complex tasks into smaller sub-agent calls
- Debugging: Reviewing exactly what was executed and what results were returned
Note that sessions require additional storage and processing overhead.
How Session Continuity Works
When sessions are enabled, the MCP response includes a session_id field. To continue the same session, pass this ID back in the next request.
Important: Your AI assistant must explicitly include the session_id in subsequent requests. While some assistants may do this automatically, it's not guaranteed. For reliable session continuity, add explicit instructions to your prompts or project rules.
Example prompt instruction:
When using sub-agents with sessions enabled, always include the session_id
from the previous response in your next request to maintain context.
Example project rule (e.g., AGENTS.md):
# Sub-Agent Session Guidelines
When calling the same sub-agent multiple times:
1. Extract the session_id from the MCP response
2. Pass it as a parameter in subsequent calls
3. This preserves context between executions
Troubleshooting
Timeout errors or authentication failures
If using Cursor CLI:
Run cursor-agent login to authenticate. Sessions can expire, so just run this command again if you see auth errors.
Verify installation:
which cursor-agent
If using Claude Code: Make sure the CLI is properly installed and accessible.
Agent not found
Check that:
AGENTS_DIRpoints to the correct directory (use absolute path)- Your agent file has
.mdor.txtextension - The filename uses hyphens or underscores (no spaces)
Other execution errors
- Verify
AGENT_TYPEis set correctly (cursor,claude,gemini, orcodex) - Ensure your chosen CLI tool is installed and accessible
- Double-check that all environment variables are set in the MCP config
Recursive sub-agent calls (infinite loop)
If sub-agents keep spawning more sub-agents, there are typically two causes:
1. MCP configuration inheritance
Create a separate settings directory without the sub-agents MCP configuration and specify it via AGENTS_SETTINGS_PATH. This prevents sub-agents from having access to this MCP server.
2. AGENTS.md instruction inheritance (Codex)
Codex concatenates AGENTS.md from CODEX_HOME and project root. If your project AGENTS.md has delegation instructions, sub-agents inherit them too.
Solution: Don't place AGENTS.md at the project root. Use separate directories:
/your-project
├── .codex-main/AGENTS.md # Main agent instructions
├── .codex-sub/AGENTS.md # Sub-agent instructions (no delegation)
└── (no AGENTS.md at root)
- Run main Codex with
CODEX_HOME=/your-project/.codex-main - Set
AGENTS_SETTINGS_PATH=/your-project/.codex-subin sub-agents-mcp config
Design Philosophy
Why Independent Contexts Matter
Every sub-agent starts with a fresh context. This adds some startup overhead for each call, but it ensures that every task runs independently and without leftover state from previous runs.
Context Isolation
- Each agent only receives the information relevant to its task
- No context leakage between runs
- The main agent stays focused and lightweight
Accuracy and Reliability
- Sub-agents can specialize in a single goal without interference
- Less risk of confusion from unrelated context
- More consistent results in complex, multi-step workflows
Scalability
- Large tasks can be safely split into smaller sub-tasks
- Each sub-agent operates within its own token limit
- The main agent coordinates without hitting global context limits
The startup overhead is an intentional trade-off: the system favors clarity and accuracy over raw execution speed.
How It Works
This MCP server acts as a bridge between your AI tool and a supported execution engine (Cursor CLI, Claude Code, Gemini CLI, or Codex).
The flow:
- You configure the MCP server in your client (Cursor, Claude Desktop, etc.)
- The client automatically launches
sub-agents-mcpas a background process when it starts - When your main AI assistant needs a sub-agent, it makes an MCP tool call
- The MCP server reads the agent definition (markdown file) and invokes the selected CLI (
cursor-agent,claude,gemini, orcodex) - The execution engine runs the agent and streams results back through the MCP server
- Your main assistant receives the results and continues working
This architecture lets any MCP-compatible tool benefit from specialized sub-agents, even if it doesn't have native support.
License
MIT
AI-to-AI collaboration through Model Context Protocol
常见问题
io.github.shinpr/sub-agents-mcp 是什么?
面向 Cursor 等工具的 MCP server,可将任务委派给不同专长的 AI assistants,提升协作效率。
相关 Skills
MCP构建
by anthropics
聚焦高质量 MCP Server 开发,覆盖协议研究、工具设计、错误处理与传输选型,适合用 FastMCP 或 MCP SDK 对接外部 API、封装服务能力。
✎ 想让 LLM 稳定调用外部 API,就用 MCP构建:从 Python 到 Node 都有成熟指引,帮你更快做出高质量 MCP 服务器。
Slack动图
by anthropics
面向Slack的动图制作Skill,内置emoji/消息GIF的尺寸、帧率和色彩约束、校验与优化流程,适合把创意或上传图片快速做成可直接发送的Slack动画。
✎ 帮你快速做出适配 Slack 的动图,内置约束规则和校验工具,少踩上传与播放坑,做表情包和演示都更省心。
MCP服务构建器
by alirezarezvani
从 OpenAPI 一键生成 Python/TypeScript MCP server 脚手架,并校验 tool schema、命名规范与版本兼容性,适合把现有 REST API 快速发布成可生产演进的 MCP 服务。
✎ 帮你快速搭建 MCP 服务与后端 API,脚手架完善、扩展顺手,尤其适合想高效验证服务能力的开发者。
相关 MCP Server
Slack 消息
编辑精选by Anthropic
Slack 是让 AI 助手直接读写你的 Slack 频道和消息的 MCP 服务器。
✎ 这个服务器解决了团队协作中需要 AI 实时获取 Slack 信息的痛点,特别适合开发团队让 Claude 帮忙汇总频道讨论或发送通知。不过,它目前只是参考实现,文档有限,不建议在生产环境直接使用——更适合开发者学习 MCP 如何集成第三方服务。
by netdata
io.github.netdata/mcp-server 是让 AI 助手实时监控服务器指标和日志的 MCP 服务器。
✎ 这个工具解决了运维人员需要手动检查系统状态的痛点,最适合 DevOps 团队让 Claude 自动分析性能数据。不过,它依赖 NetData 的现有部署,如果你没用过这个监控平台,得先花时间配置。
by d4vinci
Scrapling MCP Server 是专为现代网页设计的智能爬虫工具,支持绕过 Cloudflare 等反爬机制。
✎ 这个工具解决了爬取动态网页和反爬网站时的头疼问题,特别适合需要批量采集电商价格或新闻数据的开发者。不过,它依赖外部浏览器引擎,资源消耗较大,不适合轻量级任务。