MCP服务器电路图
用于读取和分析的模型上下文协议(MCP)服务器 .cddx 电路图文件。此服务器使Claude Code能够与电路图文档文件交互,提取元件信息、连接和元数据。
特性
- 读取电路文件:解析
.cddx文件(包含XML电路数据的ZIP存档) - 成分分析:提取组件类型、ID、位置和属性
- 连接映射:识别组件之间的电线和连接
- 元数据提取:检索文档元数据(作者、日期等)
- 错误处理:对无效文件的强大错误处理
什么是.cddx文件?
.cddx 文件是电路图软件使用的电路图文档文件。它们是ZIP存档,包含:
circuitdiagram/Document.xml-XML格式的主电路图数据- 其他元数据和资源
安装
先决条件
- Python 3.10或更高版本
- pip(Python包管理器)
- 互联网连接(用于下载电路图CLI)
步骤1:安装MCP服务器依赖项
打开PowerShell或命令提示符并导航到此目录:
cd C:\Users\jcmec\Desktop\DevRepos\circuit-mcp-server安装MCP服务器所需的Python包:
pip install -r requirements.txt步骤2:安装电路图CLI工具
MCP服务器使用电路图CLI来呈现电路图。自动安装:
python setup.py这将:
- 下载适用于您平台(Windows/Linux/macOS)的电路图CLI二进制文件
- 将其安装到
bin/目录 - 将电路元件文件下载到
components/目录 - 验证安装
选项:
python setup.py --force-即使已安装,也强制重新安装python setup.py --path /custom/dir-安装到自定义目录
备注:在Linux上,您可能需要安装libfontconfig1:
sudo apt-get install libfontconfig1有关详细的安装信息,请参阅 README_INSTALL.md 运行安装程序后。
步骤3:测试服务器(可选)
您可以使用MCP检查器工具独立测试服务器:
npx @modelcontextprotocol/inspector python circuit_server.py这将打开一个web界面,您可以在其中测试 read_circuit 工具直接。
Claude代码的配置
Windows配置
将MCP服务器添加到您的Claude Code配置文件中:
位置: %APPDATA%\Claude\claude_desktop_config.json
(通常: C:\Users\YourUsername\AppData\Roaming\Claude\claude_desktop_config.json)
要添加的配置:
{
"mcpServers": {
"circuit-diagram": {
"command": "python",
"args": [
"C:\\Users\\jcmec\\Desktop\\DevRepos\\circuit-mcp-server\\circuit_server.py"
]
}
}
}重要:
- 使用双反睫毛(
\\)在Windows路径中 - 替换
C:\\Users\\jcmec\\如果不同,请使用您的实际用户名/路径 - 如果您有其他MCP服务器,请将此条目添加到现有的
mcpServers对象
完整配置示例
如果这是您唯一的MCP服务器:
{
"mcpServers": {
"circuit-diagram": {
"command": "python",
"args": [
"C:\\Users\\jcmec\\Desktop\\DevRepos\\circuit-mcp-server\\circuit_server.py"
]
}
}
}如果您已经有其他服务器:
{
"mcpServers": {
"existing-server": {
"command": "existing-command",
"args": ["..."]
},
"circuit-diagram": {
"command": "python",
"args": [
"C:\\Users\\jcmec\\Desktop\\DevRepos\\circuit-mcp-server\\circuit_server.py"
]
}
}
}步骤4:重新启动Claude代码
添加配置后:
- 完全关闭克劳德代码/克劳德桌面
- 重新打开应用程序
- 电路图服务器现在应该可用
用法
配置后,您可以使用Claude Code分析电路文件:
示例命令
读取电路文件:
Can you read the circuit diagram at C:\circuits\my_circuit.cddx?分析组件:
What components are in the circuit file C:\circuits\my_circuit.cddx?获取连接信息:
Show me the connections in C:\circuits\my_circuit.cddx使用read_circuit工具
MCP服务器提供 read_circuit 克劳德可以自动调用的工具。工具:
- 输入:指向a的文件路径
.cddx文件(绝对或相对路径) - 输出:详细分析包括:
- 文档元数据(作者、创建日期等) - 组件的数量和类型 - 组件属性和位置 - 组件之间的接线 - 文档属性
输出示例
Circuit Diagram Analysis: example_circuit.cddx
============================================================
METADATA:
----------------------------------------
Author: John Doe
Created: 2024-01-15
COMPONENTS: 5
----------------------------------------
[1] Type: Resistor, ID: R1
Location: (100, 200)
Resistance: 1kΩ
[2] Type: Capacitor, ID: C1
Location: (200, 200)
Capacitance: 10µF
[3] Type: LED, ID: D1
Location: (300, 200)
COMPONENT SUMMARY BY TYPE:
----------------------------------------
Resistor: 2 component(s)
Capacitor: 1 component(s)
LED: 2 component(s)
CONNECTIONS/WIRES: 4
----------------------------------------
[1] Wire ID: wire_1
From: (100, 200) To: (200, 200)
[2] Wire ID: wire_2
From: (200, 200) To: (300, 200)测试
创建测试回路文件
样品 .cddx 文件(test_circuit.cddx)包含在此存储库中用于测试目的。
使用MCP检查员进行测试
npx @modelcontextprotocol/inspector python circuit_server.py然后使用web界面调用 read_circuit 使用测试文件路径。
使用Claude代码进行测试
- 确保服务器已在中配置
claude_desktop_config.json - 重新启动Claude代码
- 请Claude分析测试文件:
Please analyze the circuit at C:\Users\jcmec\Desktop\DevRepos\circuit-mcp-server\test_circuit.cddx故障排除
服务器未出现在Claude代码中
- 检查
claude_desktop_config.json存在于%APPDATA%\Claude\ - 验证JSON语法是否有效(使用JSON验证器)
- 确保路径使用双反斜杠(
\\) - 完全重新启动Claude代码
找不到Python
如果你得到“python无法识别”:
- 确保Python已安装并位于PATH中
- 尝试使用python.exe的完整路径:
{
"mcpServers": {
"circuit-diagram": {
"command": "C:\\Python311\\python.exe",
"args": ["C:\\Users\\jcmec\\Desktop\\DevRepos\\circuit-mcp-server\\circuit_server.py"]
}
}
}未找到模块“mcp”
确保您安装了以下要求:
pip install -r requirements.txt如果使用虚拟环境,请确保在安装之前将其激活。
未找到电路图CLI
如果您收到有关找不到电路图CLI的错误:
- 确保您运行了安装脚本:
python setup.py- 验证是否安装了CLI:
./bin/circuit-diagram --help
# Windows: .\bin\circuit-diagram.exe --help- 如果仍然不起作用,请尝试重新安装:
python setup.py --force文件路径问题
- 使用绝对路径
.cddx文件 - 使用带有反斜杠或正斜杠的Windows样式路径
- 确保文件路径存在并且可访问
发展
项目结构
circuit-mcp-server/
├── circuit_server.py # Main MCP server implementation
├── setup.py # Installation script for circuit-diagram CLI
├── requirements.txt # Python dependencies for MCP server
├── README.md # This file
├── test_circuit.cddx # Sample circuit file for testing
├── bin/ # Created by setup.py - contains CLI executable
│ └── circuit-diagram # (or circuit-diagram.exe on Windows)
├── components/ # Created by setup.py - circuit components
│ └── *.xml # Component definition files
└── README_INSTALL.md # Created by setup.py - CLI installation details扩展服务器
要添加更多工具,请编辑 circuit_server.py:
- 在中添加新工具
list_tools()函数 - 在中添加处理
call_tool()函数 - 执行工具逻辑
XML 模式
电路图XML通常遵循以下结构:
Name
Date
许可证
本项目按原样提供,用于教育和发展目的。
支持
对于问题或疑问:
- 检查上面的故障排除部分
- 审查MCP文件:https://modelcontextprotocol.io
- 确保您的
.cddx文件是有效的电路图文档
