@microcharts/mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ import { c as catalog, i as findChart, n as AGENT_SETUP, o as LIBRARY_VERSION, r as getChart, t as renderChart } from "./render-core-CnQfk-v1.mjs";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { z } from "zod";
4
+ //#region src/version.ts
5
+ const MCP_VERSION = "0.1.0";
6
+ //#endregion
7
+ //#region src/server.ts
8
+ /**
9
+ * Output schemas. Declaring these is what lets a client type-check and validate
10
+ * `structuredContent` instead of re-parsing the text block — the SDK checks
11
+ * every result against them, so a drift between a tool's return type and what
12
+ * it advertises fails here rather than in a host.
13
+ */
14
+ const chartProp = z.object({
15
+ name: z.string(),
16
+ type: z.string(),
17
+ required: z.boolean(),
18
+ description: z.string(),
19
+ interactive: z.boolean().optional()
20
+ });
21
+ const findOutput = { results: z.array(z.object({
22
+ slug: z.string(),
23
+ name: z.string(),
24
+ tagline: z.string(),
25
+ dataShape: z.string(),
26
+ why: z.string().describe("The bestFor phrase or tagline that matched.")
27
+ })) };
28
+ const getOutput = {
29
+ slug: z.string(),
30
+ name: z.string(),
31
+ tagline: z.string(),
32
+ status: z.enum(["stable", "planned"]),
33
+ dataShape: z.string(),
34
+ encoding: z.object({
35
+ channel: z.string(),
36
+ precision: z.string()
37
+ }),
38
+ staticImport: z.string(),
39
+ interactiveImport: z.string().optional(),
40
+ bestFor: z.array(z.string()),
41
+ avoidFor: z.array(z.string()),
42
+ props: z.array(chartProp),
43
+ sharedProps: z.array(chartProp),
44
+ example: z.object({
45
+ title: z.string(),
46
+ code: z.string()
47
+ }),
48
+ sample: z.record(z.string(), z.unknown()).optional().describe("Ready-to-render props — pass straight to render_microchart.")
49
+ };
50
+ const renderOutput = {
51
+ svg: z.string(),
52
+ mimeType: z.enum(["image/svg+xml", "text/html"]),
53
+ summary: z.string().describe("The chart's generated accessible name — its alt text."),
54
+ width: z.number(),
55
+ height: z.number(),
56
+ library: z.string()
57
+ };
58
+ /**
59
+ * Build the microcharts MCP server: three tools (find / get / render) + two
60
+ * resources (the catalog, the agent-setup prompt). Transport-agnostic — `cli.ts`
61
+ * wires it to stdio; a remote host could wire the same server to Streamable HTTP
62
+ * without changing anything here.
63
+ */
64
+ function createServer() {
65
+ const server = new McpServer({
66
+ name: "microcharts",
67
+ version: MCP_VERSION
68
+ }, { instructions: `microcharts renders word-sized charts. Use find_microchart to pick a chart for a question, get_microchart to see its props and a runnable example, and render_microchart to get a finished SVG with alt text. This server snapshots @microcharts/react ${LIBRARY_VERSION}.` });
69
+ server.registerTool("find_microchart", {
70
+ title: "Find a chart by question",
71
+ description: "Rank microcharts chart types against a plain-language question about data (\"is it trending?\", \"error budget\", \"part to whole\"). Returns candidates with the reason each matched. Start here when you know the question, not the chart.",
72
+ inputSchema: {
73
+ question: z.string().describe("What the data needs to show, in plain language."),
74
+ dataShape: z.string().optional().describe("Optional filter, e.g. \"number[]\"."),
75
+ limit: z.number().int().min(1).max(20).optional().describe("Max results (default 6).")
76
+ },
77
+ outputSchema: findOutput
78
+ }, ({ question, dataShape, limit }) => {
79
+ const results = findChart(question, {
80
+ ...dataShape ? { dataShape } : {},
81
+ ...limit ? { limit } : {}
82
+ });
83
+ return {
84
+ content: [{
85
+ type: "text",
86
+ text: JSON.stringify(results, null, 2)
87
+ }],
88
+ structuredContent: { results }
89
+ };
90
+ });
91
+ server.registerTool("get_microchart", {
92
+ title: "Get a chart's props + example",
93
+ description: "Full wiring detail for one chart by slug: import paths, its props plus the shared props, data shape, best/avoid guidance, a copy-runnable example, and `sample` — the example as JSON props you can pass straight to render_microchart.",
94
+ inputSchema: { slug: z.string().describe("Chart slug, e.g. \"sparkline\".") },
95
+ outputSchema: getOutput
96
+ }, ({ slug }) => {
97
+ const result = getChart(slug);
98
+ if (!result) return {
99
+ content: [{
100
+ type: "text",
101
+ text: `Unknown chart "${slug}".`
102
+ }],
103
+ isError: true
104
+ };
105
+ return {
106
+ content: [{
107
+ type: "text",
108
+ text: JSON.stringify(result, null, 2)
109
+ }],
110
+ structuredContent: result
111
+ };
112
+ });
113
+ server.registerTool("render_microchart", {
114
+ title: "Render a chart to SVG",
115
+ description: "Render a chart to a finished, self-contained SVG (styles embedded) plus its generated alt text — for surfaces that can't run React. Pass the series as `data`; put other props (value, target, curve, color, width) in `props`. Each chart takes its own data shape — get_microchart returns a valid `sample` to adapt.",
116
+ inputSchema: {
117
+ type: z.string().describe("Chart slug, e.g. \"sparkline\"."),
118
+ data: z.any().optional().describe("Primary series; omit for scalar charts."),
119
+ props: z.record(z.string(), z.any()).optional().describe("Other props (value, target, color, …)."),
120
+ format: z.enum(["svg", "bare"]).optional().describe("`svg` (default) or `bare`.")
121
+ },
122
+ outputSchema: renderOutput
123
+ }, async (input) => {
124
+ try {
125
+ const result = await renderChart(input);
126
+ return {
127
+ content: [{
128
+ type: "text",
129
+ text: result.svg
130
+ }, {
131
+ type: "text",
132
+ text: `${result.summary} (${result.mimeType}, ${result.width}×${result.height})`
133
+ }],
134
+ structuredContent: result
135
+ };
136
+ } catch (err) {
137
+ return {
138
+ content: [{
139
+ type: "text",
140
+ text: err.message
141
+ }],
142
+ isError: true
143
+ };
144
+ }
145
+ });
146
+ server.registerResource("catalog", "microcharts://catalog", {
147
+ title: "microcharts catalog",
148
+ description: "Every chart type with metadata, props, and the library version stamp.",
149
+ mimeType: "application/json"
150
+ }, (uri) => ({ contents: [{
151
+ uri: uri.href,
152
+ mimeType: "application/json",
153
+ text: JSON.stringify(catalog)
154
+ }] }));
155
+ server.registerResource("agent-setup", "microcharts://agent-setup", {
156
+ title: "microcharts agent setup",
157
+ description: "The canonical prompt for wiring microcharts into a codebase.",
158
+ mimeType: "text/markdown"
159
+ }, (uri) => ({ contents: [{
160
+ uri: uri.href,
161
+ mimeType: "text/markdown",
162
+ text: AGENT_SETUP
163
+ }] }));
164
+ return server;
165
+ }
166
+ //#endregion
167
+ export { MCP_VERSION as n, createServer as t };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@microcharts/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server + Vercel AI-SDK tools for microcharts — let a model find, wire, and render word-sized charts.",
5
+ "keywords": [
6
+ "ai",
7
+ "ai-sdk",
8
+ "charts",
9
+ "llm",
10
+ "mcp",
11
+ "microcharts",
12
+ "model-context-protocol",
13
+ "sparkline",
14
+ "svg"
15
+ ],
16
+ "homepage": "https://microcharts.dev/docs/mcp",
17
+ "license": "MIT",
18
+ "author": "Ganapati V S",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ganapativs/microcharts.git",
22
+ "directory": "packages/mcp"
23
+ },
24
+ "bin": {
25
+ "microcharts-mcp": "./dist/cli.mjs"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "type": "module",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.mts",
34
+ "default": "./dist/index.mjs"
35
+ },
36
+ "./ai-sdk": {
37
+ "types": "./dist/ai-sdk.d.mts",
38
+ "default": "./dist/ai-sdk.mjs"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "provenance": true
45
+ },
46
+ "dependencies": {
47
+ "@modelcontextprotocol/sdk": "^1.29.0",
48
+ "react": "^18.0.0 || ^19.0.0",
49
+ "react-dom": "^18.0.0 || ^19.0.0",
50
+ "zod": "^3.25.76 || ^4.0.0",
51
+ "@microcharts/react": "^0.8.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^26.1.1",
55
+ "ai": "^7.0.37",
56
+ "esbuild": "^0.28.1",
57
+ "tsdown": "^0.22.14",
58
+ "tsx": "^4.23.1",
59
+ "vitest": "^4.1.10"
60
+ },
61
+ "peerDependencies": {
62
+ "ai": "^7.0.0"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "ai": {
66
+ "optional": true
67
+ }
68
+ },
69
+ "engines": {
70
+ "node": ">=20"
71
+ },
72
+ "mcpName": "io.github.ganapativs/microcharts",
73
+ "scripts": {
74
+ "gen": "tsx scripts/gen.ts",
75
+ "build": "tsdown",
76
+ "typecheck": "tsc --noEmit",
77
+ "test": "vitest run"
78
+ }
79
+ }