feat: Add local symbol library search and 3rd party library support (#25)

Adds comprehensive local KiCad symbol library search functionality and fixes KICAD9_3RD_PARTY environment variable resolution.

Features:
- Symbol library search by name, LCSC ID, description, manufacturer, MPN
- Support for 3rd party libraries installed via Plugin and Content Manager
- New MCP tools: search_symbols, list_symbol_libraries, get_symbol_info
- Enhanced library path resolution for KiCad 8 and 9

This enables users with locally installed JLCPCB libraries to search and use components directly.

Co-authored-by: l3wi <l3wi@users.noreply.github.com>
This commit is contained in:
Lewis Freiberg
2025-12-31 16:57:10 +01:00
committed by GitHub
parent 8a1cb46b39
commit 0227dd48d2
7 changed files with 899 additions and 11 deletions

View File

@@ -28,9 +28,10 @@ export function registerSchematicTools(server: McpServer, callKicadScript: Funct
// Add component to schematic
server.tool(
"add_schematic_component",
"Add a component to the schematic",
"Add a component to the schematic. Symbol format is 'Library:SymbolName' (e.g., 'Device:R', 'EDA-MCP:ESP32-C3')",
{
symbol: z.string().describe("Symbol library reference"),
schematicPath: z.string().describe("Path to the schematic file"),
symbol: z.string().describe("Symbol library:name reference (e.g., Device:R, EDA-MCP:ESP32-C3)"),
reference: z.string().describe("Component reference (e.g., R1, U1)"),
value: z.string().optional().describe("Component value"),
position: z.object({
@@ -38,14 +39,41 @@ export function registerSchematicTools(server: McpServer, callKicadScript: Funct
y: z.number()
}).optional().describe("Position on schematic"),
},
async (args: any) => {
const result = await callKicadScript("add_schematic_component", args);
return {
content: [{
type: "text",
text: JSON.stringify(result, null, 2)
}]
async (args: { schematicPath: string; symbol: string; reference: string; value?: string; position?: { x: number; y: number } }) => {
// Transform to what Python backend expects
const [library, symbolName] = args.symbol.includes(':')
? args.symbol.split(':')
: ['Device', args.symbol];
const transformed = {
schematicPath: args.schematicPath,
component: {
library,
type: symbolName,
reference: args.reference,
value: args.value,
// Python expects flat x, y not nested position
x: args.position?.x ?? 0,
y: args.position?.y ?? 0
}
};
const result = await callKicadScript("add_schematic_component", transformed);
if (result.success) {
return {
content: [{
type: "text",
text: `Successfully added ${args.reference} (${args.symbol}) to schematic`
}]
};
} else {
return {
content: [{
type: "text",
text: `Failed to add component: ${result.message || JSON.stringify(result)}`
}]
};
}
}
);