Skip to content

Commit a44a880

Browse files
committed
feat: init
0 parents  commit a44a880

File tree

20 files changed

+617
-0
lines changed

20 files changed

+617
-0
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: macos-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js environment
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
22+
- name: Run Continuous Integration
23+
run: |
24+
npm install
25+
npm run build
26+
npx vitest --watch=false

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
yarn.lock
9+
10+
# Sys
11+
.DS_Store
12+
.idea
13+
14+
# Node
15+
node_modules/
16+
17+
# Build
18+
dist
19+
lib
20+
esm
21+
build
22+
23+
# Test
24+
coverage
25+
26+
# Editor
27+
.vscode
28+
.histor
29+
30+
# Package
31+
package-lock.json
32+
pnpm-lock.yaml
33+
bun.lock

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
echo "Running lint-staged"
3+
npx lint-staged

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": true,
3+
"singleQuote": false,
4+
"trailingComma": "all",
5+
"bracketSpacing": true
6+
}

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:lts-alpine
2+
3+
WORKDIR /app
4+
5+
# Copy package files
6+
COPY package*.json ./
7+
8+
# Install dependencies
9+
RUN npm install --ignore-scripts
10+
11+
# Copy application code
12+
COPY . .
13+
14+
# Build the application
15+
RUN npm run build
16+
17+
# Command will be provided by smithery.yaml
18+
CMD ["node", "build/index.js"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 hustcc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# <img src="https://echarts.apache.org/zh/images/favicon.png" height="24"/> MCP ECharts ![](https://badge.mcpx.dev?type=server 'MCP Server') [![build](https://github.com/hustcc/mcp-echarts/actions/workflows/build.yml/badge.svg)](https://github.com/hustcc/mcp-echarts/actions/workflows/build.yml) [![npm Version](https://img.shields.io/npm/v/mcp-echarts.svg)](https://www.npmjs.com/package/mcp-echarts) [![smithery badge](https://smithery.ai/badge/@hustcc/mcp-echarts)](https://smithery.ai/server/@hustcc/mcp-echarts) [![npm License](https://img.shields.io/npm/l/mcp-echarts.svg)](https://www.npmjs.com/package/mcp-echarts)
2+
3+
Generate <img src="https://echarts.apache.org/zh/images/favicon.png" height="14"/> [Apache ECharts](https://echarts.apache.org/) diagram and chart with AI MCP dynamically. Using for chart generation and data analysis.
4+
5+
<div align="center">
6+
<img width="648" alt="mcp-echarts" src="https://mdn.alipayobjects.com/huamei_1gdzij/afts/img/A*vwGqSKDW1OoAAAAARqAAAAgAemB7AQ/fmt.webp" />
7+
</div>
8+
9+
## ✨ Features
10+
11+
- Fully support all features and syntax of `ECharts`, include data, style, theme and so on.
12+
- Support exporting to `png`, `svg`, and `option` formats, with validation for `ECharts` to facilitate the model's multi-round output of correct syntax and graphics.
13+
- Lightweight, we can install it with `zero dependence`.
14+
- Extremely `secure`, fully generated locally, without relying on any remote services.
15+
16+
17+
## 🤖 Usage
18+
19+
To use with `Desktop APP`, such as Claude, VSCode, Cline, Cherry Studio, and so on, add the MCP server config below. On Mac system:
20+
21+
```json
22+
{
23+
"mcpServers": {
24+
"mcp-echarts": {
25+
"command": "npx",
26+
"args": [
27+
"-y",
28+
"mcp-echarts"
29+
]
30+
}
31+
}
32+
}
33+
```
34+
35+
On Window system:
36+
37+
```json
38+
{
39+
"mcpServers": {
40+
"mcp-echarts": {
41+
"command": "cmd",
42+
"args": [
43+
"/c",
44+
"npx",
45+
"-y",
46+
"mcp-echarts"
47+
]
48+
}
49+
}
50+
}
51+
```
52+
53+
Also, you can use it on aliyun, modelscope, glama.ai, smithery.ai or others with HTTP, SSE Protocol.
54+
55+
56+
## 🔨 Development
57+
58+
Install dependencies:
59+
60+
```bash
61+
npm install
62+
```
63+
64+
Build the server:
65+
66+
```bash
67+
npm run build
68+
```
69+
70+
Start the MCP server:
71+
72+
```bash
73+
npm run start
74+
```
75+
76+
77+
## 📄 License
78+
79+
MIT@[hustcc](https://github.com/hustcc).

__tests__/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { z } from "zod";
2+
import { zodToJsonSchema as zodToJsonSchemaOriginal } from "zod-to-json-schema";
3+
4+
// TODO: use zod v4 JSON to schema to replace zod-to-json-schema when v4 is stable
5+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
6+
export const zodToJsonSchema = (schema: z.ZodType<any>) => {
7+
return zodToJsonSchemaOriginal(schema, {
8+
rejectedAdditionalProperties: undefined,
9+
});
10+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "generate_echarts",
3+
"description": "Generate visual charts using Apache ECharts with echarts option and configuration dynamically. Apache ECharts is an Open Source JavaScript Visualization Library, which is used to create interactive charts and visualizations in web applications. It supports a wide range of chart types, including line charts, bar charts, pie charts, scatter plots, and more. ECharts is highly customizable and can be integrated with various data sources to create dynamic visualizations.",
4+
"inputSchema": {
5+
"type": "object",
6+
"properties": {
7+
"echartsOption": {
8+
"type": "string",
9+
"minLength": 1,
10+
"description": "ECharts option and configuration used to generate charts. For example:\n{\n \"title\": {\n \"text\": \"ECharts Entry Example\",\n \"left\": \"center\",\n \"top\": \"2%\"\n },\n \"tooltip\": {},\n \"xAxis\": {\n \"data\": [\"shirt\", \"cardigan\", \"chiffon\", \"pants\", \"heels\", \"socks\"]\n },\n \"yAxis\": {},\n \"series\": [{\n \"name\": \"Sales\",\n \"type\": \"bar\",\n \"data\": [5, 20, 36, 10, 10, 20]\n }]\n}\n\nATTENTION: A valid ECharts option must be a valid JSON string, and cannot be empty.\n"
11+
},
12+
"width": {
13+
"type": "number",
14+
"description": "The width of the ECharts in pixels. Default is 800.",
15+
"default": 800
16+
},
17+
"height": {
18+
"type": "number",
19+
"description": "The height of the ECharts in pixels. Default is 600.",
20+
"default": 600
21+
},
22+
"theme": {
23+
"type": "string",
24+
"enum": ["default", "dark"],
25+
"description": "ECharts theme, optional. Default is 'default'.",
26+
"default": "default"
27+
},
28+
"outputType": {
29+
"type": "string",
30+
"enum": ["png", "svg", "option"],
31+
"description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option.",
32+
"default": "png"
33+
}
34+
},
35+
"required": ["echartsOption"],
36+
"$schema": "http://json-schema.org/draft-07/schema#"
37+
}
38+
}

__tests__/tools/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it } from "vitest";
2+
import { generateEChartsTool } from "../../src/tools";
3+
import { zodToJsonSchema } from "../schema";
4+
import expects from "./generate-echarts.json";
5+
6+
describe("schema check", () => {
7+
it("echarts schema", () => {
8+
const { run, inputSchema, ...rest } = generateEChartsTool;
9+
10+
expect({
11+
...rest,
12+
inputSchema: zodToJsonSchema(inputSchema),
13+
}).toEqual(expects);
14+
});
15+
});

0 commit comments

Comments
 (0)