mcp-agent — Build AI Agents with MCP Patterns
mcp-agent is a Python framework for building AI agents using the Model Context Protocol. 8.2K+ GitHub stars. Implements composable workflow patterns (orchestrator, map-reduce, evaluator-optimizer, rou
What it is
mcp-agent is a Python framework for building AI agents that leverage the Model Context Protocol (MCP). It implements composable workflow patterns including orchestrator, map-reduce, evaluator-optimizer, and router patterns. Each pattern is a reusable building block for constructing complex agent systems.
This framework targets developers building multi-step AI agents who want structured patterns rather than ad-hoc chains. If you need agents that fan out work, evaluate results, and iteratively improve, mcp-agent provides the scaffolding.
How it saves time or tokens
Instead of implementing agent orchestration patterns from scratch, mcp-agent provides tested, reusable implementations. The workflow provides pip install commands and shows how to compose patterns. You define what each step does; the framework handles execution order, result aggregation, and error handling.
How to use
- Install mcp-agent:
# With uv (recommended)
uv add 'mcp-agent[anthropic]'
# With pip
pip install 'mcp-agent[anthropic]'
# Multiple providers
uv add 'mcp-agent[openai,anthropic,google]'
- Define an agent with workflow patterns:
from mcp_agent import Agent, OrchestratorWorkflow
agent = Agent(
name='research-agent',
model='claude-sonnet-4-20250514',
tools=['web-search', 'file-reader']
)
workflow = OrchestratorWorkflow(
agents=[agent],
objective='Research and summarize the topic'
)
result = await workflow.run('Latest developments in quantum computing')
- Compose patterns for complex workflows:
from mcp_agent import MapReduceWorkflow, EvaluatorWorkflow
# Fan out research, then synthesize
research = MapReduceWorkflow(
map_agent=researcher,
reduce_agent=synthesizer,
inputs=['topic1', 'topic2', 'topic3']
)
Example
from mcp_agent import Agent, RouterWorkflow
# Route tasks to specialized agents
coder = Agent(name='coder', model='claude-sonnet-4-20250514', tools=['filesystem'])
writer = Agent(name='writer', model='claude-sonnet-4-20250514', tools=['web-search'])
router = RouterWorkflow(
agents=[coder, writer],
routing_strategy='llm', # LLM decides which agent handles each task
)
result = await router.run('Write a Python script that scrapes news headlines')
Related on TokRepo
- Multi-agent frameworks -- Compare multi-agent orchestration tools
- AI tools for agents -- Agent building frameworks and tools
Common pitfalls
- MCP server connections must be configured before running agents. Ensure your .mcp.json or environment variables point to running MCP servers.
- Map-reduce workflows multiply API costs by the number of map operations. Monitor token usage when fanning out to many parallel agents.
- The evaluator-optimizer pattern can loop indefinitely if the evaluation criteria are too strict. Set a max_iterations limit.
Frequently Asked Questions
mcp-agent supports orchestrator (single agent with tools), map-reduce (fan out and aggregate), evaluator-optimizer (iterative improvement loop), router (route tasks to specialized agents), and pipeline (sequential processing) patterns.
mcp-agent is designed around MCP but can also work with direct tool implementations. MCP servers provide the tool layer, but you can define tools as Python functions if you prefer not to use MCP.
mcp-agent supports Anthropic, OpenAI, Google, Azure, and AWS Bedrock through optional dependencies. Install with the appropriate extras like mcp-agent[anthropic] or mcp-agent[openai].
An agent generates output, then an evaluator agent scores it against criteria. If the score is below the threshold, the optimizer provides feedback and the generator tries again. This loops until the quality threshold is met or max iterations are reached.
Yes. Patterns are composable. You can use a router to dispatch tasks, each routed agent can use map-reduce internally, and the final output can go through an evaluator-optimizer for quality assurance.
Citations (3)
- mcp-agent GitHub— mcp-agent implements composable workflow patterns for MCP-based agents
- MCP Specification— Model Context Protocol for AI tool integration
- Anthropic Agent Patterns— Orchestrator, map-reduce, evaluator-optimizer patterns
Related on TokRepo
Source & Thanks
Created by LastMile AI. Licensed under MIT. lastmile-ai/mcp-agent — 8,200+ GitHub stars