diff --git a/src/index.ts b/src/index.ts index d7b37c5..6f31054 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,13 +107,12 @@ async function shutdownServer(server: KiCADMcpServer) { } } -// Run the main function if this file is executed directly -if (import.meta.url === `file://${process.argv[1]}`) { - main().catch((error) => { - logger.error(`Unhandled error in main: ${error}`); - process.exit(1); - }); -} +// Run the main function - always run when imported as module entry point +// The import.meta.url check was failing on Windows due to path separators +main().catch((error) => { + console.error(`Unhandled error in main: ${error}`); + process.exit(1); +}); // For testing and programmatic usage export { KiCADMcpServer }; diff --git a/src/logger.ts b/src/logger.ts index d597e12..6a22d8b 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -86,21 +86,10 @@ class Logger { private log(level: LogLevel, message: string): void { const timestamp = new Date().toISOString(); const formattedMessage = `[${timestamp}] [${level.toUpperCase()}] ${message}`; - - // Log to console - switch (level) { - case 'error': - console.error(formattedMessage); - break; - case 'warn': - console.warn(formattedMessage); - break; - case 'info': - case 'debug': - default: - console.log(formattedMessage); - break; - } + + // Log to console.error (stderr) only - stdout is reserved for MCP protocol + // All log levels go to stderr to avoid corrupting STDIO MCP transport + console.error(formattedMessage); // Log to file try {