Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ npm run start
- [2niuhe](https://github.com/2niuhe): Support MCP with SSE and Streaming HTTP. [#17](https://github.com/hustcc/mcp-echarts/issues/17)
- [susuperli](https://github.com/susuperli): Use `MinIO` to save the chart image base64 and return the url. [#10](https://github.com/hustcc/mcp-echarts/issues/10)
- [BQXBQX](https://github.com/BQXBQX): Use `@napi-rs/canvas` instead node-canvas. [#3](https://github.com/hustcc/mcp-echarts/issues/3)
- [Meet-student](https://github.com/Meet-student): Add `outputType` schema for all chart tools. [#24](https://github.com/hustcc/mcp-echarts/issues/24)
- [hustcc](https://github.com/hustcc): Initial the repo.


Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/boxplot.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/candlestick.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/funnel.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/gauge.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/line.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/parallel.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data", "dimensions"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/pie.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/radar.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/sankey.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/scatter.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/sunburst.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
6 changes: 6 additions & 0 deletions __tests__/schema/treemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"exclusiveMinimum": 0,
"default": 800,
"description": "Set the width of the chart, default is 800px."
},
"outputType": {
"type": "string",
"enum": ["png", "svg", "option"],
"default": "png",
"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."
}
},
"required": ["data"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mcp-echarts",
"description": "❀️ Generate visual charts using Apache ECharts with AI MCP dynamically.",
"version": "0.5.0",
"version": "0.6.0",
"main": "build/index.js",
"scripts": {
"test": "vitest",
Expand Down
6 changes: 5 additions & 1 deletion src/tools/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AxisXTitleSchema,
AxisYTitleSchema,
HeightSchema,
OutputTypeSchema,
ThemeSchema,
TitleSchema,
WidthSchema,
Expand Down Expand Up @@ -54,6 +55,7 @@ export const generateBarChartTool = {
theme: ThemeSchema,
title: TitleSchema,
width: WidthSchema,
outputType: OutputTypeSchema,
}),
run: async (params: {
axisXTitle?: string;
Expand All @@ -65,6 +67,7 @@ export const generateBarChartTool = {
theme?: "default" | "dark";
title?: string;
width: number;
outputType?: "png" | "svg" | "option";
}) => {
const {
axisXTitle,
Expand All @@ -76,6 +79,7 @@ export const generateBarChartTool = {
theme,
title,
width,
outputType,
} = params;

// Check if data has group field for multiple series
Expand Down Expand Up @@ -169,7 +173,7 @@ export const generateBarChartTool = {
width,
height,
theme,
"png",
outputType,
"generate_bar_chart",
);
},
Expand Down
17 changes: 14 additions & 3 deletions src/tools/boxplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AxisXTitleSchema,
AxisYTitleSchema,
HeightSchema,
OutputTypeSchema,
ThemeSchema,
TitleSchema,
WidthSchema,
Expand Down Expand Up @@ -41,6 +42,7 @@ export const generateBoxplotChartTool = {
theme: ThemeSchema,
title: TitleSchema,
width: WidthSchema,
outputType: OutputTypeSchema,
}),
run: async (params: {
axisXTitle?: string;
Expand All @@ -50,9 +52,18 @@ export const generateBoxplotChartTool = {
theme?: "default" | "dark";
title?: string;
width: number;
outputType?: "png" | "svg" | "option";
}) => {
const { axisXTitle, axisYTitle, data, height, theme, title, width } =
params;
const {
axisXTitle,
axisYTitle,
data,
height,
theme,
title,
width,
outputType,
} = params;

// Group data by category and optional group
const hasGroups = data.some((item) => item.group);
Expand Down Expand Up @@ -186,7 +197,7 @@ export const generateBoxplotChartTool = {
width,
height,
theme,
"png",
outputType,
"generate_boxplot_chart",
);
},
Expand Down
15 changes: 13 additions & 2 deletions src/tools/candlestick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";
import { generateChartImage } from "../utils";
import {
HeightSchema,
OutputTypeSchema,
ThemeSchema,
TitleSchema,
WidthSchema,
Expand Down Expand Up @@ -40,6 +41,7 @@ export const generateCandlestickChartTool = {
theme: ThemeSchema,
title: TitleSchema,
width: WidthSchema,
outputType: OutputTypeSchema,
}),
run: async (params: {
data: Array<{
Expand All @@ -55,8 +57,17 @@ export const generateCandlestickChartTool = {
theme?: "default" | "dark";
title?: string;
width: number;
outputType?: "png" | "svg" | "option";
}) => {
const { data, height, showVolume = false, theme, title, width } = params;
const {
data,
height,
showVolume = false,
theme,
title,
width,
outputType,
} = params;

// Sort data by date
const sortedData = [...data].sort(
Expand Down Expand Up @@ -216,7 +227,7 @@ export const generateCandlestickChartTool = {
width,
height,
theme,
"png",
outputType,
"generate_candlestick_chart",
);
},
Expand Down
9 changes: 2 additions & 7 deletions src/tools/echarts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "zod";
import { generateChartImage } from "../utils";
import { OutputTypeSchema } from "../utils/schema";

function isValidEChartsOption(option: string): boolean {
try {
Expand Down Expand Up @@ -89,13 +90,7 @@ ATTENTION: A valid ECharts option must be a valid JSON string, and cannot be emp
.describe("ECharts theme, optional. Default is 'default'.")
.optional()
.default("default"),
outputType: z
.enum(["png", "svg", "option"])
.describe(
"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.",
)
.optional()
.default("png"),
outputType: OutputTypeSchema,
}),
run: async (params: {
echartsOption: string;
Expand Down
Loading
Loading