visualize_data
Transform complex datasets into clear, interpretable visuals using the Vega-Lite grammar. Use this tool to visualize multi-dimensional data from saved tables, enhancing understanding and analysis.
Instructions
A tool which allows you to produce a data visualization using the Vega-Lite grammar. When to use this tool:
At times, it will be advantageous to provide the user with a visual representation of some data, rather than just a textual representation.
This tool is particularly useful when the data is complex or has many dimensions, making it difficult to understand in a tabular format. It is not useful for singular data points. How to use this tool:
Prior to visualization, data must be saved to a named table using the save_data tool.
After saving the data, use this tool to visualize the data by providing the name of the table with the saved data and a Vega-Lite specification.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data_name | Yes | The name of the data table to visualize | |
| vegalite_specification | Yes | The vegalite v5 specification for the visualization. Do not include the data field, as this will be added automatically. |
Implementation Reference
- The core handler logic for the 'visualize_data' tool. Retrieves data by name from saved_data, injects it into the Vega-Lite spec, renders to PNG if output_type is 'png', otherwise returns text content with artifact.elif name == "visualize_data": data_name = arguments["data_name"] vegalite_specification = eval(arguments["vegalite_specification"]) data = saved_data[data_name] vegalite_specification["data"] = {"values": data} if output_type == "png": png = vlc.vegalite_to_png(vl_spec=vegalite_specification, scale=2) png = base64.b64encode(png).decode("utf-8") return [types.ImageContent(type="image", data=png, mimeType="image/png")] else: return [ types.TextContent( type="text", text=f"Visualized data from table {data_name} with provided spec.", artifact=vegalite_specification, ) ]
- src/mcp_server_vegalite/server.py:99-116 (registration)Tool registration in the list_tools() handler, defining the tool's name, description reference, and input schema.types.Tool( name="visualize_data", description=VISUALIZE_DATA_TOOL_DESCRIPTION, inputSchema={ "type": "object", "properties": { "data_name": { "type": "string", "description": "The name of the data table to visualize", }, "vegalite_specification": { "type": "string", "description": "The vegalite v5 specification for the visualization. Do not include the data field, as this will be added automatically.", }, }, "required": ["data_name", "vegalite_specification"], }, ),
- Pydantic-like input schema for the visualize_data tool, specifying required parameters: data_name (string) and vegalite_specification (string).inputSchema={ "type": "object", "properties": { "data_name": { "type": "string", "description": "The name of the data table to visualize", }, "vegalite_specification": { "type": "string", "description": "The vegalite v5 specification for the visualization. Do not include the data field, as this will be added automatically.", }, }, "required": ["data_name", "vegalite_specification"], },