A sophisticated multi-agent system that leverages Agent-to-Agent (A2A) communication protocol, Azure OpenAI services, and Model Context Protocol (MCP) to provide comprehensive data analysis capabilities for both CSV files and SQL databases.
This project implements a distributed multi-agent architecture where specialized agents collaborate to provide data analysis services:
-
MCP Servers (Model Context Protocol)
- CSV MCP Server (Port 8000): Provides tools for CSV file operations including loading, analyzing, executing custom Python code, and generating visualizations
- MySQL MCP Server (Port 8001): Offers MySQL database operations such as query execution, database/table listing, and schema inspection
-
Specialized Agents
- CSV Agent (Port 5555): A semantic kernel-based agent specialized in CSV data analysis, connected to the CSV MCP Server via SSE (Server-Sent Events)
- MySQL Agent (Port 5556): A semantic kernel-based agent focused on SQL query execution and database operations, connected to the MySQL MCP Server via SSE
- Host Agent (Port 8002): An orchestration agent that coordinates between CSV and MySQL agents, providing a unified interface for users
-
Agent Initialization:
- Each agent is built using
semantic_kernel.agents.chat_completion.ChatCompletionAgent - Agents use Azure OpenAI's ChatCompletion service (deployment: gpt-4o-mini)
- Agents are configured with specific plugins (MCPSsePlugin) to communicate with their respective MCP servers
- Each agent is built using
-
A2A Protocol Communication:
- Agents expose their capabilities through A2A (Agent-to-Agent) protocol
- Each agent publishes an AgentCard describing its skills and capabilities
- The Host Agent uses A2AClient to communicate with both CSV and MySQL agents
- Messages are exchanged using the A2A protocol's SendMessageRequest/Response pattern
-
MCP Integration:
- MCP servers provide tool-based interfaces for specific operations
- Agents connect to MCP servers via SSE (Server-Sent Events) for real-time communication
- The semantic kernel's MCPSsePlugin enables agents to invoke MCP tools as native functions
- User submits a request to the Host Agent via web interface
- Host Agent analyzes the request and determines which specialized agent to invoke
- Host Agent sends an A2A message to the appropriate agent (CSV or MySQL)
- The specialized agent processes the request using its semantic kernel and MCP tools
- Results flow back through the A2A protocol to the Host Agent
- Host Agent returns the consolidated response to the user
Each agent leverages Microsoft's Semantic Kernel framework:
- ChatCompletionAgent: Provides LLM-powered reasoning capabilities
- Kernel Functions: Enable tool registration and invocation
- Chat History Management: Maintains conversation context per session
- Plugin System: Allows integration with external services (MCP servers)
The MCP servers act as tool providers:
CSV MCP Server Tools:
load_csv: Load CSV files into memorylist_datasets: Show all loaded datasetsget_dataset_info: Get detailed dataset informationexecute_analysis_code: Run custom Python code for analysisgenerate_basic_insights: Auto-generate statistical insightsexport_dataset: Export processed datasend_email: Send analysis results via email
MySQL MCP Server Tools:
execute_query: Run SQL querieslist_databases: Show available databaseslist_tables: List tables in a databasedescribe_table: Get table schematest_connection: Verify database connectivityupdate_connection: Change connection parameters
The system uses the A2A SDK for inter-agent communication:
- AgentCard: Describes agent capabilities and endpoints
- AgentSkill: Defines specific skills with examples
- MessageSendParams: Structures communication between agents
- A2AClient/A2ACardResolver: Handles agent discovery and messaging
All agents use Azure OpenAI for intelligent processing:
- Deployment: gpt-4o-mini model
- API Version: 2024-12-01-preview
- Configuration: Loaded from environment variables for security
- Usage: Powers natural language understanding and response generation
csv-sql-agents-with-mcp/
├── agents/ # Agent implementations
│ ├── csv_agent/ # CSV analysis agent
│ │ ├── __main__.py # A2A server setup
│ │ ├── agent.py # Semantic kernel agent
│ │ └── agent_executor.py # Request processing
│ ├── sql_agent/ # SQL query agent
│ │ ├── __main__.py # A2A server setup
│ │ ├── agent.py # Semantic kernel agent
│ │ └── agent_executor.py # Request processing
│ └── host_agent/ # Host orchestration agent
│ ├── main.py # FastAPI app with agents
│ └── index.html # Web interface
├── mcp-csv-analyzer/ # CSV MCP server
│ └── mcp_csv_analyzer/
│ └── server.py # MCP tool implementations
├── mysql_mcp/ # MySQL MCP server
│ └── main.py # MCP tool implementations
├── scripts/ # Entry point scripts
├── .env # Environment configuration
├── pyproject.toml # Unified project configuration
├── start_uv.bat # Windows batch script
└── README.md # This file
-
Clone the repository
-
Create a
.envfile in the root directory with your Azure OpenAI credentials:API_KEY=your_azure_openai_api_key_here END_POINT=your_azure_openai_endpoint DEPLOYMENT=gpt-4o-mini API_VERSION=2024-12-01-preview # Optional: MySQL configuration MYSQL_HOST=localhost MYSQL_USER=root MYSQL_PASSWORD=your_password MYSQL_DATABASE=your_database MYSQL_PORT=3306 -
Install dependencies using uv:
uv sync
- Docker and Docker Compose installed
- At least 4GB of available RAM
-
Windows:
docker-start.bat
-
Linux/Mac:
chmod +x docker-start.sh ./docker-start.sh
-
Copy the Docker environment template:
cp env.docker .env
-
Update
.envwith your Azure OpenAI credentials -
Build and start all services:
docker-compose build docker-compose up -d
-
Check service status:
docker-compose ps
The Docker setup includes:
- All 5 agent services (CSV MCP, MySQL MCP, CSV Agent, SQL Agent, Host Agent)
- MySQL 8.0 database for testing
- Shared network for inter-service communication
- Volume mounts for data persistence
- Health checks for proper startup ordering
# View logs for a specific service
docker-compose logs -f csv-agent
# Stop all services
docker-compose down
# Stop and remove all data volumes
docker-compose down -v
# Rebuild after code changes
docker-compose build --no-cache
# Scale a service
docker-compose up -d --scale csv-agent=2In Docker, services communicate using container names:
- CSV MCP Server:
http://csv-mcp-server:8000 - MySQL MCP Server:
http://mysql-mcp-server:8001 - CSV Agent:
http://csv-agent:5555 - SQL Agent:
http://sql-agent:5556 - MySQL Database:
mysql-db:3306
Run all services using the batch script:
start_uv.bat# CSV MCP Server (port 8000)
uv run csv-mcp-server
# MySQL MCP Server (port 8001)
set FASTMCP_PORT=8001 && uv run mysql-mcp-server
# CSV Agent (port 5555)
uv run csv-agent
# SQL Agent (port 5556)
uv run sql-agent
# Host Agent (port 8002)
uv run host-agent- CSV MCP Server: http://localhost:8000 (SSE endpoint: /sse)
- MySQL MCP Server: http://localhost:8001 (SSE endpoint: /sse)
- CSV Agent: http://localhost:5555 (A2A endpoint)
- SQL Agent: http://localhost:5556 (A2A endpoint)
- Host Agent: http://localhost:8002 (Web UI)
- Navigate to http://localhost:8002
- Enter your data analysis request in natural language
- The system will automatically route to the appropriate agent
Example requests:
- "Load the sales.csv file and show me the top 10 products by revenue"
- "Connect to the customer database and find all orders from last month"
- "Analyze the correlation between price and quantity in my dataset"
- "Show me all tables in the inventory database"
You can also communicate directly with individual agents via their A2A endpoints using the A2A client SDK.
The Host Agent uses Azure OpenAI to understand user intent and automatically routes requests to the appropriate specialized agent.
Each agent maintains conversation history, allowing for follow-up questions and contextual understanding.
Agents are augmented with MCP tools, combining LLM intelligence with deterministic operations.
The distributed nature allows for easy scaling and addition of new specialized agents.
All sensitive credentials are managed through environment variables.
- Add the tool function to the appropriate MCP server
- Decorate with
@mcp.tool() - The tool automatically becomes available to connected agents
- Create a new agent directory under
agents/ - Implement the semantic kernel agent
- Set up A2A server with AgentCard
- Add MCP plugin connections as needed
The Host Agent can be extended with new tools by:
- Creating new kernel functions with
@kernel_function - Adding them to the agent's plugin list
- Updating the system prompt to include new capabilities
- Port conflicts: Ensure ports 8000, 8001, 5555, 5556, and 8002 are available
- MCP connection issues: Start MCP servers before agents
- Azure OpenAI errors: Verify credentials in
.envfile - Agent communication failures: Check A2A endpoints are accessible
Enable detailed logging by setting:
logging.basicConfig(level=logging.DEBUG)- MCP Servers: Check
/healthendpoint - Agents: Verify A2A card at agent URL
- Host Agent: Access web UI at http://localhost:8002
- Separation of Concerns: Each agent specializes in its domain
- Modularity: Easy to add/remove agents without affecting others
- Scalability: Agents can be distributed across machines
- Flexibility: MCP tools can be updated independently
- Intelligence: LLM-powered understanding and reasoning
- Interoperability: A2A protocol enables cross-agent communication
- Add more specialized agents (e.g., Excel, MongoDB, APIs)
- Implement agent discovery service
- Add authentication and authorization
- Create Docker containers for easy deployment
- Implement result caching and optimization
- Add support for streaming responses
- Create agent orchestration workflows
