这是一个基于模型上下文协议(MCP)的SVG转PNG工具服务器。
目前支持两种SVG到PNG的转换方案:
Cairo SVG 方案(当前使用中)
cairosvg库进行转换Inkscape 解决方案(备选)
注意:当前版本默认使用CairoSVG方案。如果遇到字体渲染或复杂SVG转换问题,可考虑切换至Inkscape方案。
svg2png_mcp/
├── src/
│ ├── server.py # MCP服务器实现
│ ├── svg2png.py # SVG转PNG的业务逻辑
│ └── test_client.py # 测试客户端
├── servers_config.example.json # MCP服务器配置示例
└── requirements.txt # 依赖文件
要通过 Smithery 自动安装SVG到PNG MCP服务器给Claude桌面:
npx -y @smithery/cli install @longbowzz/svg2png_mcp --client claude
# 创建虚拟环境
python -m venv venv
# 激活虚拟环境
# 在 macOS/Linux 上:
source venv/bin/activate
# 在 Windows 上:
.\venv\Scripts\activate
pip install -r requirements.txt
cp servers_config.example.json servers_config.json
servers_config.json,必须使用绝对路径:{
"mcpServers": {
"svg2png": {
"command": "/absolute/path/to/venv/bin/python",
"args": [
"/absolute/path/to/svg2png_mcp/src/server.py"
]
}
}
}
⚠️ 重要提示:
command 必须是虚拟环境中的Python解释器的绝对路径server.py 的路径必须是绝对路径获取路径的方法:
# 获取Python解释器的绝对路径(在虚拟环境中运行)
which python # macOS/Linux
where python # Windows
# 获取项目根目录的绝对路径
pwd # macOS/Linux
cd # Windows
示例(macOS/Linux):
{
"mcpServers": {
"svg2png": {
"command": "/Users/username/projects/svg2png_mcp/venv/bin/python",
"args": [
"/Users/username/projects/svg2png_mcp/src/server.py"
]
}
}
}
示例(Windows):
{
"mcpServers": {
"svg2png": {
"command": "C:\\Users\\username\\projects\\svg2png_mcp\\venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\username\\projects\\svg2png_mcp\\src\\server.py"
]
}
}
}
运行测试客户端:
# 确保虚拟环境已激活
source venv/bin/activate # macOS/Linux
# 运行客户端
python src/test_client.py
如果正常运行,将在test_output目录下生成名为'output.png'的图片。
将服务器配置文件的内容填入cursor和Claude桌面等MCP客户端以使用。
注意:
servers_config.json自动响应配置启动服务器servers_config.json使用了正确的绝对路径svg_to_png工具接口