Skip to main content

MCP server for data visualization with Mermaid-first approach for Cursor and other MCP clients

Project description

Plots MCP Server

A lightweight Model Context Protocol (MCP) server for data visualization. It exposes tools to render charts (line, bar, pie, scatter, heatmap, etc.) from tabular data and returns MCP-compatible image/text content.

๐Ÿš€ Quick Start

๐Ÿ“ฆ PyPI Installation (Recommended)

pip install mcp-plots
mcp-plots  # Start the server

๐ŸŽฏ For Cursor Users

  1. Install the package: pip install mcp-plots
  2. Add to your Cursor MCP config (~/.cursor/mcp.json):
    {
      "mcpServers": {
        "plots": {
          "command": "mcp-plots",
          "args": ["--transport", "stdio"]
        }
      }
    }
    
  3. Restart Cursor
  4. Ask: "Create a bar chart showing sales: A=100, B=150, C=80"

๐Ÿ› ๏ธ Development Installation

uvx --from git+https://github.com/mr901/mcp-plots.git run-server.py

๐Ÿ“– Documentation โ†’ | Quick Start โ†’ | API Reference โ†’

Project layout

src/
  app/                # Server construction and runtime
    server.py
  capabilities/       # MCP tools and prompts
    tools.py
    prompts.py
  visualization/      # Plotting engines and configurations
    chart_config.py
    generator.py

Requirements

  • Python 3.10+
  • See requirements.txt

Installation & Usage

๐Ÿš€ Quick Start with uvx (Recommended)

The easiest way to run the MCP server without managing Python environments:

# Run directly with uvx (no installation needed)
uvx --from git+https://github.com/mr901/mcp-plots.git run-server.py

# Or install and run the command
uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots

# With custom options
uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots --port 8080 --log-level DEBUG

Why uvx?

  • โœ… No Environment Management: Automatically handles Python dependencies
  • โœ… Isolated Execution: Runs in its own virtual environment
  • โœ… Always Latest: Pulls fresh code from repository
  • โœ… Zero Setup: Works immediately without pip install
  • โœ… Cross-Platform: Same command works on Windows, macOS, Linux

๐Ÿ“ฆ Traditional Installation

  1. Install dependencies
pip install -r requirements.txt
  1. Run the server (HTTP transport, default port 8000)
python -m src --transport streamable-http --host 0.0.0.0 --port 8000 --log-level INFO
  1. Run with stdio (for MCP clients that spawn processes)
python -m src --transport stdio

๐Ÿณ Docker

docker build -t mcp-plots .
docker run -p 8000:8000 mcp-plots

Environment variables (optional):

  • MCP_TRANSPORT (streamable-http|stdio)
  • MCP_HOST (default 0.0.0.0)
  • MCP_PORT (default 8000)
  • LOG_LEVEL (default INFO)

Tools

  • list_chart_types() โ†’ returns available chart types
  • list_themes() โ†’ returns available themes
  • suggest_fields(sample_rows) โ†’ suggests field roles based on data samples
  • render_chart(chart_type, data, field_map, config_overrides?, options?, output_format?) โ†’ returns MCP content
  • generate_test_image() โ†’ generates a test image (red circle) to verify MCP image support

๐ŸŽฏ Cursor Integration

This MCP server is fully compatible with Cursor's image support! When you use the render_chart tool:

  • Charts appear directly in chat - No need to save files or open separate windows
  • AI can analyze your charts - Vision-enabled models can discuss and interpret your visualizations
  • Perfect MCP format - Uses the exact base64 PNG format that Cursor expects

The server returns images in the MCP format Cursor requires:

{
  "content": [
    {
      "type": "image", 
      "data": "<base64-encoded-png>",
      "mimeType": "image/png"
    }
  ]
}

Example call (pseudo):

render_chart(
  chart_type="bar",
  data=[{"category":"A","value":10},{"category":"B","value":20}],
  field_map={"category_field":"category","value_field":"value"},
  config_overrides={"title":"Example Bar","width":800,"height":600,"output_format":"MCP_IMAGE"}
)

Return shape (PNG):

{
  "status": "success",
  "content": [{"type":"image","data":"<base64>","mimeType":"image/png"}]
}

Configuration

The server can be configured via environment variables or command line arguments:

Server Settings

  • MCP_TRANSPORT - Transport type: streamable-http or stdio (default: streamable-http)
  • MCP_HOST - Host address (default: 0.0.0.0)
  • MCP_PORT - Port number (default: 8000)
  • LOG_LEVEL - Logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO)
  • MCP_DEBUG - Enable debug mode: true or false (default: false)

