loading…
Search for a command to run...
loading…
Enables AI agents to generate safe, runnable HTML chart pages from structured JSON data using Apache ECharts. It provides tools for chart type recommendation, p
Enables AI agents to generate safe, runnable HTML chart pages from structured JSON data using Apache ECharts. It provides tools for chart type recommendation, page generation, validation, and patching with controlled, deterministic output.
echarts-chartpage is a TypeScript toolkit that turns structured JSON data, visualization goals, and field mappings into safe, runnable HTML chart pages powered by Apache ECharts.
It ships as:
The project is designed for deterministic output, controlled option generation, strong validation, and public open-source maintainability.
echarts npm package in source code for types and integration correctnessgoal, theme, and field mapping inputtrendcomparecompositiondistributionrankingcorrelationlinebarstacked_barpiedonutscatterareatablenpm install echarts-chartpage
For local development:
npm install
npx echarts-chartpage generate \
--input examples/inputs/line-chart.json \
--output revenue-trend.html
import { generateChartPage } from "echarts-chartpage";
const result = generateChartPage({
title: "Monthly Revenue Trend",
goal: "trend",
theme: "light",
outputMode: "single_html",
data: [
{ month: "2025-01", revenue: 120 },
{ month: "2025-02", revenue: 132 },
{ month: "2025-03", revenue: 148 }
],
fields: {
x: "month",
y: "revenue"
}
});
console.log(result.chartType);
console.log(result.html);
Build first, then start the stdio server:
npm run build
npm run mcp:start
type GenerateChartPageInput = {
title: string;
description?: string;
goal: "trend" | "compare" | "composition" | "distribution" | "ranking" | "correlation";
data: Array<Record<string, string | number | boolean | null>>;
fields: {
x: string;
y: string | string[];
series?: string;
category?: string;
};
theme?: "light" | "dark";
outputMode?: "single_html";
chartType?: "line" | "bar" | "stacked_bar" | "pie" | "donut" | "scatter" | "area" | "table";
};
generateChartPage() returns:
null for table fallbackThe CLI binary name is echarts-chartpage.
generateGenerate a single HTML page from JSON input:
echarts-chartpage generate \
--input examples/inputs/line-chart.json \
--output examples/generated/line-chart.html
recommendRecommend a chart type:
echarts-chartpage recommend \
--input examples/inputs/bar-chart.json
validateValidate input and optionally validate generated HTML:
echarts-chartpage validate \
--input examples/inputs/pie-chart.json \
--html examples/generated/pie-chart.html
patchPatch a base chart spec and regenerate HTML:
echarts-chartpage patch \
--base examples/inputs/patch-base.json \
--patch examples/inputs/patch-update.json \
--output examples/generated/patch-example.html
The server exposes these tools:
recommend_chart_typegenerate_chart_pagevalidate_chart_pagepatch_chart_pageAll tool inputs and outputs are structured JSON. A typical MCP client configuration points to the built stdio server:
{
"mcpServers": {
"echarts-chartpage": {
"command": "node",
"args": ["dist/mcp/server.js"]
}
}
}
See examples/mcp-usage.md for request payload samples.
Public API surface:
generateChartPagerecommendChartTypevalidateChartInputvalidateChartPageRequestvalidateGeneratedHtmlpatchChartPagebuildChartOptionbuildChartHtmlRuntime schemas are exported as well:
generateChartPageInputSchemapatchChartPageChangesSchemapatchChartPageInputSchemavalidateChartPageInputSchemaInput:
{
"title": "Traffic Source Mix",
"goal": "composition",
"theme": "light",
"outputMode": "single_html",
"data": [
{ "source": "Organic", "sessions": 4200 },
{ "source": "Paid", "sessions": 2100 },
{ "source": "Referral", "sessions": 1100 }
],
"fields": {
"x": "source",
"y": "sessions",
"category": "source"
}
}
Output summary:
{
"chartType": "donut",
"warnings": [],
"html": "<!doctype html>..."
}
The repository includes:
Generate all example HTML files with:
npm run examples:generate
Generated HTML files are written to examples/generated/.
This repository also includes a reusable Codex-style skill for agents that need to call the MCP server consistently:
It documents:
Install the bundled skill into the local Codex skill directory with:
npm run build
npm run skill:install
Project layout:
src/
core/
chart-recommender.ts
option-builder.ts
html-builder.ts
validator.ts
patcher.ts
generator.ts
cli/
index.ts
commands/
mcp/
server.ts
schemas/
types/
utils/
Design rules:
See also:
npm install
npm run lint
npm run typecheck
npm run test
npm run build
npm run examples:generate
npm run build
Outputs are emitted to dist/.
npm run test
Before publishing:
package.json.daqiang901003 is authenticated on the publishing machine.CHANGELOG.md.npm run verify.npm publish.The package is configured with:
exports.d.tsbinfilesNo. The generator does not accept arbitrary formatter functions, script fragments, or custom JS injection.
table?The builder uses a conservative whitelist. If mappings or data types are incompatible with a controlled chart output, it falls back to a stable table rendering.
No. It is a single HTML file intended to open directly in the browser.
Yes. Set chartType in the input. If the requested chart is incompatible with the data mapping, validation warnings are returned and generation can fall back to table.
This project is intended for trusted structured data pipelines. If you accept untrusted input from external users, validate and sanitize it at your own boundary as well.
For the full repository policy, see SECURITY.md.
This project uses ECharts in two places:
echarts npm package for typed option generationSee CONTRIBUTING.md.
MIT. See LICENSE.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"echarts-chartpage-mcp-server": {
"command": "npx",
"args": []
}
}
}