AI Skill Hub 强烈推荐:MCP智能体框架 是一款优质的AI工具。已获得 8.3k 颗 GitHub Star,AI 综合评分 8.2 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
基于Model Context Protocol的开源智能体构建框架,提供简洁高效的工作流模式。适合开发者快速搭建对话型AI应用、自动化任务处理系统,支持多轮推理和复杂业务流程编排。
MCP智能体框架 是一款基于 Python 开发的开源工具,专注于 MCP协议、AI智能体、工作流引擎 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
基于Model Context Protocol的开源智能体构建框架,提供简洁高效的工作流模式。适合开发者快速搭建对话型AI应用、自动化任务处理系统,支持多轮推理和复杂业务流程编排。
MCP智能体框架 是一款基于 Python 开发的开源工具,专注于 MCP协议、AI智能体、工作流引擎 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:pip 安装(推荐)
pip install mcp-agent
# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install mcp-agent
# 方式三:从源码安装(获取最新功能)
git clone https://github.com/lastmile-ai/mcp-agent
cd mcp-agent
pip install -e .
# 验证安装
python -c "import mcp_agent; print('安装成功')"
# 命令行使用
mcp-agent --help
# 基本用法
mcp-agent input_file -o output_file
# Python 代码中调用
import mcp_agent
# 示例
result = mcp_agent.process("input")
print(result)
# mcp-agent 配置文件示例(config.yml) app: name: "mcp-agent" debug: false log_level: "INFO" # 运行时指定配置文件 mcp-agent --config config.yml # 或通过环境变量配置 export MCP_AGENT_API_KEY="your-key" export MCP_AGENT_OUTPUT_DIR="./output"
<p align="center"> <a href="https://docs.mcp-agent.com"><img src="https://github.com/user-attachments/assets/c8d059e5-bd56-4ea2-a72d-807fb4897bde" alt="Logo" width="300" /></a> </p>
<p align="center"> <em>Build effective agents with Model Context Protocol using simple, composable patterns.</em>
<p align="center"> <a href="https://github.com/lastmile-ai/mcp-agent/tree/main/examples" target="_blank"><strong>Examples</strong></a> | <a href="https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/overview" target="_blank"><strong>Building Effective Agents</strong></a> | <a href="https://modelcontextprotocol.io/introduction" target="_blank"><strong>MCP</strong></a> </p>
<p align="center"> <a href="https://docs.mcp-agent.com"><img src="https://img.shields.io/badge/docs-8F?style=flat&link=https%3A%2F%2Fdocs.mcp-agent.com%2F" /><a/> <a href="https://pypi.org/project/mcp-agent/"><img src="https://img.shields.io/pypi/v/mcp-agent?color=%2334D058&label=pypi" /></a> <img alt="Pepy Total Downloads" src="https://img.shields.io/pepy/dt/mcp-agent?label=pypi%20%7C%20downloads"/> <a href="https://github.com/lastmile-ai/mcp-agent/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg"/></a> <a href="https://lmai.link/discord/mcp-agent"><img src="https://img.shields.io/badge/Discord-%235865F2.svg?logo=discord&logoColor=white" alt="discord"/></a> </p>
<p align="center"> <a href="https://trendshift.io/repositories/13216" target="_blank"><img src="https://trendshift.io/api/badge/repositories/13216" alt="lastmile-ai%2Fmcp-agent | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a> </p>
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:
<u>Altogether, this is the simplest and easiest way to build robust agent applications</u>.
We welcome all kinds of contributions, feedback and your help in improving this project.
<a id="minimal-example"></a> Minimal example
```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())
```
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.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]").
Deploy to mcp-agent Cloud for managed Temporal execution, secrets, and HTTPS MCP endpoints.
uvx mcp-agent login
uvx mcp-agent deploy my-agent
uvx mcp-agent cloud apps list
Docs: Cloud overview • Deployment quickstart • Examples: examples/cloud.
Run uvx mcp-agent deploy <app-name> after logging in with uvx mcp-agent login. The CLI packages your project, provisions secrets, and exposes an MCP endpoint backed by a durable Temporal runtime. See the Cloud quickstart for step-by-step screenshots and CLI output.
[!TIP] Theexamplesdirectory 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:
<details open> <summary>finder_agent.py</summary>
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())
</details>
<details> <summary>mcp_agent.config.yaml</summary>
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
</details>
<details> <summary>Agent output</summary> <img width="2398" alt="Image" src="https://github.com/user-attachments/assets/eaa60fdf-bcc6-460b-926e-6fa8534e9089" /> </details>
Browse gallery.md for runnable examples, demo videos, and community projects grouped by concept. Every entry cites the docs page and command you need to run it locally.
Settings load from mcp_agent.config.yaml, mcp_agent.secrets.yaml, environment variables, and optional preload strings. Keep secrets out of source control.
```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
oauth: providers: github: client_id: "${GITHUB_CLIENT_ID}" client_secret: "${GITHUB_CLIENT_SECRET}" scopes: ["repo", "user"] ```
Docs: Advanced authentication • Server authentication • Examples: examples/basic/oauth_basic_agent.
logger: transports: [console] level: info otel: enabled: true exporters: - console
`TokenCounter` tracks token usage for agents, workflows, and LLM nodes. Attach watchers to stream updates or trigger alerts.
python
Build Settings objects programmatically when you need dynamic config (tests, multi-tenant hosts) instead of YAML files.
from mcp_agent.config import Settings, MCPSettings, MCPServerSettings
settings = Settings(
execution_engine="asyncio",
mcp=MCPSettings(
servers={
"fetch": MCPServerSettings(command="uvx", args=["mcp-server-fetch"]),
}
),
)
app = MCPApp(name="configured_app", settings=settings)
Docs: Configuring your application.
uvx mcp-agent scaffolds projects, manages secrets, inspects workflows, and deploys to Cloud.
uvx mcp-agent init --template basic # Scaffold a new project
uvx mcp-agent deploy my-agent # Deploy to mcp-agent Cloud
Docs: CLI reference • Getting started guides.
Every class, decorator, and CLI command is documented on docs.mcp-agent.com. The API reference and the llms-full.txt are designed so LLMs (or you) can ingest the whole surface area easily.
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 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.
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.
Key agent patterns are implemented as an AugmentedLLM. Use factory helpers to wire them up or inspect the runnable projects listed in gallery.md.
| Pattern | Helper | Summary | Docs |
|---|---|---|---|
| Parallel (Map-Reduce) | create_parallel_llm(...) | Fan-out specialists and fan-in aggregated reports.<br><a href="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F406bb032ca007fd1624f261af717d70e6ca86286-2401x1000.png&w=3840&q=75"><img src="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F406bb032ca007fd1624f261af717d70e6ca86286-2401x1000.png&w=3840&q=75" width="260"/></a> | [Parallel](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/map-reduce) |
| Router | create_router_llm(...) / create_router_embedding(...) | Route requests to the best agent, server, or function.<br><a href="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F5c0c0e9fe4def0b584c04d37849941da55e5e71c-2401x1000.png&w=3840&q=75"><img src="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F5c0c0e9fe4def0b584c04d37849941da55e5e71c-2401x1000.png&w=3840&q=75" width="260"/></a> | [Router](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/router) |
| Intent classifier | create_intent_classifier_llm(...) / create_intent_classifier_embedding(...) | Bucket user input into intents before automation. | [Intent classifier](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/intent-classifier) |
| Orchestrator-workers | create_orchestrator(...) | Generate plans and coordinate worker agents.<br><a href="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F8985fc683fae4780fb34eab1365ab78c7e51bc8e-2401x1000.png&w=3840&q=75"><img src="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F8985fc683fae4780fb34eab1365ab78c7e51bc8e-2401x1000.png&w=3840&q=75" width="260"/></a> | [Planner](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/planner) |
| Deep research | create_deep_orchestrator(...) | Long-horizon research with knowledge extraction and policy checks. | [Deep research](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/deep-research) |
| Evaluator-optimizer | create_evaluator_optimizer_llm(...) | Iterate until an evaluator approves the result.<br><a href="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F14f51e6406ccb29e695da48b17017e899a6119c7-2401x1000.png&w=3840&q=75"><img src="https://www.anthropic.com/_next/image?url=https%3A%2F%2Fwww-cdn.anthropic.com%2Fimages%2F4zrzovbb%2Fwebsite%2F14f51e6406ccb29e695da48b17017e899a6119c7-2401x1000.png&w=3840&q=75" width="260"/></a> | [Evaluator-optimizer](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/evaluator-optimizer) |
| Swarm | create_swarm(...) | Multi-agent handoffs compatible with OpenAI Swarm.<br><a href="https://github.com/openai/swarm/blob/main/assets/swarm_diagram.png?raw=true"><img src="https://github.com/openai/swarm/blob/main/assets/swarm_diagram.png?raw=true" width="220"/></a> | [Swarm](https://docs.mcp-agent.com/mcp-agent-sdk/effective-patterns/swarm) |
Mix and match AgentSpecs to build higher-level workflows using the factory helpers—routers, parallel pipelines, orchestrators, and more.
```python from mcp_agent.workflows.factory import create_router_llm
mcp-agent 是一个简单且可组合的框架,旨在利用 Model Context Protocol (MCP) 构建高效的智能体(Agents)。我们的核心理念是:MCP 是构建 Agent 的基石,相比复杂的架构,简单的设计模式能更稳健地交付高质量的 Agent。通过 mcp-agent,您可以获得完整的 MCP 支持,并利用简单的模式快速实现复杂的交互逻辑。
推荐使用 uv 来管��您的 Python 项目(执行 `uv init`)。您可以通过 `uv add "mcp-agent"` 进行安装。此外,您也可以使用传统的 `pip install mcp-agent` 命令。为了支持不同的 LLM 提供商,建议根据需求安装可选依赖包,例如:`uv add "mcp-agent[openai, anthropic, google, azure, bedrock]"`。
您可以直接通过项目中的 `examples` 目录开始探索。若要运行示例,请克隆本仓库,或使用命令 `uvx mcp-agent init --template basic --dir my-first-agent` 来快速生成一个基础模板。在运行前,请务必将 `mcp_agent.secrets.yaml.example` 复制为 `mcp_agent.secrets.yaml` 并配置您的 API 密钥。
项目的配置与敏感信息管理非常灵活。设置可以从 `mcp_agent.config.yaml`、`mcp_agent.secrets.yaml`、环境变量或可选的预加载字符串中加载。为了保证安全性,请务必将敏感的 API Key 存储在 secrets 文件中,避免将其提交至版本控制系统(Source Control)。
mcp-agent 提供了强大的 CLI 工具,通过 `uvx mcp-agent` 命令,您可以进行项目脚手架搭建、密钥管理、工作流检查以及向 Cloud 端部署。所有的类、装饰器和 CLI 命令均在官方文档中有详尽记录。此外,我们还提供了专门为 LLM 设计的 `llms-full.txt` 文件,方便 AI 直接摄取完整的 API 知识面。
项目的核心运行机制围绕 `MCPApp` 运行时展开,它负责加载配置、注册 Agents 和 MCP servers,并对外暴露 tools 与 workflows。通过使用 `MCPApp` 提供的装饰器,您可以轻松地将协程(coroutines)转换为持久化的 workflows 和 tools。这些注解在 `asyncio` 和 Temporal 执行引擎下均能保持一致的工作逻辑。
高星开源项目,MCP生态关键框架,提供简洁有效的智能体开发范式,社区活跃度高,适合快速原型和生产应用。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。
总体来看,MCP智能体框架 是一款质量优秀的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | mcp-agent |
| 原始描述 | 开源MCP工具:Build effective agents using Model Context Protocol and simple workflow patterns。⭐8.3k · Python |
| Topics | MCP协议AI智能体工作流引擎LLM应用框架Python开发 |
| GitHub | https://github.com/lastmile-ai/mcp-agent |
| License | Apache-2.0 |
| 语言 | Python |
收录时间:2026-05-14 · 更新时间:2026-05-16 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。