根据官方规范实现的模型上下文协议(MCP)服务器,提供了处理 JSON Canvas 文件的工具。该服务器支持创建、修改和验证无限画布数据结构。
JSON Canvas MCP 服务器实现了完整的 JSON Canvas 1.0 规范,支持以下功能:
服务器公开了以下资源:
canvas://schema:用于验证画布文件的 JSON Schemacanvas://examples:展示不同特性的示例画布文件canvas://templates:创建新画布的模板create_node
type (字符串):节点类型 ("text", "file", "link", "group")properties (对象):节点特定属性
id, x, y, width, height, colortext, file, url 等update_node
id (字符串):要更新的节点IDproperties (对象):要更新的属性delete_node
id (字符串):要删除的节点IDcreate_edge
id (字符串):唯一的边缘标识符fromNode (字符串):源节点IDtoNode (字符串):目标节点IDfromSide (可选字符串):起始边 ("top", "right", "bottom", "left")toSide (可选字符串):结束边color (可选字符串):边缘颜色label (可选字符串):边缘标签update_edge
id (字符串):要更新的边缘IDproperties (对象):要更新的属性delete_edge
id (字符串):要删除的边缘IDvalidate_canvas
canvas (对象):要验证的画布数据export_canvas
format (字符串):目标格式 ("json", "svg", "png")canvas (对象):要导出的画布数据在你的 claude_desktop_config.json 中添加以下内容:
{
"mcpServers": {
"jsoncanvas": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"canvas-data:/data",
"mcp/jsoncanvas"
],
"env": {
"OUTPUT_PATH": "/data/output"
}
}
}
}
{
"mcpServers": {
"jsoncanvas": {
"command": "uv",
"args": [
"--directory",
"/path/to/jsoncanvas",
"run",
"mcp-server-jsoncanvas"
],
"env": {
"OUTPUT_PATH": "./output"
}
}
}
}
服务器可以通过环境变量进行配置:
OUTPUT_PATH:画布文件保存的目录(默认:"./output")FORMAT:画布文件的默认输出格式(默认:"json")docker build -t mcp/jsoncanvas .
# 如果尚未安装,请安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# 创建虚拟环境并安装依赖项
uv venv
source .venv/bin/activate # 在 Windows 上:.venv\Scripts\activate
uv pip install -e .
# 运行测试
pytest
from jsoncanvas import Canvas, TextNode, Edge
# 创建节点
title = TextNode(
id="title",
x=100,
y=100,
width=400,
height=100,
text="# Hello Canvas\n\n这是一个演示。",
color="#4285F4"
)
info = TextNode(
id="info",
x=600,
y=100,
width=300,
height=100,
text="这里有更多的信息",
color="2" # 使用预设颜色
)
# 创建画布
canvas = Canvas()
canvas.add_node(title)
canvas.add_node(info)
# 连接节点
edge = Edge(
id="edge1",
from_node="title",
to_node="info",
from_side="right",
to_side="left",
label="连接"
)
canvas.add_edge(edge)
# 保存画布
canvas.save("example.canvas")
此 MCP 服务器采用 MIT 许可证。这意味着你可以自由地使用、修改和分发软件,但需遵守 MIT 许可证中的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。