知识库 · AI 智能体
CAMEL-AI x MCP:一篇文章读懂如何让 AI 智能体玩转所有工具
MCP 是 Anthropic 提出的标准化工具调用协议,基于 JSON-RPC 2.0。CAMEL-AI 全面支持 MCP,让智能体能轻松连接任意 MCP Server,同时也可将自身暴露为 MCP Server,实现工具与多智能体的高效复用与协作。
CAMEL-AI x MCP:一篇文章读懂如何让 AI 智能体玩转所有工具
2025年5月14日修改
原创 Xiaotian CAMEL CAMEL AI2025年05月12日 23:30 英国
AI 的世界正在飞速变化,其中一个最令人兴奋的新进展就是 模型上下文协议(Model Context Protocol,简称 MCP) 。这是一个很酷的标准,有望彻底改变 AI 模型与外部工具打交道的方式。今天我想跟大家聊聊,我们 CAMEL AI 的多智能体框架是如何拥抱 MCP,把智能体的能力拉满!
MCP 是什么?为什么它这么重要?
简单说,MCP 是一种基于 JSON-RPC 2.0 的统一协议,它让 AI 模型能够用标准格式和外部工具沟通。那它为什么厉害呢?先来看看函数调用这件事是怎么演变的:
函数调用的进化史
2023 年之前 :那时的 LLM 还不会原生使用工具。大家只好通过 prompt 工程、解析输出,想办法让模型间接 "使用" 工具。像 LangChain、CAMEL 当时就做了很多这方面的事,但说实话,这方法挺麻烦。
2023 年 6 月 :OpenAI 推出了 GPT-4 的函数调用功能,可以直接用 JSON 输出来调用工具,终于像样了。
2024 年 11 月 :Anthropic 提出了 MCP 标准,正式把工具调用用 JSON-RPC 2.0 标准化了。
2025 年 :OpenAI、DeepMind 等大厂也加入 MCP 阵营,整个 AI 世界开始讲统一语言了!
为什么标准化这么重要?
以前我们每接一个工具就要为每个模型重新写对接,像在拼命造轮子。现在有了 MCP,只要双方都支持这个标准,直接就能对话。不仅开发快了,还让创新变得更容易。
MCP 背后的机制
MCP 架构其实很简洁,分成三个角色:
MCP Host(宿主) :像 Claude 桌面应用或 CAMEL agent,是模型的运行平台。
MCP Client(客户端) :负责把模型的请求发送给工具,然后再把结果送回来。
MCP Server(服务器) :真正执行功能的工具端,像一个插件服务。
只要把工具封装成 MCP Server,就可以被所有支持 MCP 的智能体使用,超方便。
CAMEL AI 怎么玩转 MCP
我们在 CAMEL 里对工具集成本来就做得不错,但 MCP 让我们如虎添翼。
最基本的工具接入
先来个例子,怎么把一个函数变成模型可调用的工具:
代码块
from camel.toolkits import FunctionTool
def my_weird_add(a: int, b: int) -> int:
return a + b + 7
agent = ChatAgent(tools=[FunctionTool(my_weird_add)])
response = agent.step("What is 15+15")
print(response.msgs[0].content)输出结果是: 37 ,因为它默默加了个 7~
CAMEL Agent 作为 MCP 客户端
将 Model Context Protocol(MCP)工具集成进 CAMEL-AI 十分简单。以下是如何将 CAMEL-AI 的智能体与一个 Time MCP 服务器进行连接的步骤:
第一步:配置你的 MCP 服务器
你需要先完成 MCP 服务器的基本配置,为 CAMEL Agent 提供上下文服务支持。
代码块
{
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time", "--local-timezone=Asia/Riyadh"]
}
}
}第二步:使用 MCPToolkit 连接服务器,并让工具可用于 Agent
接下来,使用 MCPToolkit 连接你的 MCP 服务器,并将其中的工具加载至 CAMEL Agent,可供其调用使用。
代码块
import asyncio
from camel.toolkits.mcp_toolkit import MCPToolkit, MCPClient
async def run_time_example():
# Initialize the MCPToolkit with your configuration file
mcp_toolkit = MCPToolkit(config_path="config/time.json")
# Connect to all configured MCP servers
await mcp_toolkit.connect()
camel_agent = ChatAgent(
model=model,
tools=[*mcp_toolkit.get_tools()],
)
response = await camel_agent.astep("What time is it now?")
print(response.msgs[0].content)
print(response.info['tool_calls'])
# Disconnect from all servers
await mcp_toolkit.disconnect()
await run_time_example()
'''
The current local time in Riyadh is 15:57 (3:57 PM).
[ToolCallingRecord(tool_name='get_current_time', args={'timezone': 'Asia/Riyadh'}, result='{\n "timezone": "Asia/Riyadh",\n "datetime": "2025-05-01T15:57:59+03:00",\n "is_dst": false\n}', tool_call_id='toolu_01Gwdy3Ppzf2z42t6YL7n7cE')]
''' 让 CAMEL 工具也能变成 MCP Server
CAMEL-AI Agents 也能作为 MCP 服务器使用
更令人兴奋的是,CAMEL-AI 智能体现在也可以作为 MCP 服务器对外开放。这意味着你可以为不同任务创建专属的智能体,并将它们作为服务提供给任何兼容 MCP 协议的模型使用,实现更高效的多智能体协作与工具复用。
代码块
# Create a default chat agent
chat_agent = ChatAgent()
chat_agent_description = "A general-purpose assistant that can answer questions and help with various tasks."
# Create a reasoning agent
reasoning_agent = ChatAgent(
model=ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type="gpt-4o-mini",
)
)
reasoning_agent_description = "A specialized assistant focused on logical reasoning and problem-solving."
# Create a search agent
search_agent = ChatAgent(
model=ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type="gpt-4o",
),
tools=[FunctionTool(SearchToolkit().search_brave)],
)
search_agent_description = "A research assistant capable of retrieving information from the web."
# Define your agent dictionary
agents_dict = {
"general": chat_agent,
"search": search_agent,
"reasoning": reasoning_agent,
}
# Add descriptions
description_dict = {
"general": chat_agent_description,
"search": search_agent_description,
"reasoning": reasoning_agent_description,
} 这些智能体随后可以被公开为 MCP 服务器,允许其他系统调用它们的专属能力,从而实现跨系统协作与能力共享。
与 Claude Desktop 集成使用
你也可以通过配置相应参数,在 Claude Desktop 中与 CAMEL-AI 智能体进行交互。
这种集成方式让你无需离开桌面应用环境,即可调用 CAMEL-AI 的能力,实现更自然的对话式操作和多智能体协同体验。
代码块
"camel-chat-agent": {
"command": "/path/to/python",
"args": [
"/path/to/camel/services/agent_mcp_server.py"
],
"env": {
"OPENAI_API_KEY": "...",
"OPENROUTER_API_KEY": "...",
"BRAVE_API_KEY": "..."
}
}该配置使 Claude 能够无缝连接并调用 CAMEL-AI 智能体的能力,打造一个强大的混合式 AI 系统,充分结合两个平台的优势。
配置完成后,我们便可以在 Claude Desktop 中直接与 CAMEL-AI 智能体对话。以下截图展示了实际使用效果:Claude 成功连接至 CAMEL-AI 智能体,并调用其中一个智能体顺利执行了任务。
如何将你的工具在 CAMEL 中变为 MCP 服务器
我们在集成 Model Context Protocol(MCP)过程中,最令人兴奋的特性之一就是: 可以将任意 CAMEL-AI 工具包变成一个 MCP 服务器 。这意味着你在 CAMEL-AI 中开发的任何工具,都可以轻松共享给整个 AI 智能体生态,供其他模型和系统调用使用。
以下是将 ArxivToolkit 转换为 MCP 服务器的具体方法:
代码块
# arxiv_toolkit_server.py
import argparse
import sys
from camel.toolkits import ArxivToolkit
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Run Arxiv Toolkit in MCP server mode.",
usage=f"python {sys.argv[0]} [--mode MODE]",
)
parser.add_argument(
"--mode",
choices=["stdio", "sse"],
default="stdio",
help="MCP server mode (default: 'stdio')",
)
parser.add_argument(
"--timeout",
type=float,
default=None,
help="Timeout for the MCP server (default: None)",
)
args = parser.parse_args()
toolkit = ArxivToolkit(timeout=args.timeout)
# Run the toolkit as an MCP server
toolkit.run_mcp_server(mode=args.mode)OWL x MCP
OWL 是一个前沿的多智能体协作框架,构建于 CAMEL-AI Framework 之上,旨在突破任务自动化的边界。OWL 激活了 CAMEL-AI 中最强大的能力,包括:
角色扮演式智能体(Role-Playing Agents)
OWL 利用角色扮演的智能体协作方式,将复杂任务拆解并协同完成,保障自动化过程的高效与稳健。
实时决策机制(Real-Time Decision-Making)
通过 POMDP(部分可观测马尔可夫决策过程)等方法,OWL 能够动态优化每一步决策过程。
多模态工具集成(Multi-Modal Tool Integration)
无论是网页数据抓取、代码执行还是文档处理,OWL 都能集成多种工具,赋能复杂场景下的智能体协作。
不仅 CAMEL-AI 的智能体可以接入 MCP 服务器,OWL 的智能体同样具备这一能力!目前已有多个社区实践案例展示了 OWL 与 MCP 的集成能力:
WhatsApp MCP 案例
Notion MCP 案例
QWEN3 MCP 案例
这些案例展示了如何通过 MCP 实现与不同平台的连接,释放智能体在真实世界中的潜能。(链接请看这篇公众号评论区)
MCP 生态系统正在迅速发展
Model Context Protocol(MCP)生态系统正快速扩展,已有多个平台提供对 MCP 服务器的接入支持:
ACI.dev
Klavis AI
Pulse
Smithery
Composio
mcp.run
ModelScope
Awesome MCP Servers
这些平台均提供多种工具,可轻松集成至任意兼容 MCP 的模型中,极大地提升了模型的实用性与拓展性。
CAMEL MCP Hub
MCP Hub 是 CAMEL 官方推出的工具目录平台,聚合了所有符合 Model Collaboration Protocol(MCP)标准的服务器,助力 CAMEL 智能体快速接入各类专业能力,无需繁琐配置,轻松嵌入工作流程。
核心功能亮点
1. 交互式工具目录
可视化工具卡片 :在「CAMEL with MCP」页面浏览 MCP 工具,包括 Apify、Astra DB、Bing Search 等热门服务。
按场景分类 :工具按照数据库、网页搜索、云服务等使用场景分类展示,便于快速定位所需能力。
官方与第三方筛选 :可筛选 CAMEL 官方维护或社区提供的 MCP 工具,如 Anthropic、Microsoft 等。
2. 一键配置接入
点击即可获取 JSON 配置 :每个工具卡片都内嵌配置代码,点击即可复制,粘贴至 mcp_config.json 中即可启用。
无需手动调试 :开箱即用,适配 CAMEL 智能体,助你高效构建多能力协作系统。
我们还开发了专门的工具,帮助你更高效地发现已有的 MCP 服务器。
通过 MCPSearchToolkit ,你可以轻松查找最适合你需求的工具,无需手动筛选或配置,大幅提升集成效率。
无论是查找特定任务的解决方案,还是想快速浏览当前可用的工具集,MCPSearchToolkit 都是你探索 MCP 生态的理想助手。
代码块
search_toolkit = PulseMCPSearchToolkit()
search_toolkit.search_mcp_servers(
query="Slack",
package_registry="npm", # Only search for servers registered in npm
top_k=1,
)
'''
{
"name": "Slack",
"url": "https://www.pulsemcp.com/servers/slack",
"external_url": null,
"short_description": "Send messages, manage channels, and access workspace history.",
"source_code_url": "https://github.com/modelcontextprotocol/servers/tree/HEAD/src/slack",
"github_stars": 41847,
"package_registry": "npm",
"package_name": "@modelcontextprotocol/server-slack",
"package_download_count": 188989,
"EXPERIMENTAL_ai_generated_description": "This Slack MCP Server, developed by the Anthropic team, provides a robust interface for language models to interact with Slack workspaces. It enables AI agents to perform a wide range of Slack-specific tasks including listing channels, posting messages, replying to threads, adding reactions, retrieving channel history, and accessing user information. The implementation distinguishes itself by offering comprehensive Slack API integration, making it ideal for AI-driven workplace communication and automation. By leveraging Slack's Bot User OAuth Tokens, it ensures secure and authorized access to workspace data. This tool is particularly powerful for AI assistants designed to enhance team collaboration, automate routine communication tasks, and provide intelligent insights from Slack conversations."
}
'''它会返回关于可用 Slack MCP 服务器的详细信息,包括其支持的功能、相关文档以及使用统计数据等。
通过这些信息,你可以快速判断该服务器是否适合你的智能体使用场景,并实现精准、高效的工具接入。
MCP 搜索智能体
为了让发现 MCP 服务器更加便捷,我们创建了 MCPAgent ,它可以根据你的查询动态搜索并集成 MCP 服务器。
下面的示例中,我们使用的是 Smithery 的 MCP 注册中心 :
代码块
from camel.agents import MCPAgent, MCPRegistryConfig, MCPRegistryType
smithery_config = MCPRegistryConfig(
type=MCPRegistryType.SMITHERY,
api_key=os.getenv("SMITHERY_API_KEY")
)
# Create MCPAgent with registry configurations
agent = MCPAgent(
model=model,
registry_configs=[smithery_config]
)
async with agent:
response = await agent.astep("Use Brave API to search info about CAMEL-AI.org")
print(response.msgs[0].content)
"""
Response from Use Brave MCP search tools to search info about CAMEL-AI.org.:
# CAMEL-AI.org: Information and Purpose
Based on my search results, here's what I found about CAMEL-AI.org:
## Organization Overview
CAMEL-AI.org is the first LLM (Large Language Model) multi-agent framework and
an open-source community. The name CAMEL stands for "Communicative Agents for
Mind Exploration of Large Language Model Society."
## Core Purpose
The organization is dedicated to "Finding the Scaling Law of Agents" - this
appears to be their primary research mission, focusing on understanding how
agent-based AI systems scale and develop.
## Research Focus
CAMEL-AI is a research-driven organization that explores:
- Scalable techniques for autonomous cooperation among communicative agents
- Multi-agent frameworks for AI systems
- Data generation for AI training
- AI society simulations
## Community and Collaboration
- They maintain an active open-source community
- They invite contributors and collaborators through platforms like Slack and
Discord
- The organization has a research collaboration questionnaire for those
interested in building or researching environments for LLM-based agents
## Technical Resources
- Their code is available on GitHub (github.com/camel-ai) with 18 repositories
- They provide documentation for developers and researchers at
docs.camel-ai.org
- They offer tools and cookbooks for working with their agent framework
## Website and Online Presence
- Main website: https://www.camel-ai.org/
- GitHub: https://github.com/camel-ai
- Documentation: https://docs.camel-ai.org/
The organization appears to be at the forefront of research on multi-agent AI
systems, focusing on how these systems can cooperate autonomously and scale
effectively.
"""该智能体可以搜索相关的 MCP 服务器,解释它们的功能,甚至直接通过这些服务器执行查询任务。
例如,查询 “Gmail 工具” 会返回多个 Google Workspace 相关服务器的信息;而搜索 “CAMEL-AI” 则会检索网络内容,并返回关于我们组织的详细资料。
接下来的计划
我们正在不断推进 MCP 的深度集成,以下是我们正在开发并充满期待的一些方向:
MCP 搜索智能体(MCP Search Agents) :我们将扩展对更多 MCP 注册中心的支持,例如 Composio,让你能够接入更广泛的工具生态。
MCP Hub :我们正在建设自己的高质量 MCP 服务器仓库,确保为社区提供稳定、可靠的工具资源。
RolePlaying/Workforce作为 MCP 服务器 :我们正在将 CAMEL-AI 的多智能体模块转化为 MCP 服务器,实现更复杂的智能体交互与自动化工作流。
结语
MCP(Model Context Protocol)是 AI 系统演进过程中的关键一步。它通过标准化模型与外部工具的交互方式,让 AI 智能体变得更强大、更灵活,也更易于集成和部署。
在 CAMEL-AI,我们全面拥抱这一协议标准,积极构建强大的集成方案,充分释放 MCP 的潜能。无论你是接入现有的 MCP 服务器、创建自己的工具,还是将 CAMEL-AI 智能体转换为 MCP 服务器,我们的框架都能为你提供构建下一代 AI 智能体生态所需的一切工具。
欢迎加入我们,共同探索 MCP 为 AI 开发带来的无限可能!
都看到这了,别忘了给我们的GitHub点小星星呀🌟
来 CAMEL-AI 官网转转,加入我们的 微信群和Discord 吧!
请大家文明加群,严禁发布任何广告信息。请勿重复加群,所有通知将在各群同步发布~感谢支持!
往期内容推荐:
双周报
双周报
双周报
双周报
双周报
CAMEL微信群
加入CAMEL微信群,请添加CAMEL官方微信号CamelAIOrg,会有工作人员通过您的好友申请并邀请您加入我们的微信群~
Join CAMEL Community