
mcp-agent
Agents assembled from the patterns in Anthropic's "Building Effective Agents", with MCP as the only tool interface
What is mcp-agent?
mcp-agent makes a narrow bet: if every tool an agent needs arrives over MCP, the framework can be small. It handles the tedious half of that — opening, holding and closing connections to MCP servers — and then supplies the well-known compositions from Anthropic's "Building Effective Agents" as pieces you can nest: a router that picks a specialist, an orchestrator that plans and delegates, an evaluator that sends work back for another pass. The same agent can be published as an MCP server itself. For runs that must survive a crash it can execute on Temporal, which brings pause and resume at the cost of a service to operate.
What can you do with mcp-agent?
- Name the servers, not the connections — You list which MCP servers an agent may use and the framework opens, keeps and closes those connections around the run.
- Pick a specialist with a router — A router reads the request and sends it to whichever agent or server is meant to handle it, instead of putting every tool in one prompt.
- Plan, delegate, and gather the results — The orchestrator breaks a task into steps, hands each to an agent, and assembles what comes back — the pattern behind most "research this for me" agents.
- Send weak work back for another pass — An evaluator judges the output against criteria you set and returns it to the writer until it passes, rather than shipping the first attempt.
- Publish the agent as an MCP server — The finished agent can be exposed over MCP itself, so another agent — or a desktop client — can call it as a single tool.
- Survive a crash with durable execution — Running on Temporal lets a workflow pause, resume and recover from where it stopped, without changing how the agent is written.
Before you choose mcp-agent
- Durable execution is the reason to choose it over a smaller library, and it requires running Temporal — a separate service with its own operational weight — alongside your agent.
- The repository has been quiet since early 2026, so check recent commits and releases before building something long-lived on it.
Frequently asked questions
Is mcp-agent free for commercial use?
mcp-agent is released under the Apache-2.0 licence — OSI-approved open source, which permits commercial use.
How can mcp-agent be deployed?
mcp-agent is available as Self-hosted / Runs locally.
Documentation
Reproduced from the lastmile-ai/mcp-agent README, published under Apache-2.0. Read the original ↗
Overview
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:
- Full MCP support: It fully implements MCP, and handles the pesky business of managing the lifecycle of MCP server connections so you don’t have to.
- Effective agent patterns: It implements every pattern described in Anthropic’s Building Effective Agents in a composable way, allowing you to chain these patterns together.
- Durable agents: It works for simple agents and scales to sophisticated workflows built on Temporal so you can pause, resume, and recover without any API changes to your agent.
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.
Minimal example
import asyncio
from mcp_agent.app import MCPApp
from mcp_agent.agents.agent import Agent
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
app = MCPApp(name="hello_world")
async def main():
async with app.run():
agent = Agent(
name="finder",
instruction="Use filesystem and fetch to answer questions.",
server_names=["filesystem", "fetch"],
)
async with agent:
llm = await agent.attach_llm(OpenAIAugmentedLLM)
answer = await llm.generate_str("Summarize README.md in two sentences.")
print(answer)
if __name__ == "__main__":
asyncio.run(main())
# Add your LLM API key to `mcp_agent.secrets.yaml` or set it in env.
# The [Getting Started guide](https://docs.mcp-agent.com/get-started/overview) walks through configuration and secrets in detail.
At a glance
Documentation & build with LLMs
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.- docs MCP server
Table of Contents
- Overview
- Minimal example
- Quickstart
- Why mcp-agent
- Core concepts
- Workflow patterns
- CLI reference
- Authentication
- Advanced
- Cloud deployment
- Examples
- FAQs
- Community & contributions
Get Started
[!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
Installation
We recommend using uv to manage your Python projects (uv init).
uv add "mcp-agent"
Alternatively:
pip install mcp-agent
Also add optional packages for LLM providers (e.g. uv add "mcp-agent[openai, anthropic, google, azure, bedrock]").
Quickstart
[!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:
import asyncio
import os
from mcp_agent.app import MCPApp
from mcp_agent.agents.agent import Agent
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
app = MCPApp(name="hello_world_agent")
async def example_usage():
async with app.run() as mcp_agent_app:
logger = mcp_agent_app.logger
# This agent can read the filesystem or fetch URLs
finder_agent = Agent(
name="finder",
instruction="""You can read local files or fetch URLs.
Return the requested information when asked.""",
server_names=["fetch", "filesystem"], # MCP servers this Agent can use
)
async with finder_agent:
# Automatically initializes the MCP servers and adds their tools for LLM use
tools = await finder_agent.list_tools()
logger.info(f"Tools available:", data=tools)
# Attach an OpenAI LLM to the agent (defaults to GPT-4o)
llm = await finder_agent.attach_llm(OpenAIAugmentedLLM)
# This will perform a file lookup and read using the filesystem server
result = await llm.generate_str(
message="Show me what's in README.md verbatim"
)
logger.info(f"README.md contents: {result}")
# Uses the fetch server to fetch the content from URL
result = await llm.generate_str(
message="Print the first two paragraphs from https://www.anthropic.com/research/building-effective-agents"
)
logger.info(f"Blog intro: {result}")
# Multi-turn interactions by default
result = await llm.generate_str("Summarize that in a 128-char tweet")
logger.info(f"Tweet: {result}")
if __name__ == "__main__":
asyncio.run(example_usage())
execution_engine: asyncio
logger:
transports: [console] # You can use [file, console] for both
level: debug
path: "logs/mcp-agent.jsonl" # Used for file transport
# For dynamic log filenames:
# path_settings:
# path_pattern: "logs/mcp-agent-{unique_id}.jsonl"
# unique_id: "timestamp" # Or "session_id"
# timestamp_format: "%Y%m%d_%H%M%S"
mcp:
servers:
fetch:
command: "uvx"
args: ["mcp-server-fetch"]
filesystem:
command: "npx"
args:
[
"-y",
"@modelcontextprotocol/server-filesystem",
"<add_your_directories>",
]
openai:
# Secrets (API keys, etc.) are stored in an mcp_agent.secrets.yaml file which can be gitignored
default_model: gpt-4o
Why use 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:
- Composable – every pattern ships as a reusable workflow you can mix and match.
- MCP-native – any MCP server (filesystem, fetch, Slack, Jira, FastMCP apps) connects without custom adapters.
- Production ready – Temporal-backed durability, structured logging, token accounting, and Cloud deploys are first-class.
- Pythonic – a handful of decorators and context managers wire everything together.
Docs: Welcome to mcp-agent • Effective patterns overview.
Core Components
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.
MCPApp
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 & AgentSpec
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 LLM
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.
from pydantic import BaseModel
from mcp_agent.workflows.llm.augmented_llm import RequestParams
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
class Summary(BaseModel):
title: str
verdict: str
async with agent:
llm = await agent.attach_llm(OpenAIAugmentedLLM)
report = await llm.generate_str(
message="Draft a 3-sentence release note from CHANGELOG.md",
request_params=RequestParams(maxTokens=400, temperature=0.2),
)
structured = await llm.generate_structured(
message="Return a JSON object with `title` and `verdict` summarising the README.",
response_model=Summary,
)
Docs: Augmented LLMs • Examples: examples/basic/mcp_basic_agent and the workflow projects listed in gallery.md.
Workflows & decorators
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.
Configuration & secrets
Settings load from mcp_agent.config.yaml, mcp_agent.secrets.yaml, environment variables, and optional preload strings. Keep secrets out of source control.
# mcp_agent.config.yaml
execution_engine: asyncio
mcp:
servers:
fetch:
command: "uvx"
args: ["mcp-server-fetch"]
filesystem:
command: "npx"
args: ["-y", "@modelcontextprotocol/server-filesystem"]
openai:
default_model: gpt-4o-mini
# mcp_agent.secrets.yaml (gitignored)
openai:
api_key: "${OPENAI_API_KEY}"
Docs: Configuration reference • Specify secrets.
MCP integration
Connect to existing MCP servers programmatically or aggregate several into one façade.
from mcp_agent.mcp.gen_client import gen_client
async with app.run():
async with gen_client("filesystem", app.server_registry, context=app.context) as client:
resources = await client.list_resources()
app.logger.info("Filesystem resources", data={"uris": [r.uri for r in resources.resources]})
Docs: MCP integration overview • Examples: examples/mcp.
This README has been shortened. The full version is on GitHub. Read the original ↗