Chart Settings

  • CHART_DEFAULT_WIDTH - Default chart width in pixels (default: 800)
  • CHART_DEFAULT_HEIGHT - Default chart height in pixels (default: 600)
  • CHART_DEFAULT_DPI - Default chart DPI (default: 100)
  • CHART_MAX_DATA_POINTS - Maximum data points per chart (default: 10000)

Command Line Usage

With uvx (recommended):

uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots --help

# Examples:
uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots --port 8080 --log-level DEBUG
uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots --chart-width 1200 --chart-height 800

Traditional Python:

python -m src --help

# Examples:
python -m src --transport streamable-http --host 0.0.0.0 --port 8000
python -m src --log-level DEBUG --chart-width 1200 --chart-height 800

Docker

Build image:

docker build -t mcp-plots .

Run container with custom configuration:

docker run --rm -p 8000:8000 \
  -e MCP_TRANSPORT=streamable-http \
  -e MCP_HOST=0.0.0.0 \
  -e MCP_PORT=8000 \
  -e LOG_LEVEL=INFO \
  -e CHART_DEFAULT_WIDTH=1000 \
  -e CHART_DEFAULT_HEIGHT=700 \
  -e CHART_DEFAULT_DPI=150 \
  -e CHART_MAX_DATA_POINTS=5000 \
  mcp-plots

๐ŸŽฏ Cursor MCP Integration

Quick Setup for Cursor

The Plots MCP Server is designed to work seamlessly with Cursor's MCP support. Here's how to integrate it:

1. Add to Cursor's MCP Configuration

Add this to your Cursor MCP configuration file (~/.cursor/mcp.json or similar):

{
  "mcpServers": {
    "plots": {
      "command": "uvx",
      "args": [
        "--from", 
        "git+https://github.com/mr901/mcp-plots.git@main",
        "mcp-plots",
        "--transport", 
        "stdio"
      ],
      "env": {
        "LOG_LEVEL": "INFO",
        "CHART_DEFAULT_WIDTH": "800",
        "CHART_DEFAULT_HEIGHT": "600"
      }
    }
  }
}

2. Alternative: HTTP Transport

For HTTP-based integration:

{
  "mcpServers": {
    "plots-http": {
      "command": "uvx",
      "args": [
        "--from", 
        "git+https://github.com/mr901/mcp-plots.git@main", 
        "mcp-plots",
        "--transport", 
        "streamable-http",
        "--host", 
        "127.0.0.1",
        "--port", 
        "8000"
      ]
    }
  }
}

3. Local Development Setup

For local development (if you have the code cloned):

{
  "mcpServers": {
    "plots-dev": {
      "command": "python",
      "args": ["-m", "src", "--transport", "stdio"],
      "cwd": "/path/to/mcp-plots",
      "env": {
        "LOG_LEVEL": "DEBUG"
      }
    }
  }
}

4. Verify Integration

After adding the configuration:

  1. Restart Cursor
  2. Check MCP connection in Cursor's MCP panel
  3. Test with a simple chart:
    Create a bar chart showing sales data: A=100, B=150, C=80
    

๐ŸŽจ MERMAID-First Approach

This server prioritizes MERMAID output by default because:

  • โœ… Renders instantly in Cursor - No external viewers needed
  • โœ… Interactive - Cursor can analyze and discuss the diagrams
  • โœ… Lightweight - Fast generation and display
  • โœ… Scalable - Vector-based, works at any zoom level

Chart Types with Native MERMAID Support:

  • line, bar, pie, area โ†’ xychart-beta format
  • histogram โ†’ xychart-beta with automatic binning
  • funnel โ†’ Styled flowchart with color gradients
  • gauge โ†’ Flowchart with color-coded value indicators
  • sankey โ†’ Flow diagrams with source/target styling

๐Ÿ“Š Available Tools

render_chart

Main chart generation tool with MERMAID-first approach.

Parameters:

  • chart_type - Chart type (line, bar, pie, scatter, heatmap, etc.)
  • data - List of data objects
  • field_map - Field mappings (x_field, y_field, category_field, etc.)
  • config_overrides - Chart configuration overrides
  • output_format - Output format (mermaid [default], mcp_image, mcp_text)

Special Modes:

  • chart_type="help" - Show available chart types and themes
  • chart_type="suggest" - Analyze data and suggest field mappings

configure_preferences

Interactive configuration tool for setting user preferences.

Parameters:

  • output_format - Default output format (mermaid, mcp_image, mcp_text)
  • theme - Default theme (default, dark, seaborn, minimal)
  • chart_width - Default chart width in pixels
  • chart_height - Default chart height in pixels
  • reset_to_defaults - Reset all preferences to system defaults

