# mcp-agent

> Build composable agents on the Model Context Protocol

- Category: Agents & Automation / Multi-Agent Systems
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/lastmile-ai/mcp-agent
- Website: https://docs.mcp-agent.com
- Canonical page: https://ai-tldr.dev/tools/mcp-agent/

## In short

mcp-agent is a Python framework for building agents that connect large language models to Model Context Protocol (MCP) servers as tools. It sits in the Multi-Agent Systems category of the Agents & Automation tools and is open-source, written in Python and licensed Apache-2.0. To get started: install the package.

## Overview

mcp-agent is a Python framework for building agents that connect large language models to Model Context Protocol (MCP) servers as tools. It manages the lifecycle of MCP server connections for you, so you can focus on what the agent should do rather than the plumbing of starting, connecting to, and tearing down servers.

It is aimed at developers building multi-agent systems who want reusable patterns instead of bespoke architectures. The library implements the patterns from Anthropic's "Building Effective Agents" guide, such as router, orchestrator, evaluator-optimizer, and map-reduce, and lets you chain them together.

As a multi-agent framework, mcp-agent works for a single simple agent and scales up to durable workflows backed by Temporal, which let an agent pause, resume, and recover. Agents can also be exposed as MCP servers themselves using a FastMCP-compatible API.

## What it does

- Full MCP support, including tools, resources, prompts, notifications, plus OAuth, sampling, elicitation, and roots
- Manages the connection lifecycle of MCP servers so you don't handle it yourself
- Composable agent patterns (router, orchestrator, evaluator-optimizer, map-reduce) that chain together
- Durable execution on Temporal for pause, resume, and recovery without changing your agent code
- Expose your own agents as MCP servers via a FastMCP-compatible API
- Works with augmented LLM backends such as OpenAI

## Getting started

Install mcp-agent from PyPI, set an LLM API key, then run a minimal agent that talks to MCP servers.

1. Install the package

   Install mcp-agent from PyPI into your Python environment.

```bash
pip install mcp-agent
```

2. Configure your LLM key

   Add your LLM API key to mcp_agent.secrets.yaml or set it in your environment. The Getting Started guide covers configuration and secrets in detail.

3. Run a minimal agent

   Create an app, define an agent that uses the filesystem and fetch MCP servers, attach an LLM, and generate a response.

```python
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())
```

## When to use it

- Build an agent that reads local files and fetches web pages through MCP servers
- Compose multi-agent workflows using patterns like router, orchestrator, or evaluator-optimizer
- Run long-running, durable agents on Temporal that can pause, resume, and recover
- Expose an existing agent as an MCP server for other clients to call
