Build effective agents using Model Context Protocol and simple workflow patterns
Build effective agents using Model Context Protocol and simple workflow patterns
Build effective agents with Model Context Protocol using simple, composable patterns.
Examples | Building Effective Agents | MCP
mcp-agent is a simple, composable framework to build effective agents using Model Context Protocol.
[!Note] mcp-agent's vision is that MCP is all you need to build agents, and that simple patterns are more robust than complex architectures for shipping high-quality agents.
mcp-agent gives you the following:
Altogether, this is the simplest and easiest way to build robust agent applications.
We welcome all kinds of contributions, feedback and your help in improving this project.
…
Build an AgentConnect LLMs to MCP servers in simple, composable patterns like map-reduce, orchestrator, evaluator-optimizer, router & more. |
Create any kind of MCP ServerCreate MCP servers with a FastMCP-compatible API. You can even expose agents as MCP servers. |
Full MCP SupportCore: Tools ✅ Resources ✅ Prompts ✅ Notifications ✅ |
Durable Execution (Temporal)Scales to production workloads using Temporal as the agent runtime backend without any API changes. |
☁️ Deploy to CloudBeta: Deploy agents yourself, or use mcp-c for a managed agent runtime. All apps are deployed as MCP servers. |
mcp-agent's complete documentation is available at docs.mcp-agent.com, including full SDK guides, CLI reference, and advanced patterns. This readme gives a high-level overview to get you started.
llms-full.txt: contains entire documentation.llms.txt: sitemap listing key pages in the docs.[!TIP] The CLI is available via
uvx mcp-agent. To get up and running, scaffold a project withuvx mcp-agent initand deploy withuvx mcp-agent deploy my-agent.You can get up and running in 2 minutes by running these commands:
mkdir hello-mcp-agent && cd hello-mcp-agent uvx mcp-agent init uv init uv add "mcp-agent[openai]" # Add openai API key to `mcp_agent.secrets.yaml` or set `OPENAI_API_KEY` uv run main.py
We recommend using uv to manage your Python projects (uv init).
uv add "mcp-agent"Alternatively:
pip install mcp-agentAlso add optional packages for LLM providers (e.g. uv add "mcp-agent[openai, anthropic, google, azure, bedrock]").
[!TIP] The
examplesdirectory has several example applications to get started with. To run an example, clone this repo (or generate one withuvx mcp-agent init --template basic --dir my-first-agent)cd examples/basic/mcp_basic_agent # Or any other example # Option A: secrets YAML # cp mcp_agent.secrets.yaml.example mcp_agent.secrets.yaml && edit mcp_agent.secrets.yaml uv run main.py
Here is a basic "finder" agent that uses the fetch and filesystem servers to look up a file, read a blog and write a tweet. Example link:
finder_agent.py……mcp-agent?There are too many AI frameworks out there already. But mcp-agent is the only one that is purpose-built for a shared protocol - MCP.mcp-agent pairs Anthropic’s Building Effective Agents patterns with a batteries-included MCP runtime so you can focus on behaviour, not boilerplate. Teams pick it because it is:
Docs: Welcome to mcp-agent • Effective patterns overview.
Every project revolves around a single MCPApp runtime that loads configuration, registers agents and MCP servers, and exposes tools/workflows. The Core Components guide walks through these building blocks.
Initialises configuration, logging, tracing, and the execution engine so everything shares one context.
from mcp_agent.app import MCPApp
app = MCPApp(name="finder_app")
async def main():
async with app.run() as running_app:
logger = running_app.logger
logger.info("App ready", data={"servers": list(running_app.context.server_registry.registry)})Docs: MCPApp • Example: examples/basic/mcp_basic_agent.
Agents couple instructions with the MCP servers (and optional functions) they may call. AgentSpec definitions can be loaded from disk and turned into agents or Augmented LLMs with the factory helpers.
from pathlib import Path
from mcp_agent.agents.agent import Agent
from mcp_agent.workflows.factory import load_agent_specs_from_file
agent = Agent(
name="researcher",
instruction="Research topics using web and filesystem access",
server_names=["fetch", "filesystem"],
)
async with agent:
tools = await agent.list_tools()
async with app.run() as running_app:
specs = load_agent_specs_from_file(
str(Path("examples/basic/agent_factory/agents.yaml")),
context=running_app.context,
)Docs: Agents • Agent factory helpers • Examples: examples/basic/agent_factory.
Augmented LLMs wrap provider SDKs with the agent’s tools, memory, and structured output helpers. Attach one to an agent to unlock generate, generate_str, and generate_structured.
…Docs: Augmented LLMs • Examples: examples/basic/mcp_basic_agent and the workflow projects listed in gallery.md.
MCPApp decorators convert coroutines into durable workflows and tools. The same annotations work for both asyncio and Temporal execution.
from datetime import timedelta
from mcp_agent.executor.workflow import Workflow, WorkflowResult
@app.workflow
class PublishArticle(Workflow[WorkflowResult[str]]):
@app.workflow_task(schedule_to_close_timeout=timedelta(minutes=5))
async def draft(self, topic: str) -> str:
return f"- intro to {topic}\n- highlights\n- next steps"
@app.workflow_run
async def run(self, topic: str) -> WorkflowResult[str]:
outline = await self.draft(topic)
return WorkflowResult(value=outline)Docs: Decorator reference • Examples: examples/workflows.
Document an opt-in Memcode memory workflow for MCP Agent
Add ScreenContextAgent to MCP integration examples
Interested in a free security test for mcp-agent?
Support MCP server prompts
docs: openai.base_url /v1 vs MCP_API_BASE_URL for hosted Chat Completions hosts
Configurable max tool response size
Add an official HOL Guard pre-tool security example
Architecture: Preventing Context Drift in MCP Agents with Temporal Signatures
Agent identity for cross-org orchestration workflows
idea for rust wasm