Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
07f18bfdfThis file is pinned to the selected release. Download the original to open it in your design tool.
/**
* Freerouting autoroute tools for KiCAD MCP server
*
* Provides autorouting via Freerouting (Specctra DSN/SES workflow).
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export function registerFreeroutingTools(server: McpServer, callKicadScript: Function) {
// Full autoroute: export DSN -> run Freerouting -> import SES
server.tool(
"autoroute",
"Run Freerouting autorouter on the current PCB. Exports to Specctra DSN, runs Freerouting CLI, and imports the routed SES result. Requires Java 11+ and freerouting.jar (see check_freerouting).",
{
boardPath: z.string().optional().describe("Path to .kicad_pcb file (default: current board)"),
freeroutingJar: z
.string()
.optional()
.describe(
"Path to freerouting.jar (default: ~/.kicad-mcp/freerouting.jar or FREEROUTING_JAR env)",
),
maxPasses: z.number().optional().describe("Maximum routing passes (default: 20)"),
timeout: z.number().optional().describe("Timeout in seconds (default: 300)"),
},
async (args: any) => {
const result = await callKicadScript("autoroute", args);
return {
content: [
{
type: "text",
text: JSON.stringify(result, null, 2),
},
],
};
},
);
// Export DSN only
server.tool(
"export_dsn",
"Export the current PCB to Specctra DSN format. Useful for manual Freerouting workflow or external autorouters.",
{
boardPath: z.string().optional().describe("Path to .kicad_pcb file (default: current board)"),
outputPath: z
.string()
.optional()
.describe("Output DSN file path (default: same dir as board)"),
},
async (args: any) => {
const result = await callKicadScript("export_dsn", args);
return {
content: [
{
type: "text",
text: JSON.stringify(result, null, 2),
},
],
};
},
);
// Import SES
server.tool(
"import_ses",
"Import a Specctra SES (session) file into the current PCB. Use after running Freerouting externally.",
{
sesPath: z.string().describe("Path to the .ses file to import"),
boardPath: z.string().optional().describe("Path to .kicad_pcb file (default: current board)"),
},
async (args: any) => {
const result = await callKicadScript("import_ses", args);
return {
content: [
{
type: "text",
text: JSON.stringify(result, null, 2),
},
],
};
},
);
// Check Freerouting dependencies
server.tool(
"check_freerouting",
"Check if Java and Freerouting JAR are available on the system. Run this before autoroute to verify prerequisites.",
{
freeroutingJar: z.string().optional().describe("Path to freerouting.jar to check"),
},
async (args: any) => {
const result = await callKicadScript("check_freerouting", args);
return {
content: [
{
type: "text",
text: JSON.stringify(result, null, 2),
},
],
};
},
);
}