@figviz/figviz-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.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/index.js +114 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Figviz
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Figviz MCP server
|
|
2
|
+
|
|
3
|
+
Generate clear, **labeled science & math diagrams** (biology, chemistry, physics,
|
|
4
|
+
K-12 math, lab setups, graphic organizers) straight from your AI assistant, via
|
|
5
|
+
the [Figviz](https://figviz.com) API.
|
|
6
|
+
|
|
7
|
+
Works with any [Model Context Protocol](https://modelcontextprotocol.io) client —
|
|
8
|
+
Claude Desktop, Cursor, Cline, Windsurf, and more.
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
Exposes one tool:
|
|
13
|
+
|
|
14
|
+
- **`generate_diagram`** — describe a diagram in plain text and get back a hosted
|
|
15
|
+
image URL. Options: `quality` (`1k` / `2k` / `4k`) and `aspectRatio`
|
|
16
|
+
(e.g. `16:9`, `1:1`).
|
|
17
|
+
|
|
18
|
+
Example prompts:
|
|
19
|
+
|
|
20
|
+
- "labeled plant cell cross-section for 8th grade"
|
|
21
|
+
- "convex lens ray diagram, object between F and 2F"
|
|
22
|
+
- "acid–base titration setup for high school chemistry"
|
|
23
|
+
- "KWL chart graphic organizer, blank"
|
|
24
|
+
|
|
25
|
+
## Get an API key
|
|
26
|
+
|
|
27
|
+
Create a free key (includes 3 credits) at **https://figviz.com/settings/api**.
|
|
28
|
+
Figviz is pay-as-you-go — no subscription, credits never expire.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
Run it with `npx` (no install needed):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
FIGVIZ_API_KEY=fvk_xxx npx -y figviz-mcp
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Claude Desktop
|
|
39
|
+
|
|
40
|
+
Add to `claude_desktop_config.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"figviz": {
|
|
46
|
+
"command": "npx",
|
|
47
|
+
"args": ["-y", "figviz-mcp"],
|
|
48
|
+
"env": { "FIGVIZ_API_KEY": "fvk_xxx" }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Cursor / Cline / Windsurf
|
|
55
|
+
|
|
56
|
+
Add the same server entry to your client's MCP config (`mcp.json` or the MCP
|
|
57
|
+
settings UI):
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"figviz": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": ["-y", "figviz-mcp"],
|
|
65
|
+
"env": { "FIGVIZ_API_KEY": "fvk_xxx" }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then ask your assistant: *"Use figviz to generate a labeled animal cell diagram
|
|
72
|
+
for 7th grade."*
|
|
73
|
+
|
|
74
|
+
## Environment variables
|
|
75
|
+
|
|
76
|
+
| Variable | Required | Default | Description |
|
|
77
|
+
| ----------------- | -------- | -------------------- | --------------------------------- |
|
|
78
|
+
| `FIGVIZ_API_KEY` | yes | — | Your `fvk_…` key from figviz.com |
|
|
79
|
+
| `FIGVIZ_API_BASE` | no | `https://figviz.com` | Override the API host (advanced) |
|
|
80
|
+
|
|
81
|
+
## Credits & pricing
|
|
82
|
+
|
|
83
|
+
Each diagram costs 1 credit (4k costs 1.5). Buy credit packs at
|
|
84
|
+
https://figviz.com/pricing. The MCP shares the same balance as your Figviz
|
|
85
|
+
account.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Figviz MCP server.
|
|
4
|
+
*
|
|
5
|
+
* Exposes a `generate_diagram` tool so MCP clients (Claude Desktop, Cursor,
|
|
6
|
+
* Cline, Windsurf, etc.) can generate labeled science & math diagrams from a
|
|
7
|
+
* text description via the Figviz public API.
|
|
8
|
+
*
|
|
9
|
+
* Auth: set FIGVIZ_API_KEY (get a free key with 3 credits at
|
|
10
|
+
* https://figviz.com/settings/api). Optional FIGVIZ_API_BASE overrides the host.
|
|
11
|
+
*/
|
|
12
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
13
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
const API_BASE = (process.env.FIGVIZ_API_BASE ?? 'https://figviz.com').replace(/\/+$/, '');
|
|
16
|
+
const API_KEY = process.env.FIGVIZ_API_KEY;
|
|
17
|
+
const GET_KEY_URL = 'https://figviz.com/settings/api';
|
|
18
|
+
const PRICING_URL = 'https://figviz.com/pricing';
|
|
19
|
+
const server = new McpServer({ name: 'figviz', version: '0.1.0' });
|
|
20
|
+
server.registerTool('generate_diagram', {
|
|
21
|
+
title: 'Generate a science or math diagram',
|
|
22
|
+
description: 'Generate a clear, labeled science or math diagram (biology, chemistry, physics, K-12 math, lab setups, graphic organizers) from a plain-text description using Figviz. Returns hosted image URL(s). Requires the FIGVIZ_API_KEY environment variable.',
|
|
23
|
+
inputSchema: {
|
|
24
|
+
prompt: z
|
|
25
|
+
.string()
|
|
26
|
+
.min(3)
|
|
27
|
+
.describe("What to draw, e.g. 'labeled plant cell cross-section for 8th grade' or 'convex lens ray diagram, object between F and 2F'"),
|
|
28
|
+
quality: z
|
|
29
|
+
.enum(['1k', '2k', '4k'])
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Resolution. 4k costs 1.5 credits; 1k/2k cost 1. Default 1k.'),
|
|
32
|
+
aspectRatio: z
|
|
33
|
+
.string()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Aspect ratio, e.g. '16:9', '1:1', '4:3'. Omit for auto."),
|
|
36
|
+
},
|
|
37
|
+
}, async ({ prompt, quality, aspectRatio }) => {
|
|
38
|
+
if (!API_KEY) {
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: 'text',
|
|
44
|
+
text: `FIGVIZ_API_KEY is not set. Get a free key (3 credits included) at ${GET_KEY_URL}, then set the FIGVIZ_API_KEY environment variable in your MCP client config.`,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(`${API_BASE}/api/v1/generate`, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
'content-type': 'application/json',
|
|
54
|
+
authorization: `Bearer ${API_KEY}`,
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify({ prompt, quality, aspectRatio }),
|
|
57
|
+
});
|
|
58
|
+
const data = (await res.json().catch(() => null));
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
const base = data?.error ?? `Request failed (HTTP ${res.status}).`;
|
|
61
|
+
let hint = '';
|
|
62
|
+
if (res.status === 402)
|
|
63
|
+
hint = ` Buy a credit pack at ${PRICING_URL}.`;
|
|
64
|
+
else if (res.status === 401)
|
|
65
|
+
hint = ` Check your FIGVIZ_API_KEY (get one at ${GET_KEY_URL}).`;
|
|
66
|
+
return {
|
|
67
|
+
isError: true,
|
|
68
|
+
content: [{ type: 'text', text: base + hint }],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const images = data?.images ?? [];
|
|
72
|
+
if (images.length === 0) {
|
|
73
|
+
return {
|
|
74
|
+
isError: true,
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: 'text',
|
|
78
|
+
text: 'No image was generated. Try rephrasing the prompt with a clearer subject and grade level.',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const body = images
|
|
84
|
+
.map((img) => `\n${img.url}`)
|
|
85
|
+
.join('\n\n');
|
|
86
|
+
const credits = typeof data?.credits_remaining === 'number'
|
|
87
|
+
? `\n\nCredits remaining: ${data.credits_remaining}`
|
|
88
|
+
: '';
|
|
89
|
+
return {
|
|
90
|
+
content: [{ type: 'text', text: `${body}${credits}` }],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return {
|
|
95
|
+
isError: true,
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: `Network error contacting Figviz: ${err instanceof Error ? err.message : String(err)}`,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
async function main() {
|
|
106
|
+
const transport = new StdioServerTransport();
|
|
107
|
+
await server.connect(transport);
|
|
108
|
+
// Logs go to stderr so they don't corrupt the stdio JSON-RPC stream.
|
|
109
|
+
console.error('Figviz MCP server running on stdio');
|
|
110
|
+
}
|
|
111
|
+
main().catch((err) => {
|
|
112
|
+
console.error('Fatal error starting Figviz MCP server:', err);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@figviz/figviz-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for Figviz — generate labeled science & math diagrams (biology, chemistry, physics, K-12 math) from text via the Figviz API.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"figviz-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"start": "node dist/index.js",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"mcp",
|
|
27
|
+
"model-context-protocol",
|
|
28
|
+
"figviz",
|
|
29
|
+
"diagram",
|
|
30
|
+
"diagram-generator",
|
|
31
|
+
"science",
|
|
32
|
+
"education",
|
|
33
|
+
"ai",
|
|
34
|
+
"claude",
|
|
35
|
+
"cursor"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"author": "Figviz <support@figviz.com>",
|
|
39
|
+
"homepage": "https://figviz.com",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/jyjyxt/figviz-mcp.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/jyjyxt/figviz-mcp/issues"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
49
|
+
"zod": "^3.23.8"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^22.10.0",
|
|
53
|
+
"typescript": "^5.7.0"
|
|
54
|
+
}
|
|
55
|
+
}
|