MCPAgent
MCPAgent is the new base class for AI Agents that also act as MCPs- this is to enable agents communicate and collaborate with each other; this will serve as the foundation for AgentNetwork
claude mcp add --transport stdio geniusgeek-mcpagent python -m mcp_agent \ --env OPENAI_API_KEY="Your OpenAI API key (if using OpenAI as the LLM backend)" \ --env ADDITIONAL_MCP_ENV="placeholder for any project-specific env vars" \ --env MCP_AGENT_LOG_LEVEL="INFO (optional, e.g., DEBUG, INFO, WARNING)"
How to use
MCPAgent extends the AutoGen/Ag2 ConversableAgent to implement the Model Context Protocol, enabling standardized context sharing, context management tools, and cross-agent tool calls. This server provides built-in context handling and a registry for MCP-compatible tools, plus the ability to register other MCPAgent instances as callable tools. With MCPAgent, you can manage contextual data (like user preferences, current task state, or shared workspace data), expose functions as tools that can be invoked via multiple formats (OpenAI function calls, explicit MCP calls, or natural language intents), and automatically incorporate relevant context into LLM prompts to produce more informed responses. The included examples show how to create a basic MCP-enabled agent, register custom tools (e.g., math operations), and wire in other agents as tools to build a networked agent collaboration. The framework is designed to be drop-in minimal configuration by simply inheriting from MCPAgent and registering tools or other agents as needed.
To use MCPAgent, instantiate an MCP-enabled agent in your Python project, optionally configure LLM capabilities, and start interacting via the provided tool interfaces. You can update and query context via agent.update_context and agent.execute_tool, generate responses that leverage the current context, and retrieve MCP information such as available tools and agent metadata through the mcp_info tool.
How to install
Prerequisites:
- Python 3.8+ installed on your system
- pip (Python package installer)
- Optional: OpenAI API key if you plan to use OpenAI as the LLM backend
Installation steps:
-
Install AutoGen (required dependency): pip install autogen
-
Include the MCPAgent module in your project:
- Place mcp_agent.py (or your packaged version) in your project directory or install the package that provides MCPAgent.
- If MCPAgent is available as a package, you can install it via pip as appropriate for your project setup.
-
Prepare to run MCPAgent:
- Ensure your environment variables are set (e.g., OPENAI_API_KEY if using OpenAI).
- Verify Python environment is active (virtualenv/venv recommended).
-
Run MCPAgent (example): python -m mcp_agent
Notes:
- The README sample uses a simple inheritance pattern to create MCP-enabled agents. Adapt the import path if your project layout differs.
- If you plan to run alongside other services, consider containerizing the setup or using a script to initialize required tools and agents.
Additional notes
Tips and common considerations:
- OpenAI integration: Set OPENAI_API_KEY in your environment if you plan to use the OpenAI model backend. You can also configure llm_config with the desired model and key.
- Context management: Use agent.update_context(key, value) to store context and agent.execute_tool('context_list') to inspect available context keys.
- Tool registration: Use agent.register_mcp_tool(...) to expose custom functions as MCP tools. You can also register other MCPAgent instances as tools for cross-agent collaboration.
- Tool call formats: MCPAgent supports direct method calls (execute_tool), OpenAI function call format, explicit MCP calls via mcp.call, and natural language intent detection. Ensure your tools are well-described to improve intent parsing.
- MCP information: Retrieve metadata about capabilities using the mcp_info tool, which reveals agent id, version, and available tools.
- Debugging: Set MCP_AGENT_LOG_LEVEL to DEBUG temporarily during development to gain detailed traces of tool dispatch and context handling.
Related MCP Servers
mysql_mcp_server
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
Lambda
Creates a simple MCP tool server with "streaming" HTTP.
jmeter
✨ JMeter Meets AI Workflows: Introducing the JMeter MCP Server! 🤯
quick -example
Short and sweet example MCP server / client implementation for Tools, Resources and Prompts.
asterisk
Asterisk Model Context Protocol (MCP) server.
mcp-community
Easily run, deploy, and connect to MCP servers