chore: set up pre-commit framework with general hooks

Add .pre-commit-config.yaml with pre-commit-hooks v5.0.0 (trailing
whitespace, end-of-file fixer, yaml/json checks, large file guard,
merge conflict detection). Add minimal pyproject.toml. Auto-fix
trailing whitespace and missing end-of-file newlines across the
codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-03-29 12:58:36 +01:00
parent 41ae1ba82c
commit eee5bfb9ed
26 changed files with 322 additions and 385 deletions

View File

@@ -1,6 +1,6 @@
/**
* Board resources for KiCAD MCP server
*
*
* These resources provide information about the PCB board
* to the LLM, enabling better context-aware assistance.
*/
@@ -15,7 +15,7 @@ type CommandFunction = (command: string, params: Record<string, unknown>) => Pro
/**
* Register board resources with the MCP server
*
*
* @param server MCP server instance
* @param callKicadScript Function to call KiCAD script commands
*/
@@ -31,7 +31,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
async (uri) => {
logger.debug('Retrieving board information');
const result = await callKicadScript("get_board_info", {});
if (!result.success) {
logger.error(`Failed to retrieve board information: ${result.errorDetails}`);
return {
@@ -45,7 +45,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
logger.debug('Successfully retrieved board information');
return {
contents: [{
@@ -66,7 +66,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
async (uri) => {
logger.debug('Retrieving layer list');
const result = await callKicadScript("get_layer_list", {});
if (!result.success) {
logger.error(`Failed to retrieve layer list: ${result.errorDetails}`);
return {
@@ -80,7 +80,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
logger.debug(`Successfully retrieved ${result.layers?.length || 0} layers`);
return {
contents: [{
@@ -107,10 +107,10 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}),
async (uri, params) => {
const unit = params.unit || 'mm';
logger.debug(`Retrieving board extents in ${unit}`);
const result = await callKicadScript("get_board_extents", { unit });
if (!result.success) {
logger.error(`Failed to retrieve board extents: ${result.errorDetails}`);
return {
@@ -124,7 +124,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
logger.debug('Successfully retrieved board extents');
return {
contents: [{
@@ -156,7 +156,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
const height = params.height ? parseInt(params.height as string) : undefined;
// Handle layers parameter - could be string or array
const layers = typeof params.layers === 'string' ? params.layers.split(',') : params.layers;
logger.debug('Retrieving 2D board view');
const result = await callKicadScript("get_board_2d_view", {
layers,
@@ -164,7 +164,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
height,
format
});
if (!result.success) {
logger.error(`Failed to retrieve 2D board view: ${result.errorDetails}`);
return {
@@ -178,9 +178,9 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
logger.debug('Successfully retrieved 2D board view');
if (format === 'svg') {
return {
contents: [{
@@ -219,14 +219,14 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
const angle = params.angle || 'isometric';
const width = params.width ? parseInt(params.width as string) : undefined;
const height = params.height ? parseInt(params.height as string) : undefined;
logger.debug(`Retrieving 3D board view from ${angle} angle`);
const result = await callKicadScript("get_board_3d_view", {
width,
height,
angle
});
if (!result.success) {
logger.error(`Failed to retrieve 3D board view: ${result.errorDetails}`);
return {
@@ -240,7 +240,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
logger.debug('Successfully retrieved 3D board view');
return {
contents: [{
@@ -260,7 +260,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
"kicad://board/statistics",
async (uri) => {
logger.debug('Generating board statistics');
// Get board info
const boardResult = await callKicadScript("get_board_info", {});
if (!boardResult.success) {
@@ -276,7 +276,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
// Get component list
const componentsResult = await callKicadScript("get_component_list", {});
if (!componentsResult.success) {
@@ -292,7 +292,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
// Get nets list
const netsResult = await callKicadScript("get_nets_list", {});
if (!netsResult.success) {
@@ -308,7 +308,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
}]
};
}
// Combine all information into statistics
const statistics = {
board: {
@@ -324,7 +324,7 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
count: netsResult.nets?.length || 0
}
};
logger.debug('Successfully generated board statistics');
return {
contents: [{
@@ -344,11 +344,11 @@ export function registerBoardResources(server: McpServer, callKicadScript: Comma
*/
function countComponentTypes(components: any[]): Record<string, number> {
const typeCounts: Record<string, number> = {};
for (const component of components) {
const type = component.value?.split(' ')[0] || 'Unknown';
typeCounts[type] = (typeCounts[type] || 0) + 1;
}
return typeCounts;
}

View File

@@ -1,6 +1,6 @@
/**
* Component resources for KiCAD MCP server
*
*
* These resources provide information about components on the PCB
* to the LLM, enabling better context-aware assistance.
*/
@@ -13,7 +13,7 @@ type CommandFunction = (command: string, params: Record<string, unknown>) => Pro
/**
* Register component resources with the MCP server
*
*
* @param server MCP server instance
* @param callKicadScript Function to call KiCAD script commands
*/
@@ -29,7 +29,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
async (uri) => {
logger.debug('Retrieving component list');
const result = await callKicadScript("get_component_list", {});
if (!result.success) {
logger.error(`Failed to retrieve component list: ${result.errorDetails}`);
return {
@@ -43,7 +43,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug(`Successfully retrieved ${result.components?.length || 0} components`);
return {
contents: [{
@@ -69,7 +69,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
const result = await callKicadScript("get_component_properties", {
reference
});
if (!result.success) {
logger.error(`Failed to retrieve component details: ${result.errorDetails}`);
return {
@@ -83,7 +83,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug(`Successfully retrieved details for component: ${reference}`);
return {
contents: [{
@@ -109,7 +109,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
const result = await callKicadScript("get_component_connections", {
reference
});
if (!result.success) {
logger.error(`Failed to retrieve component connections: ${result.errorDetails}`);
return {
@@ -123,7 +123,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug(`Successfully retrieved connections for component: ${reference}`);
return {
contents: [{
@@ -144,7 +144,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
async (uri) => {
logger.debug('Retrieving component placement information');
const result = await callKicadScript("get_component_placement", {});
if (!result.success) {
logger.error(`Failed to retrieve component placement: ${result.errorDetails}`);
return {
@@ -158,7 +158,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug('Successfully retrieved component placement information');
return {
contents: [{
@@ -179,7 +179,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
async (uri) => {
logger.debug('Retrieving component groups');
const result = await callKicadScript("get_component_groups", {});
if (!result.success) {
logger.error(`Failed to retrieve component groups: ${result.errorDetails}`);
return {
@@ -193,7 +193,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug(`Successfully retrieved ${result.groups?.length || 0} component groups`);
return {
contents: [{
@@ -219,7 +219,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
const result = await callKicadScript("get_component_visualization", {
reference
});
if (!result.success) {
logger.error(`Failed to generate component visualization: ${result.errorDetails}`);
return {
@@ -233,7 +233,7 @@ export function registerComponentResources(server: McpServer, callKicadScript: C
}]
};
}
logger.debug(`Successfully generated visualization for component: ${reference}`);
return {
contents: [{

View File

@@ -1,6 +1,6 @@
/**
* Resources index for KiCAD MCP server
*
*
* Exports all resource registration functions
*/

View File

@@ -1,6 +1,6 @@
/**
* Library resources for KiCAD MCP server
*
*
* These resources provide information about KiCAD component libraries
* to the LLM, enabling better context-aware assistance.
*/
@@ -14,7 +14,7 @@ type CommandFunction = (command: string, params: Record<string, unknown>) => Pro
/**
* Register library resources with the MCP server
*
*
* @param server MCP server instance
* @param callKicadScript Function to call KiCAD script commands
*/
@@ -39,7 +39,7 @@ export function registerLibraryResources(server: McpServer, callKicadScript: Com
const limit = Number(params.limit) || undefined;
logger.debug(`Retrieving component library${filter ? ` with filter: ${filter}` : ''}${library ? ` from library: ${library}` : ''}`);
const result = await callKicadScript("get_component_library", {
filter,
library,
@@ -117,7 +117,7 @@ export function registerLibraryResources(server: McpServer, callKicadScript: Com
async (uri, params) => {
const { componentId, library } = params;
logger.debug(`Retrieving details for component: ${componentId}${library ? ` from library: ${library}` : ''}`);
const result = await callKicadScript("get_component_details", {
componentId,
library
@@ -159,7 +159,7 @@ export function registerLibraryResources(server: McpServer, callKicadScript: Com
async (uri, params) => {
const { componentId, footprint } = params;
logger.debug(`Retrieving footprint for component: ${componentId}${footprint ? ` (${footprint})` : ''}`);
const result = await callKicadScript("get_component_footprint", {
componentId,
footprint
@@ -201,7 +201,7 @@ export function registerLibraryResources(server: McpServer, callKicadScript: Com
async (uri, params) => {
const { componentId } = params;
logger.debug(`Retrieving symbol for component: ${componentId}`);
const result = await callKicadScript("get_component_symbol", {
componentId
});
@@ -255,7 +255,7 @@ export function registerLibraryResources(server: McpServer, callKicadScript: Com
async (uri, params) => {
const { componentId, footprint } = params;
logger.debug(`Retrieving 3D model for component: ${componentId}${footprint ? ` (${footprint})` : ''}`);
const result = await callKicadScript("get_component_3d_model", {
componentId,
footprint

View File

@@ -1,6 +1,6 @@
/**
* Project resources for KiCAD MCP server
*
*
* These resources provide information about the KiCAD project
* to the LLM, enabling better context-aware assistance.
*/
@@ -13,7 +13,7 @@ type CommandFunction = (command: string, params: Record<string, unknown>) => Pro
/**
* Register project resources with the MCP server
*
*
* @param server MCP server instance
* @param callKicadScript Function to call KiCAD script commands
*/
@@ -29,7 +29,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
async (uri) => {
logger.debug('Retrieving project information');
const result = await callKicadScript("get_project_info", {});
if (!result.success) {
logger.error(`Failed to retrieve project information: ${result.errorDetails}`);
return {
@@ -43,7 +43,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
logger.debug('Successfully retrieved project information');
return {
contents: [{
@@ -64,7 +64,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
async (uri) => {
logger.debug('Retrieving project properties');
const result = await callKicadScript("get_project_properties", {});
if (!result.success) {
logger.error(`Failed to retrieve project properties: ${result.errorDetails}`);
return {
@@ -78,7 +78,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
logger.debug('Successfully retrieved project properties');
return {
contents: [{
@@ -99,7 +99,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
async (uri) => {
logger.debug('Retrieving project files');
const result = await callKicadScript("get_project_files", {});
if (!result.success) {
logger.error(`Failed to retrieve project files: ${result.errorDetails}`);
return {
@@ -113,7 +113,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
logger.debug(`Successfully retrieved ${result.files?.length || 0} project files`);
return {
contents: [{
@@ -134,7 +134,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
async (uri) => {
logger.debug('Retrieving project status');
const result = await callKicadScript("get_project_status", {});
if (!result.success) {
logger.error(`Failed to retrieve project status: ${result.errorDetails}`);
return {
@@ -148,7 +148,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
logger.debug('Successfully retrieved project status');
return {
contents: [{
@@ -168,7 +168,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
"kicad://project/summary",
async (uri) => {
logger.debug('Generating project summary');
// Get project info
const infoResult = await callKicadScript("get_project_info", {});
if (!infoResult.success) {
@@ -184,7 +184,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
// Get board info
const boardResult = await callKicadScript("get_board_info", {});
if (!boardResult.success) {
@@ -200,7 +200,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
// Get component list
const componentsResult = await callKicadScript("get_component_list", {});
if (!componentsResult.success) {
@@ -216,7 +216,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
}]
};
}
// Combine all information into a summary
const summary = {
project: infoResult.project,
@@ -230,7 +230,7 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
types: countComponentTypes(componentsResult.components || [])
}
};
logger.debug('Successfully generated project summary');
return {
contents: [{
@@ -250,11 +250,11 @@ export function registerProjectResources(server: McpServer, callKicadScript: Com
*/
function countComponentTypes(components: any[]): Record<string, number> {
const typeCounts: Record<string, number> = {};
for (const component of components) {
const type = component.value?.split(' ')[0] || 'Unknown';
typeCounts[type] = (typeCounts[type] || 0) + 1;
}
return typeCounts;
}