使用说明
KiCad MCP Server
An MCP (Model Context Protocol) server that enables AI agents to perform PCB routing in KiCad.
Demo
Overview
This server exposes KiCad's PCB editing capabilities to AI agents via the MCP protocol.
PCB Layout Features
- Query board state (nets, pads, tracks, vias)
- Get design rules (clearances, track widths)
- Place tracks and vias
- Pathfinding with obstacle avoidance
- Delete routing elements
- Use transactions for batched changes
Schematic Capture (Experimental)
Schematic capture tools exist in the codebase but are still being commissioned and are hidden by default. To try them, set the environment variable KICAD_MCP_ENABLE_SCHEMATIC=1 before launching the server. Expect rough edges until this is marked stable.
Architecture
AI Agent <--MCP--> MCP Server <--IPC API (protobuf)--> KiCad
The MCP server communicates with KiCad using its IPC API (Protocol Buffers over named pipes on Windows, Unix sockets on Linux/Mac).
Requirements
- Python 3.10+
- KiCad 8.0+ with IPC API enabled
- Windows: pywin32 package
Installation
Prebuilt Installer (recommended)
A prebuilt Windows installer is available at https://nirulabs.co.za — the easiest way to get up and running without setting up a Python environment.
From source
cd kicad-mcp-server
# Install in development mode
pip install -e .
# On Windows, also install pywin32
pip install pywin32
Setup KiCad
- Open KiCad
- Go to Preferences > Preferences > API
- Enable the API
- Copy the API Token (you'll need this to connect)
- Open a PCB file
Test Connection
Before using with an AI agent, test the connection:
python scripts/test_connection.py <your-api-token>
Usage with Claude Desktop
Add to your Claude Desktop config (%APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"kicad": {
"command": "python",
"args": ["-m", "kicad_mcp.server"],
"cwd": "/path/to/kicad-mcp-server/src"
}
}
}
Available Tools
Connection & General
| Tool | Description |
|---|---|
connect_to_kicad |
Connect to a running KiCad instance (required first) |
get_kicad_version |
Get KiCad version info |
begin_commit |
Start a transaction |
end_commit |
Commit or drop a transaction |
PCB Layout Tools
| Tool | Description |
|---|---|
get_nets |
List all nets on the board |
get_layers |
Get board layer information |
get_tracks |
Get existing tracks (optionally by net) |
get_vias |
Get existing vias (optionally by net) |
get_pads |
Get all pads with positions, net assignments, and footprint references |
get_ratsnest |
Get unrouted connections showing which pads need to be connected |
get_design_rules |
Get design rules (clearances, track widths, via sizes) per net class |
check_clearance |
Check if a point/track would violate clearance rules |
find_path |
Find a collision-free path between two points using A* |
suggest_route |
Suggest a route between two pads by reference |
get_obstacles |
Get all obstacles on a layer for routing |
place_track |
Create a track segment |
place_via |
Create a via |
delete_item |
Remove a track or via |
Schematic Capture Tools (Experimental — hidden by default)
These tools are under active development. Enable them by setting KICAD_MCP_ENABLE_SCHEMATIC=1 in the server's environment.
| Tool | Description |
|---|---|
get_schematic_wires |
Get all wire segments in the schematic |
get_schematic_labels |
Get all labels (local, global, hierarchical, directive) |
get_schematic_symbols |
Get all symbols (components) in the schematic |
get_schematic_sheets |
Get all hierarchical sheets |
get_schematic_junctions |
Get all wire junctions |
get_schematic_no_connects |
Get all no-connect symbols |
draw_schematic_wire |
Draw a wire segment between two points |
add_schematic_label |
Add a label (net name) to the schematic |
add_schematic_symbol |
Add a symbol using s-expression format |
delete_schematic_item |
Remove a schematic element by ID |
Example: AI Routing Session
User: Connect to KiCad and show me the nets
AI: [calls connect_to_kicad with token]
[calls get_nets]
Found 15 nets:
- GND (code: 1)
- VCC (code: 2)
- NET1 (code: 3)
...
User: Route a track from (10, 20) to (30, 20) on the front copper layer for net GND
AI: [calls place_track with start=(10,20), end=(30,20), layer="F.Cu", net_code=1]
Created track with ID: abc123-...
Development
Recompile Protobufs
If KiCad's API changes:
pip install grpcio-tools
python scripts/compile_protos.py
Project Structure
kicad-mcp-server/
├── pyproject.toml
├── README.md
├── scripts/
│ ├── compile_protos.py
│ └── test_connection.py
├── src/kicad_mcp/
│ ├── __init__.py
│ ├── server.py # MCP server entry point
│ ├── ipc_client.py # KiCad IPC API client
│ ├── tools.py # MCP tool definitions
│ └── proto/ # Generated protobuf modules
│ ├── board/
│ ├── common/
│ └── schematic/
└── tests/
Current Limitations
PCB Layout
- No Push & Shove: The AI must calculate collision-free paths itself
- No Real-time DRC: Must query obstacles and design rules manually
Schematic Capture
- Limited Symbol Creation: Symbols must be created using s-expression format (similar to .kicad_sch file format)
- No Symbol Library Access: Cannot browse or search symbol libraries directly
- Limited Property Access: Some symbol properties may not be fully accessible via the API
Completed Improvements
- [x] Add
get_padstool for pad positions - [x] Add
get_ratsnestfor unconnected nets - [x] Add
get_design_rulesfor clearance constraints - [x] Add
check_clearancefor DRC validation - [x] Add pathfinding helpers for the AI (
find_path,suggest_route,get_obstacles) - [x] Add schematic capture tools (wires, labels, symbols, sheets)
Future Improvements
- [ ] Add symbol library browsing/searching
- [ ] Add schematic ERC (Electrical Rules Check)
- [ ] Improve symbol property editing
- [ ] Add bus support for schematics
License
MIT License - See LICENSE file