gramfig-mcp 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gramfig
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 CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # gramfig-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 图数学堂(Gramfig)的本地 MCP 服务。通过 **stdio** 向 AI 客户端提供 LaTeX 公式渲染、函数图像绘制与平面几何工具,不依赖浏览器、网络或云端状态。
4
+
5
+ > A stateless MCP stdio server for LaTeX rendering, function plotting, and plane geometry documents.
6
+
7
+ ## 快速开始
8
+
9
+ 要求 Node.js 22+:
10
+
11
+ ```bash
12
+ npx -y gramfig-mcp
13
+ ```
14
+
15
+ 在支持 stdio 的 MCP 客户端中配置:
16
+
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "gramfig": {
21
+ "command": "npx",
22
+ "args": ["-y", "gramfig-mcp"]
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ 服务启动日志只写入 stderr,stdout 专用于 MCP 协议帧。
29
+
30
+ ## 工具
31
+
32
+ | 工具 | 用途 |
33
+ |---|---|
34
+ | `latex_render` | LaTeX 数学/化学公式 → 安全 HTML 或小程序 rich-text nodes |
35
+ | `graph_plot` | mathjs 表达式 → SVG/PNG 函数图像 |
36
+ | `geometry_solve` | 校验并求解 `protocolVersion: 1` 平面几何文档 |
37
+ | `geometry_measure` | 读取或临时查询长度、周长、面积、角度 |
38
+ | `geometry_render` | 纯几何文档 → SVG/PNG(含 LaTeX 标注) |
39
+
40
+ ### latex_render
41
+
42
+ ```json
43
+ {
44
+ "latex": "\\frac{a}{b}",
45
+ "displayMode": false,
46
+ "outputs": ["html"]
47
+ }
48
+ ```
49
+
50
+ 数学公式走 KaTeX,`\ce{}` 化学公式自动分流 MathJax;HTML 经过白名单清洗。`latex` 上限 4096 字符。
51
+
52
+ ### graph_plot
53
+
54
+ ```json
55
+ {
56
+ "expressions": [
57
+ { "raw": "sin(x)", "label": "sin" },
58
+ { "raw": "x^2", "label": "x²", "color": "#dc2626" }
59
+ ],
60
+ "viewport": { "xMin": -6, "xMax": 6, "yMin": -4, "yMax": 4 },
61
+ "format": "svg"
62
+ }
63
+ ```
64
+
65
+ 支持 1–8 条曲线,单条表达式 ≤ 200 字符;可输出 SVG 或 base64 PNG,支持 light/dark 主题。
66
+
67
+ ### geometry_solve / geometry_measure / geometry_render
68
+
69
+ ```json
70
+ {
71
+ "protocolVersion": 1,
72
+ "elements": [
73
+ { "id": "a", "type": "point", "position": [0, 0] },
74
+ { "id": "b", "type": "point", "position": [2, 0] },
75
+ { "id": "s", "type": "segment", "parents": ["a", "b"] }
76
+ ],
77
+ "viewport": { "xMin": -3, "xMax": 3, "yMin": -2, "yMax": 2, "keepAspectRatio": true }
78
+ }
79
+ ```
80
+
81
+ 推荐链路:`geometry_solve` 自检并修正文档 → `geometry_measure` 取测量值 → `geometry_render` 输出图像。几何工具仅接受纯几何 v1 文档,v2/含函数方程文档请使用 `graph_plot`。
82
+
83
+ 完整协议、变换/轨迹、限额与错误码见 [docs/mcp-geometry.md](https://github.com/gaorock530/studylab/blob/main/docs/mcp-geometry.md)。
84
+
85
+ ## 限制
86
+
87
+ - 几何文档 JSON ≤ 512KB,元素数 ≤ 500
88
+ - 测量查询 ≤ 50 条;轨迹采样 16–400、总量 ≤ 100000
89
+ - 画布尺寸 200–2000 px;PNG base64 ≤ 8MB
90
+ - 服务不读写文件、不访问网络、不保存会话状态
91
+
92
+ 错误码:`INVALID_DOCUMENT`、`DUPLICATE_ID`、`UNKNOWN_PARENT`、`CYCLE`、`DEGENERATE`、`UNSUPPORTED_TYPE`、`UNSUPPORTED_CURVE_DEPENDENT`、`UNSUPPORTED_DOCUMENT`、`LIMIT_EXCEEDED`、`RENDER_FAILED`。
93
+
94
+ ## 开发
95
+
96
+ ```bash
97
+ corepack pnpm --filter gramfig-mcp typecheck
98
+ corepack pnpm --filter gramfig-mcp test
99
+ corepack pnpm --filter gramfig-mcp build
100
+ corepack pnpm --filter gramfig-mcp pack
101
+ ```
102
+
103
+ `prepack` 会先构建 `@studylab/formula`、`@studylab/viz`,再用 esbuild 把内部包内联为单个 `dist/main.js`;`@resvg/resvg-js`、`jsdom`、KaTeX/MathJax 等保持为运行时依赖。
104
+
105
+ ## License
106
+
107
+ [MIT](./LICENSE)