render_chart
Render Chart.js configuration as a chart image. Generate bar, line, pie, scatter charts from JSON data. Returns base64-encoded PNG or JPEG image for reports or documentation.
Instructions
Render a Chart.js configuration as a chart image.
Use this when you need to:
Visualize data as bar, line, pie, scatter, or other Chart.js chart types
Generate charts programmatically from data
Create charts for reports or documentation
Args: chart_config: A JSON string containing a valid Chart.js configuration object. Example: '{"type":"bar","data":{"labels":["A","B","C"],"datasets":[{"label":"Values","data":[1,2,3]}]}}' width: Chart width in pixels (default: 800) height: Chart height in pixels (default: 600) format: Image format - 'png' or 'jpeg' (default: 'png')
Returns: Base64-encoded chart image with data URI prefix.
Rate limits: Shared with screenshot API. Get a free API key at https://hermesforge.dev/api/keys
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chart_config | Yes | ||
| width | No | ||
| height | No | ||
| format | No | png |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- hermesforge_mcp/server.py:117-184 (handler)Main handler function for the render_chart tool. Accepts a Chart.js JSON config, width, height, and format, then posts to the Hermesforge chart rendering API and returns a base64-encoded image.
@mcp.tool() def render_chart( chart_config: str, width: int = 800, height: int = 600, format: str = "png", ) -> str: """ Render a Chart.js configuration as a chart image. Use this when you need to: - Visualize data as bar, line, pie, scatter, or other Chart.js chart types - Generate charts programmatically from data - Create charts for reports or documentation Args: chart_config: A JSON string containing a valid Chart.js configuration object. Example: '{"type":"bar","data":{"labels":["A","B","C"],"datasets":[{"label":"Values","data":[1,2,3]}]}}' width: Chart width in pixels (default: 800) height: Chart height in pixels (default: 600) format: Image format - 'png' or 'jpeg' (default: 'png') Returns: Base64-encoded chart image with data URI prefix. Rate limits: Shared with screenshot API. Get a free API key at https://hermesforge.dev/api/keys """ import json # Validate JSON try: config = json.loads(chart_config) except json.JSONDecodeError as e: return f"Error: chart_config is not valid JSON: {e}" payload = { "config": config, "width": width, "height": height, "format": format, } try: resp = requests.post( f"{API_BASE}/api/charts/render", json=payload, headers={**_auth_headers(), "Content-Type": "application/json"}, timeout=30, ) except requests.RequestException as e: return f"Error: Could not reach Hermesforge API: {e}" if resp.status_code == 200: img_bytes = resp.content b64 = base64.b64encode(img_bytes).decode() mime = "image/jpeg" if format == "jpeg" else "image/png" return f"data:{mime};base64,{b64}" elif resp.status_code == 429: try: msg = resp.json().get("message", "") except Exception: msg = "" return ( f"Rate limit reached. {msg} " f"Get a free API key at https://hermesforge.dev/api/keys" ) else: return f"Error: API returned {resp.status_code}: {resp.text[:200]}" - hermesforge_mcp/server.py:118-123 (schema)Type signature/input schema for render_chart. chart_config (str, required), width (int, default 800), height (int, default 600), format (str, default 'png'). Returns str.
def render_chart( chart_config: str, width: int = 800, height: int = 600, format: str = "png", ) -> str: - hermesforge_mcp/server.py:117-117 (registration)Registration decorator registering render_chart as an MCP tool via the FastMCP instance.
@mcp.tool()