CrewAI智能体开发:MCP服务器作为CrewAI中的工具
概述
模型上下文协议 (MCP) 提供了一种标准化的方式,使 AI 代理通过与外部服务(称为 MCP 服务器)通信来向 LLM 提供上下文。CrewAI 为 MCP 集成提供了两种方法:
???? 简单的 DSL 集成(推荐)直接在代理上使用 mcps 字段,实现无缝 MCP 工具集成。DSL 支持字符串引用(用于快速设置)和结构化配置(用于完全控制)。
基于字符串的引用(快速设置)非常适合远程 HTTPS 服务器和 CrewAI AOP 市场
from crewai import Agent
agent = Agent(
role="Research Analyst",
goal="Research and analyze information",
backstory="Expert researcher with access to external tools",
mcps=[
"https://mcp.exa.ai/mcp?api_key=your_key", # External MCP server
"https://api.weather.com/mcp#get_forecast",








