A streamlined chart generation system with conversational AI interface:
- Chart MCP Server - Provides chart generation tools via MCP protocol
- Chart Agent - Conversational AI agent (DeepSeek-V3) that uses MCP tools
- Visualization Module - Matplotlib-based chart rendering
⚡ Quick Start: See QUICKSTART.md for the fastest way to get started!
┌──────────────────────────────────────────────────────────┐
│ User Input (CLI) │
│ "Create a bar chart of sales data" │
└────────────────────────┬─────────────────────────────────┘
▼
┌──────────────────────┐
│ Chart Agent │
│ (DeepSeek-V3) │
│ - No embedded tools│
│ - Pure AI reasoning│
└──────────┬───────────┘
│
│ MCP Protocol (HTTP)
▼
┌──────────────────────┐
│ Chart MCP Server │
│ Port: 8000 │
│ - generate_chart │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Chart Visualizer │
│ (Matplotlib) │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ PNG Chart Files │
│ ./generated_charts/ │
└──────────────────────┘
- ✅ Minimal FastMCP-based server focused solely on chart generation
- ✅
/chartcommand handler with structured payload formatting - ✅ HTTP communication with Chart Agent
- ✅ Pydantic AI agent for intelligent chart analysis
- ✅ Precise Pydantic request/response models
- ✅ FastAPI endpoint for receiving MCP requests
- ✅ Data parsing for both single-series and multi-series data
- ✅ Chart generation using Matplotlib
- ✅ Support for bar, line, pie, scatter, area, and histogram charts
- ✅ Configurable styling (dimensions, colors, legends, grid)
- ✅ Automatic file saving to accessible location
- ✅ MCP server sends HTTP requests to AI Agent
- ✅ Response handling with chart path display
- ✅ System validation tests
- ✅ Comprehensive README files
- ✅ Configuration examples
- ✅ Integration test suite
- Python 3.10 or higher
- pip package manager
- Clone or navigate to the project directory:
cd "/Users/aprim/Documents/CodeFolder/Excel Agent"- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows- Install dependencies:
# Install Chart Agent dependencies
pip install -r ChartAgent/requirements.txt
# Install Chart MCP dependencies
cd ChartMCP && pip install -e . && cd ..- Configure environment variables:
cp .env.example .env
# Edit .env and add your OPEN_ROUTER_API_KEY📖 See QUICKSTART.md for detailed instructions and examples!
Terminal 1 - Start MCP Server:
cd ChartMCP
python start_mcp.pyTerminal 2 - Start Chart Agent:
cd ChartAgent
python agent.py./start_chart_system.shThis will:
- Start the MCP server in the background
- Launch the chart agent CLI
- Auto-cleanup when you exit
Terminal 1 - MCP Server:
cd ChartMCP
python -m src.chart_mcpTerminal 2 - Chart Agent:
cd ChartAgent
python agent.pyRun the integration tests:
python test_integration.pyThis will test:
- Health checks
- Direct chart generation
- Multi-series charts
- AI analysis
- All chart types
The Chart MCP Server exposes a generate_chart tool:
{
"chart_type": "bar",
"title": "Monthly Sales",
"data_json": '[{"label": "Jan", "value": 1000}, {"label": "Feb", "value": 1500}]',
"x_label": "Month",
"y_label": "Sales ($)",
"width": 10,
"height": 6,
"show_legend": true,
"show_grid": true
}Single-series bar chart:
curl -X POST http://localhost:8001/generate-chart \
-H "Content-Type: application/json" \
-d '{
"chart_type": "bar",
"title": "Sales Data",
"data": [
{"label": "Q1", "value": 1000},
{"label": "Q2", "value": 1500},
{"label": "Q3", "value": 1800},
{"label": "Q4", "value": 2200}
],
"x_label": "Quarter",
"y_label": "Sales ($)"
}'Multi-series line chart:
curl -X POST http://localhost:8001/generate-chart \
-H "Content-Type: application/json" \
-d '{
"chart_type": "line",
"title": "Revenue Comparison",
"series": [
{
"name": "2023",
"data": [
{"label": "Q1", "value": 1000},
{"label": "Q2", "value": 1500},
{"label": "Q3", "value": 1800},
{"label": "Q4", "value": 2200}
]
},
{
"name": "2024",
"data": [
{"label": "Q1", "value": 1200},
{"label": "Q2", "value": 1700},
{"label": "Q3", "value": 2000},
{"label": "Q4", "value": 2500}
]
}
],
"x_label": "Quarter",
"y_label": "Revenue ($)"
}'Excel Agent/
├── ChartMCP/ # MCP Server
│ ├── src/chart_mcp/
│ │ ├── __init__.py
│ │ ├── __main__.py
│ │ ├── server.py # FastMCP server with tools
│ │ ├── config.py # Configuration
│ │ ├── models.py # Data models
│ │ └── visualizer.py # Matplotlib chart generation
│ ├── start_mcp.py # Simple launcher (NEW!)
│ ├── pyproject.toml
│ └── README.md
│
├── ChartAgent/ # AI Agent (Conversational CLI)
│ ├── __init__.py
│ ├── agent.py # Main agent with MCP integration
│ ├── requirements.txt
│ └── README.md
│
├── generated_charts/ # Output directory for charts
├── test_integration.py # Integration tests
├── start_chart_system.sh # Automated startup script
├── .env # Environment configuration
├── .env.example # Configuration template
├── QUICKSTART.md # Quick start guide (NEW!)
├── CLAUDE.md # Project evaluation
└── README.md # This file
Key Changes (Phase 6 Cleanup):
- ❌ Removed FastAPI server from ChartAgent (no longer needed)
- ❌ Removed embedded tools from agent.py
- ❌ Removed duplicate visualizer and models from ChartAgent
- ✅ Added
start_mcp.pyfor simple server startup - ✅ Agent now uses ONLY MCP server tools
Create a .env file based on .env.example:
# Chart Agent Configuration
OPEN_ROUTER_API_KEY=your-api-key-here
LLM_MODEL=openai/gpt-4-turbo-preview
CHART_OUTPUT_DIR=./generated_charts
AGENT_SERVER_HOST=0.0.0.0
AGENT_SERVER_PORT=8001
LOG_LEVEL=INFO
DEFAULT_DPI=100
DEFAULT_FORMAT=png
# Chart MCP Server Configuration
CHART_AGENT_URL=http://localhost:8001/generate-chart
MCP_SERVER_PORT=8000
MCP_SERVER_HOST=0.0.0.0| Type | Description | Best For |
|---|---|---|
bar |
Bar chart | Comparing categories |
line |
Line chart | Trends over time |
pie |
Pie chart | Proportions/percentages |
scatter |
Scatter plot | Relationships between variables |
area |
Area chart | Cumulative data over time |
histogram |
Histogram | Distribution of values |
Health check endpoint.
Generate a chart from structured data.
Request: ChartRequest (see models)
Response: ChartResponse with file path
Generate a chart and get AI insights.
Response: Chart response + AI analysis
{
"chart_type": str, # Required: bar, line, pie, scatter, area, histogram
"title": str, # Required: Chart title
"data": List[ChartDataPoint], # Optional: Single-series data
"series": List[ChartDataSeries], # Optional: Multi-series data
"x_label": str, # Optional: X-axis label
"y_label": str, # Optional: Y-axis label
"width": int, # Optional: Width in inches (default: 10)
"height": int, # Optional: Height in inches (default: 6)
"show_legend": bool, # Optional: Show legend (default: true)
"show_grid": bool # Optional: Show grid (default: true)
}{
"success": bool, # Whether generation succeeded
"chart_path": str, # File path to generated chart
"error": str, # Error message if failed
"metadata": { # Additional information
"chart_type": str,
"data_points": int,
"file_size_bytes": int,
"dimensions": str,
"format": str
}
}# Start servers first (in separate terminals)
python -m ChartAgent
python -m chart_mcp
# Run integration tests
python test_integration.py- Add enum to
models.py:
class ChartType(str, Enum):
NEW_TYPE = "new_type"- Implement generator in
visualizer.py:
def generate_new_type_chart(self, request: ChartRequest) -> str:
# Implementation
pass- Register in
generate_chart()method:
chart_generators = {
ChartType.NEW_TYPE: self.generate_new_type_chart,
}- Ensure the MCP server is fully started
- Check logs for initialization errors
- Verify Chart Agent is running on port 8001
- Check
CHART_AGENT_URLin configuration
- Check
CHART_OUTPUT_DIRexists and is writable - Verify Matplotlib is installed correctly
- Review logs in
chart_agent.log
- Ensure
OPEN_ROUTER_API_KEYis set in.env - Verify API key is valid and has credits
This project is for educational and development purposes.
- FastMCP: MCP server framework
- Pydantic AI: AI agent framework
- FastAPI: Web framework
- Matplotlib: Visualization library