Features:

  • โœ… Persistent Settings - Saved to ~/.plots_mcp_config.json
  • โœ… Live Preview - Shows sample chart with current settings
  • โœ… Override Support - Use config_overrides for one-off changes

๐Ÿ“š Documentation

Additional Resources

Chart Examples

Basic Bar Chart:

{
  "chart_type": "bar",
  "data": [
    {"category": "Sales", "value": 120},
    {"category": "Marketing", "value": 80},
    {"category": "Support", "value": 60}
  ],
  "field_map": {
    "category_field": "category", 
    "value_field": "value"
  }
}

Time Series Line Chart:

{
  "chart_type": "line",
  "data": [
    {"date": "2024-01", "revenue": 1000},
    {"date": "2024-02", "revenue": 1200},
    {"date": "2024-03", "revenue": 1100}
  ],
  "field_map": {
    "x_field": "date",
    "y_field": "revenue"
  }
}

Funnel Chart:

{
  "chart_type": "funnel",
  "data": [
    {"stage": "Awareness", "value": 1000},
    {"stage": "Interest", "value": 500}, 
    {"stage": "Purchase", "value": 100}
  ],
  "field_map": {
    "category_field": "stage",
    "value_field": "value"
  }
}

๐Ÿ”ง Configuration

Environment Variables

  • MCP_TRANSPORT - Transport type (streamable-http | stdio)
  • MCP_HOST - Host address (default: 0.0.0.0)
  • MCP_PORT - Port number (default: 8000)
  • LOG_LEVEL - Logging level (default: INFO)
  • MCP_DEBUG - Enable debug mode (true | false)
  • CHART_DEFAULT_WIDTH - Default chart width in pixels (default: 800)
  • CHART_DEFAULT_HEIGHT - Default chart height in pixels (default: 600)
  • CHART_DEFAULT_DPI - Default chart DPI (default: 100)
  • CHART_MAX_DATA_POINTS - Maximum data points per chart (default: 10000)

User Preferences

Personal preferences are stored in ~/.plots_mcp_config.json:

{
  "defaults": {
    "output_format": "mermaid",
    "theme": "default",
    "chart_width": 800,
    "chart_height": 600
  },
  "user_preferences": {
    "output_format": "mcp_image",
    "theme": "dark"
  }
}

๐Ÿš€ Advanced Usage

Custom Themes

Available themes: default, dark, seaborn, minimal, whitegrid, darkgrid, ticks

High-Resolution Charts

uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots \
  --chart-width 1920 \
  --chart-height 1080 \
  --chart-dpi 300

Performance Optimization

  • Use max_data_points to limit large datasets
  • MERMAID output is fastest for quick visualization
  • PNG output for high-quality static images
  • SVG output for scalable vector graphics

๐Ÿ› Troubleshooting

Common Issues

Issue: Charts not rendering in Cursor

  • Solution: Ensure output_format="mermaid" (default)
  • Check: MCP server connection in Cursor

Issue: uvx command not found

  • Solution: Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh

Issue: Port already in use

  • Solution: Use different port: --port 8001

Issue: Large datasets slow

  • Solution: Sample data or increase --max-data-points

Debug Mode

uvx --from git+https://github.com/mr901/mcp-plots.git mcp-plots \
  --debug \
  --log-level DEBUG

๐Ÿ“ Notes

  • Matplotlib runs headless (Agg backend) in the container
  • For large datasets, sample your data for responsiveness
  • Chart defaults can be overridden per-request via config_overrides
  • MERMAID charts render instantly in Cursor for the best user experience
  • User preferences persist across sessions and apply to all charts by default

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_plots-0.0.0.tar.gz (68.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_plots-0.0.0-py3-none-any.whl (62.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_plots-0.0.0.tar.gz.

File metadata

  • Download URL: mcp_plots-0.0.0.tar.gz
  • Upload date:
  • Size: 68.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for mcp_plots-0.0.0.tar.gz
Algorithm Hash digest
SHA256 0b4755f210de66cb4eb82ca8ef2fb7a8335f6a21c0406ecfe16d53799d671bb6
MD5 94b432dbb26e74476e2d57b00cc4ce83
BLAKE2b-256 10fc31467465deda91aba47b3e9d6fffabdd3895c6d930bf220afd3984167903

See more details on using hashes here.

File details

Details for the file mcp_plots-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_plots-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 62.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for mcp_plots-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a293f2e4fb29c992478b0ad4d9a08a31eab0cbe4590cceb2db2331e961a8fd8c
MD5 23d4f0b8b2a29c5e065f898f7e7bc8c3
BLAKE2b-256 bf1482e3aa6e230c8c9a7acbddcf8f1588827eb71ce1f2d1acff040ef9ee9987

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page