Add Freerouting autoroute integration

4 new MCP tools: autoroute (full DSN→Freerouting→SES pipeline),
export_dsn, import_ses, check_freerouting. Requires Java 11+ and
freerouting.jar. Includes 21 test cases and README usage examples.
This commit is contained in:
Jeff Laflamme
2026-03-20 11:33:37 +07:00
parent 5b380c0f17
commit 53a8b3ff3e
8 changed files with 941 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import { registerDatasheetTools } from "./tools/datasheet.js";
import { registerFootprintTools } from "./tools/footprint.js";
import { registerSymbolCreatorTools } from "./tools/symbol-creator.js";
import { registerUITools } from "./tools/ui.js";
import { registerFreeroutingTools } from "./tools/freerouting.js";
import { registerRouterTools } from "./tools/router.js";
// Import resource registration functions
@@ -251,6 +252,7 @@ export class KiCADMcpServer {
registerFootprintTools(this.server, this.callKicadScript.bind(this));
registerSymbolCreatorTools(this.server, this.callKicadScript.bind(this));
registerUITools(this.server, this.callKicadScript.bind(this));
registerFreeroutingTools(this.server, this.callKicadScript.bind(this));
// Register all resources
registerProjectResources(this.server, this.callKicadScript.bind(this));

124
src/tools/freerouting.ts Normal file
View File

@@ -0,0 +1,124 @@
/**
* 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),
},
],
};
},
);
}

View File

@@ -16,3 +16,4 @@ export { registerUITools } from "./ui.js";
export { registerDatasheetTools } from "./datasheet.js";
export { registerFootprintTools } from "./footprint.js";
export { registerSymbolCreatorTools } from "./symbol-creator.js";
export { registerFreeroutingTools } from "./freerouting.js";

View File

@@ -126,6 +126,16 @@ export const toolCategories: ToolCategory[] = [
"add_via",
"add_copper_pour"
]
},
{
name: "autoroute",
description: "Freerouting autorouter: automatic PCB routing via Specctra DSN/SES",
tools: [
"autoroute",
"export_dsn",
"import_ses",
"check_freerouting"
]
}
];