Vega Lite MCP Server for VegaLite Data Visualizations
Generate interactive VegaLite visualizations from fetched data using the MCP server VegaLite renderer.
npx -y @isaacwasserman/mcp-vegalite-serverOverview
This MCP (Model Context Protocol) server provides an easy way to generate interactive Vega-Lite visualizations from data fetched by an LLM or agent. It exposes a small HTTP service that acts as an MCP “renderer” tool: you send a Vega-Lite specification (or a spec plus a data URL/payload) and the server returns an embeddable visualization (HTML fragment or exported image) suitable for insertion into conversational context, notebooks, or dashboards.
The server is useful when you want LLM-driven workflows to produce visual output: the agent fetches data, constructs (or asks the server to construct) a Vega-Lite spec, and then calls the renderer to get a ready-to-display visualization. This separates visualization rendering from the model logic, provides reproducible outputs, and produces interactive charts without requiring the model to host the rendering stack itself.
Features
- Render Vega-Lite specs into embeddable HTML fragments (vega-embed) for immediate display
- Accept data directly or via a remote data URL (server fetches data)
- Optional server-side export to PNG/SVG (configurable; depends on headless Chromium)
- Small HTTP API designed to be used as an MCP tool by agents and LLMs
- CORS-friendly endpoints for embedding in web UIs
- Lightweight configuration (port, export toggles, allowed hosts) via environment variables
Installation / Configuration
Clone the repository and install dependencies. The example below assumes an npm/Node.js implementation; substitute your package manager if needed.
# clone
# install
# start (development)
# or production
Environment variables (example .env):
PORT=8080
ALLOW_ORIGINS=*ENABLE_PNG_EXPORT=falseMAX_PAYLOAD_SIZE=1mb
If you want server-side PNG/SVG export, install and configure a headless Chromium runtime (Puppeteer). Set ENABLE_PNG_EXPORT=true and ensure the runtime is available to the server process.
Available Tools / Endpoints
The server exposes a small set of HTTP endpoints designed to integrate with MCP-aware agents:
- GET /health
- Returns 200 OK if the service is running.
- POST /render
- Renders a visualization. Accepts JSON body:
- spec: object (Vega-Lite spec)
- data: optional array or object (inline data)
- data_url: optional string (server will fetch CSV/JSON)
- output: “html” (default) or “png” | “svg”
- Returns: HTML fragment or binary image depending on output.
- Renders a visualization. Accepts JSON body:
- POST /tool-meta
- Returns a JSON description of the MCP tool (name, input schema, description) that agents can register.
Example /render request:
Response: text/html body containing an embeddable div + script that calls vegaEmbed with the provided spec.
MCP Tool Schema Example
If you register the renderer as an MCP tool, provide a schema so agents can call it programmatically. Example tool metadata (JSON):
Use Cases
- Notebook visualization: Agent fetches a dataset, constructs a Vega-Lite spec, calls the renderer, and inserts the returned HTML fragment into a notebook cell for immediate interactive exploration.
- Reporting pipelines: Automated reports generated by an LLM include charts. The report generator posts specs to the renderer and embeds returned PNGs/SVGs into PDFs or HTML reports.
- Conversational data exploration: An assistant queries a dataset on behalf of a user, then returns a chart that the user can interact with (hover, zoom) via the embedded Vega runtime.
- Validation and preview: During spec generation, an agent can ask the renderer for a quick preview before finalizing a visualization spec.
Examples
Embed returned HTML fragment in a web page:
<!-- server returned this fragment -->
Request a PNG export (if enabled on server):