May 1, 2025
Tutorial
How to Connect Your CAMEL-AI Agent to External Tools via MCP
Seamlessly integrate databases, APIs, and web services into your CAMEL-AI agents using the Model Context Protocol.
May 1, 2025
Tutorial
Seamlessly integrate databases, APIs, and web services into your CAMEL-AI agents using the Model Context Protocol.
Have you ever watched a powerful AI model get stumped because it couldn’t access a simple piece of external information? Maybe you wanted it to read a local file or browse a web page, but it just sat there as if the outside world didn’t exist. It’s like having a genius with their hands tied behind their back.
CAMEL-AI agents aim to change that. In this blog, we’ll explore how CAMEL’s intelligent agents leverage the Model Context Protocol (MCP) to break free of isolation, dynamically manage context, and seamlessly invoke external tools. By the end, you’ll see how MCP acts as an “AI USB-C connector,” linking advanced reasoning to real-world action in a secure and flexible way
Model Context Protocol is an open standard designed to bridge AI models with external data sources, tools, and environments. Think of MCP as a universal intermediate protocol layer between a language model and the outside world. Instead of hard-coding bespoke integrations for each app or data source, MCP offers one standardized interface that any AI agent can use to discover and interact with any tool. It’s essentially the “USB-C of AI integration” – one plug that connects to many devices.
How does MCP work at a high level?It follows a simple client-server architecture
When an AI agent needs to use a tool, it doesn’t execute that tool’s logic internally. Instead, it sends a request via MCP to the appropriate server, which performs the action and returns the result.
This two-way connection means the agent can pull in external information or trigger actions on the fly, then incorporate the results into its own reasoning. All of this happens through a controlled protocol layer, keeping the model’s internal reasoning and the external operations neatly separated.
The Model Context Protocol has rapidly gained traction, fostering a vibrant ecosystem of tools, hubs, and frameworks. Below are key platforms and repositories that empower developers and organizations to build, discover, and integrate MCP servers seamlessly:
A centralized registry for MCP servers, offering pre-built tools for common tasks like web scraping, database access, and code execution. Smithery simplifies discovery and deployment, making it ideal for developers seeking plug-and-play solutions.
An AI orchestration platform that integrates MCP servers into complex workflows. Composio excels at connecting LLMs to enterprise systems (e.g., CRMs, ERPs) via standardized MCP interfaces, enabling scalable automation).
A lightweight hub for testing and deploying MCP servers. Designed for rapid prototyping, it provides templates and sandboxed environments to experiment with tools like file system access or API integrations.
Focuses on advanced context management for MCP servers, offering tools to handle large datasets, real-time data streams, and hybrid cloud environments. ACI.dev bridges the gap between AI reasoning and enterprise-grade infrastructure.
A Chinese-focused MCP platform under Alibaba’s ModelScope initiative. It hosts region-specific tools (e.g., multilingual NLP models, local databases) and fosters collaboration within Asia-Pacific developer communities.
A community-curated GitHub repository listing open-source MCP servers. From niche tools (e.g., IoT device controllers) to experimental integrations, this resource is invaluable for developers seeking inspiration or reusable code
CAMEL-AI is an open-source framework for building advanced multi-agent systems – essentially, AI agents that can collaborate and perform complex tasks. These agents are built on large language models (LLMs) and can reason about problems, talk to each other, and now, thanks to MCP, use external tools to augment their capabilities. Integrating MCP into CAMEL’s agents turns them into tool-empowered assistants with dynamic context management..
In practice, here’s how a CAMEL-AI agent utilizes MCP step by step:
Throughout this process, MCP is working behind the scenes as the communication layer. The agent doesn’t need to know the low-level details of how the fetch is performed – it just knows “there’s a tool I can call for that.” MCP standardizes the call and response so that any tool looks the same to the AI. This design makes the agent’s life much easier (and the developer’s life too!).
Dynamic context management is a big deal here. Because the agent can pull in information as needed, it isn’t limited to the static context it was given at the start of the conversation. The context can expand dynamically – the agent maintains a coherent conversation while bringing in new data from tools when relevant.
In other words, the assistant can maintain context across multiple tools instead of being siloed into one fixed knowledge base. One moment it’s reading a file, next it’s browsing the web, all the while remembering the core goal of the task. This fluid movement between different contexts and tools is orchestrated smoothly by MCP.
Integrating MCP into CAMEL-AI agents brings a host of benefits that elevate the agents’ capabilities. Let’s highlight a few key advantages:
In summary, MCP turns CAMEL-AI agents into tool-augmented AI with a modular toolkit, flexible skills, and a safe way to handle external information. It’s a big step toward more practical and trustworthy AI assistants.
Now for the fun part – wiring up a single CAMEL-AI agent to your MCP servers. CAMEL’s toolkit gives you a handy MCPToolkit that reads your config file, launches each server, and hands you ready-to-go tool interfaces. Let’s dive into a minimal Python example.
You can install the Playwright MCP service globally via npm:
npm install -g @executeautomation/playwright-mcp-server
Or you may define your MCP servers in a json file like mcp_servers_config.json:
{
"mcpServers": {
"desktop-commander": {
"command": "npx",
"args": ["-y", "@wonderwhy-er/desktop-commander"]
},
"playwright": {
"command": "npx",
"args": ["-y", "@executeautomation/playwright-mcp-server", "--browser", "chromium"]
},
"mcp-server-firecrawl": {
"command": "npx",
"args": ["-y", "firecrawl-mcp"]
}
}
}
With that in place, here’s the code to connect your agent, discover all MCP tools, and run a simple scraping task:
import sys
from pathlib import Path
from dotenv import load_dotenv
from camel.logger import set_log_level
from camel.toolkits import MCPToolkit
from camel.agents import ChatAgent
# 1. Setup logging and environment
set_log_level(level="DEBUG")
load_dotenv()
# 2. Load MCP server configuration and connect
def main():
config_path = Path(__file__).parent / "mcp_servers_config.json"
mcp_toolkit = MCPToolkit(config_path=str(config_path))
mcp_toolkit.connect()
# 3. Define the task prompt (override via CLI if provided)
default_task = (
"Scrape the top news headlines from TechCrunch using the firecrawl tool "
"and return the 5 most recent titles as a JSON array."
)
task = sys.argv[1] if len(sys.argv) > 1 else default_task
# 4. Retrieve all MCP tool clients
tools = [*mcp_toolkit.get_tools()]
# 5. Initialize a ChatAgent with system message and MCP tools
agent = ChatAgent(
system_message="You are a retrieval assistant. Use available tools to fetch or scrape data as needed.",
tools=tools
)
# 6. Execute the task
response = agent.step(task)
print("Result:", response)
# 7. Disconnect from MCP servers
mcp_toolkit.disconnect()
if __name__ == "__main__":
main()
In this example, we instantiated a ChatAgent and provided it with the full set of tools discovered via MCPToolkit.get_tools(). When you call agent.step(task), the agent will:
Under the hood, MCPToolkit handles launching, connecting, and orchestrating all MCP servers, keeping your agent code focused on high‑level tasks.
Execution flow recap: prompt → agent → tool → result → agent → output.
This pattern leverages asynchronous MCP calls for smooth tool invocation, yet returns a straightforward, synchronous answer from the agent’s perspective.
By integrating MCP, CAMEL-AI has essentially opened the door for its agents to plug into a vast (and growing) ecosystem of tools. The CAMEL-AI platform has an array of MCP “plugin” servers available – from simple utilities like the ones we used, to more specialized connectors for services like Google Docs, GitHub, databases, calendars, and even coding assistants.
CAMEL currently implements MCP client capabilities through two main classes: MCPToolkit and _MCPServer. These components allow CAMEL agents to connect to and use tools from external MCP servers.
CAMEL’s MCP implementation follows this structure:
MCPToolkit is the main entry point for MCP functionality in CAMEL. It manages connections to multiple MCP servers and aggregates their tools.
Key features:
Usage example:
from camel.toolkits.mcp_toolkit import MCPToolkit
# Create toolkit from config file
toolkit = MCPToolkit(config_path="mcp_config.json")
# Use connection as context manager
async with toolkit.connection() as connected_toolkit:
# Get all tools from connected servers
tools = connected_toolkit.get_tools()
# Use tools in an agent
agent = ChatAgent(tools=tools)
_MCPServer is an internal class that handles the connection to a single MCP server. It supports two connection modes:
Key features:
The MCP Hub (mcp.camel-ai.org ) is the official directory of Model Collaboration Protocol (MCP)-compliant servers, designed to empower CAMEL agents with specialized capabilities. Browse, filter, and deploy tools directly into your workflows without manual configuration.
Explore pre-built MCP servers categorized by use case (e.g., databases, web search, cloud services).
Click any tool to reveal its JSON configuration snippet , ready to copy into your mcp_config.json
Roleplaying is a part of CAMEL’s core Society module, will be exposed as an MCP server to enable dynamic social behavior simulations (e.g., debates, negotiations) as reusable tools.
CAMEL’s native solution for multi-agent orchestration, will become an MCP-compliant server to streamline hierarchical agent team deployment .
Intelligent discovery of relevant tools from registries like Smithery and the MCP Hub.
In conclusion, CAMEL-AI agents with MCP represent a leap toward more autonomous, context-aware AI. They combine the raw intelligence of LLMs with the practicality of software tools and the richness of real-world data. We started with the frustration of an isolated AI; we end with a vision (now a reality) of AI agents that can read, write, browse, click, and more – all safely and on demand.
It truly feels like the AI comes alive with abilities beyond its neural weights, reaching into a dynamic toolkit whenever the situation calls for it. You can checkout how you can use OWL with MCP
Happy experimenting, and may your agents never again complain about being stuck in a box when they have the whole world of tools at their fingertips! 🚀
Hello there, passionate AI enthusiasts! 🌟 We are 🐫 CAMEL-AI.org, a global coalition of students, researchers, and engineers dedicated to advancing the frontier of AI and fostering a harmonious relationship between agents and humans.
📘 Our Mission: To harness the potential of AI agents in crafting a brighter and more inclusive future for all. Every contribution we receive helps push the boundaries of what’s possible in the AI realm.
🙌 Join Us: If you believe in a world where AI and humanity coexist and thrive, then you’re in the right place. Your support can make a significant difference. Let’s build the AI society of tomorrow, together!