EggAI MCP Integration
This example demonstrates how to integrate Model Context Protocol (MCP) with EggAI, allowing you to easily connect and use MCP-compatible tools in your EggAI agents.
Overview
This example provides a way to integrate MCP tools with EggAI's agent framework, allowing agents to communicate with MCP-compatible tools through a standardized interface. The integration supports:
- Running MCP tools as EggAI agents
- Agent-to-agent communication using EggAI channels
- Tool discovery and usage in LLM conversations
Components
main.py
: Main chat application that demonstrates using MCP tools with LiteLLMmcp_utils.py
: Utility functions for MCP integration with EggAImcp_servers/
: Directory containing example MCP server implementationsfetch.py
: Example server for HTTP fetch operationsfilesystem.py
: Example server for filesystem operationssandbox/
: Directory used by the filesystem MCP server
Architecture
The example follows a layered architecture:
- MCP Servers: Third-party tools that implement the MCP protocol (fetch and filesystem in this example)
- EggAI MCP Adapters: Adapters that convert MCP server communication to EggAI channels
- EggAI Agent: A client agent that can discover and use MCP tools through EggAI channels
Prerequisites
- Python 3.9+
- Kafka (provided via Docker Compose)
- Node.js and npm (for filesystem MCP server)
- uvx (for fetch MCP server)
Ensure you have a valid OpenAI API key set in your environment:
Setup
-
Clone the repository and navigate to the MCP example directory:
-
Set up the environment using the provided Makefile:
-
Start the Kafka infrastructure with Docker Compose:
Running the Example
You can run the services individually or all at once:
Start individual services
-
Start the Fetch MCP service:
-
Start the Filesystem MCP service:
-
Start the chat application:
Start all services at once
Interacting with the Example
Once all services are running, you can interact with the chat interface. The agent has access to tools from both MCP services and can:
- Fetch data from the web using the Fetch MCP server
- Read and write files using the Filesystem MCP server
Example interactions: - "Can you fetch the content from https://example.com and save it to a file?" - "What files are available in the sandbox directory?" - "Read the content of file-1.txt"
Cleanup
When you're done with the example, you can clean up:
-
Stop the Docker services:
-
Clean up the environment:
Next Steps
Ready to explore further? Check out:
- Advanced Examples: Discover more complex use cases in the examples folder.
- Contribution Guidelines: Get involved and help improve EggAI!
- GitHub Issues: Submit a bug or feature request.
- Documentation: Refer to the official docs for deeper insights.