Skip to content

ChiragKr04/graph-plot-mcp

Repository files navigation

Chart Plotting MCP

A Model Context Protocol (MCP) server that provides tools for generating and saving various types of charts and graphs.

Features

  • 📊 Bar Graphs: Generate customizable bar graphs with titles, labels, and colors
  • 📈 Line Graphs: Create line graphs with markers and customizable styling
  • 🥧 Pie Charts: Visualize proportional data with pie charts

All charts are automatically saved to the /images directory with timestamped filenames and can be directly used in your applications.

Installation

This MCP requires Python 3.10+ and uses uv for dependency management.

# Clone the repository
git clone <your-repository-url>
cd new-mcp

# Install dependencies
uv install -e .
uv install mcp[cli] matplotlib

Configuration

VS Code / GitHub Copilot / Cursor

Add this to your settings.json in VS Code:

"mcp": {
  "servers": {
    "Chart-Plotting": {
      "command": "/path/to/your/python/uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "/path/to/your/new-mcp/main.py"
      ]
    }
  }
}

Claude

Add this to your Claude configuration:

{
  "mcpServers": {
    "Chart-Plotting": {
      "command": "/path/to/your/python/uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "--with",
        "matplotlib",
        "mcp",
        "run",
        "/path/to/your/new-mcp/main.py"
      ]
    }
  }
}

Replace /path/to/your/python/uv and /path/to/your/new-mcp/main.py with your actual paths.

Usage

Once configured, you can use the MCP tools in your AI assistant:

Bar Graph

plot_bar_graph_and_save_image(
  categories=["Category A", "Category B", "Category C"],
  values=[42, 55, 30],
  title="Sales Report",
  xlabel="Product Categories",
  ylabel="Units Sold",
  color="skyblue"
)

For bar graphs with image path return:

plot_bar_graph_and_save_image_return_imagepath(
  categories=["Category A", "Category B", "Category C"],
  values=[42, 55, 30],
  title="Sales Report",
  xlabel="Product Categories",
  ylabel="Units Sold",
  color="skyblue"
)

Line Graph

plot_line_graph_and_save_image(
  x_values=[1, 2, 3, 4, 5],
  y_values=[12, 18, 11, 23, 19],
  title="Temperature Trend",
  xlabel="Days",
  ylabel="Temperature (°C)",
  color="red"
)

Pie Chart

plot_pie_chart_and_save_image(
  values=[35, 25, 20, 20],
  labels=["Product A", "Product B", "Product C", "Product D"],
  title="Market Share",
  colors=["#ff9999", "#66b3ff", "#99ff99", "#ffcc99"]
)

Example Use Cases

  • Generate sales and revenue visualizations
  • Create data comparison charts for reports
  • Visualize survey results with pie charts
  • Plot time-series data with line graphs
  • Create performance benchmarks with bar charts

Prompt Example

When interacting with an AI assistant that has this MCP configured, you can use normal language to request charts. For example:

User Request:

This is my data, plot a bar graph for me:
- Products: Laptops, Phones, Tablets, Accessories
- Sales: 45000, 62000, 28000, 15000

AI Assistant Response:

I'll create a bar graph with your sales data:

plot_bar_graph_and_save_image_return_imagepath(
  categories=["Laptops", "Phones", "Tablets", "Accessories"],
  values=[45000, 62000, 28000, 15000],
  title="Product Sales Comparison",
  xlabel="Products",
  ylabel="Sales ($)",
  color="skyblue"
)

Here's your sales data visualization showing that phones have the highest sales at $62,000, followed by laptops at $45,000, tablets at $28,000, and accessories at $15,000.

Claude Desktop in Action

Below is an example of Claude Desktop using the Chart Plotting MCP to generate all three types of charts based on user data:

User Request

User Prompt

The user provided data for BMW and Audi and requested all three types of charts:

"categories": [
  "BMW",
  "Audi"
],
"values": [
  20,
  30
],

plot all 3 types of graph bar, pie and line

Claude's Response

Claude Response

Claude automatically recognized the data format and used all three Chart Plotting MCP tools:

Bar Graph

Shows the comparison between BMW (20) and Audi (30):

Bar Graph

Pie Chart

Displays the proportion between BMW and Audi:

Pie Chart

Line Graph

Represents the brands as sequential points to show the increasing trend:

Line Graph

The MCP automatically saved all three charts to the /images directory with unique timestamps.

Notes

  • All images are saved with timestamps to prevent overwriting
  • Images are saved in the /images directory
  • You can customize colors, labels, titles, and other options
  • Bar graph function with _return_imagepath suffix returns the path to the saved image

Requirements

  • Python 3.10+
  • matplotlib
  • mcp[cli]

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages