ECharts ChartPage MCP Server
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.
README
ECharts ChartPage
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:
- an npm package for programmatic use
- a CLI for local automation
- an MCP server for agent workflows
The project is designed for deterministic output, controlled option generation, strong validation, and public open-source maintainability.
Features
- Generate complete single-file HTML chart pages with Apache ECharts CDN included
- Depend on the official
echartsnpm package in source code for types and integration correctness - Accept structured data plus
goal,theme, and field mapping input - Recommend safe chart types from a controlled whitelist
- Build controlled ECharts options without arbitrary JS formatter injection
- Validate schema, field mappings, chart compatibility, and generated HTML basics
- Patch existing chart specs and regenerate output
- Reuse one shared core across npm API, CLI, and MCP server
- Ship with tests, CI, examples, contribution docs, and release-ready packaging
Supported Goals
trendcomparecompositiondistributionrankingcorrelation
Supported Chart Types
linebarstacked_barpiedonutscatterareatable
Installation
npm install echarts-chartpage
For local development:
npm install
Quick Start
CLI
npx echarts-chartpage generate \
--input examples/inputs/line-chart.json \
--output revenue-trend.html
npm API
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);
MCP Server
Build first, then start the stdio server:
npm run build
npm run mcp:start
Input Model
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";
};
Output
generateChartPage() returns:
- normalized spec
- resolved chart type
- warnings
- controlled ECharts option or
nullfor table fallback - complete runnable HTML
CLI Usage
The CLI binary name is echarts-chartpage.
generate
Generate a single HTML page from JSON input:
echarts-chartpage generate \
--input examples/inputs/line-chart.json \
--output examples/generated/line-chart.html
recommend
Recommend a chart type:
echarts-chartpage recommend \
--input examples/inputs/bar-chart.json
validate
Validate input and optionally validate generated HTML:
echarts-chartpage validate \
--input examples/inputs/pie-chart.json \
--html examples/generated/pie-chart.html
patch
Patch 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
MCP Usage
The server exposes these tools:
recommend_chart_typegenerate_chart_pagevalidate_chart_pagepatch_chart_page
All 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.
Programming API
Public API surface:
generateChartPagerecommendChartTypevalidateChartInputvalidateChartPageRequestvalidateGeneratedHtmlpatchChartPagebuildChartOptionbuildChartHtml
Runtime schemas are exported as well:
generateChartPageInputSchemapatchChartPageChangesSchemapatchChartPageInputSchemavalidateChartPageInputSchema
Input / Output Example
Input:
{
"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>..."
}
Examples
The repository includes:
- examples/inputs/line-chart.json
- examples/inputs/bar-chart.json
- examples/inputs/pie-chart.json
- examples/inputs/multi-series.json
- examples/inputs/patch-base.json
- examples/inputs/patch-update.json
- examples/cli-usage.md
- examples/mcp-usage.md
Generate all example HTML files with:
npm run examples:generate
Generated HTML files are written to examples/generated/.
Agent Skill
This repository also includes a reusable Codex-style skill for agents that need to call the MCP server consistently:
It documents:
- when to trigger this MCP
- how to choose among recommend / validate / generate / patch
- structured calling rules
- few-shot examples for model prompting
Install the bundled skill into the local Codex skill directory with:
npm run build
npm run skill:install
Architecture
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:
- core logic is shared across all interfaces
- output is controlled and deterministic
- no arbitrary formatter functions are accepted
- only whitelisted chart types are emitted
- dataset + encode is preferred where practical
See also:
Development Commands
npm install
npm run lint
npm run typecheck
npm run test
npm run build
npm run examples:generate
Build Command
npm run build
Outputs are emitted to dist/.
Test Command
npm run test
Publish Notes
Before publishing:
- Update repository URLs in
package.json. - Ensure the npm account
daqiang901003is authenticated on the publishing machine. - Review the
CHANGELOG.md. - Run
npm run verify. - Publish with
npm publish.
The package is configured with:
exports- generated
.d.ts binfiles- ESM-first output with CommonJS compatibility
Roadmap
- richer ranking-specific sorting controls
- dashboard-oriented multi-panel HTML templates
- more chart recommendation heuristics
- configurable design presets
- richer MCP metadata and traces
FAQ
Does this execute arbitrary user JavaScript?
No. The generator does not accept arbitrary formatter functions, script fragments, or custom JS injection.
Why does some input fall back to 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.
Does the generated HTML need a build step?
No. It is a single HTML file intended to open directly in the browser.
Can I force a chart type?
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.
Security
- no arbitrary script injection
- no arbitrary external JS injection beyond the fixed ECharts CDN
- no formatter function injection
- controlled HTML template shape
- schema validation before generation
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.
ECharts Integration Note
This project uses ECharts in two places:
- source code depends on the official
echartsnpm package for typed option generation - generated HTML uses the fixed Apache ECharts CDN runtime so the output file can open directly in a browser without a bundler
Contributing
See CONTRIBUTING.md.
License
MIT. See LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。