这是一个使用 Kroki.io 将 Mermaid 图表转换为 SVG 图像的 MCP(模型上下文协议)服务器。
git clone https://github.com/tkoba1974/mcp-kroki.git
cd mcp-kroki
npm install
npm run build
该服务器提供两个主要工具:
使用 Kroki.io 生成一个图表的 URL。
参数:
type: 图表类型(例如,“mermaid”,“plantuml”)content: 指定格式下的图表内容outputFormat(可选):输出格式(svg, png, pdf, jpeg, base64)下载图表到本地文件。
参数:
type: 图表类型(例如,“mermaid”,“plantuml”)content: 指定格式下的图表内容outputPath: 应保存图表的路径outputFormat(可选):输出格式(svg, png, pdf, jpeg)scale(可选,数字,默认值:1.0):图表尺寸的比例因子。目前仅影响 SVG 输出,通过尝试修改宽度/高度属性来实现。最小值为 0.1。// 生成一个 Mermaid 图表的 URL
const result = await callTool('generate_diagram_url', {
type: 'mermaid',
content: 'graph TD; A-->B; B-->C; C-->D;',
outputFormat: 'svg'
});
// 下载一个 Mermaid 图表
const result = await callTool('download_diagram', {
type: 'mermaid',
content: 'graph TD; A-->B; B-->C; C-->D;',
outputPath: '/path/to/diagram.svg'
});
服务器使用 Kroki.io API 来转换图表。在发送给 Kroki.io 之前,图表内容会被压缩并编码。
添加到你的 Claude Desktop 配置文件(claude_desktop_config.json)中:
{
"mcpServers": {
"mcp-kroki": {
"command": "node",
"args": ["/path/to/mcp-kroki/build/index.js"]
}
}
}
{
"mcpServers": {
"mcp-kroki": {
"command": "npx",
"args": [
"-y",
"@tkoba1974/mcp-kroki"
]
}
}
}
MIT