stop_dev_server
Stop the npm run dev process managed by npm-dev-mcp server to halt background project execution, free up resources, and manage development environments effectively.
Instructions
npm run devプロセス停止
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/stopDevServer.ts:17-86 (handler)The primary MCP tool handler for 'stop_dev_server'. Orchestrates stopping the dev server via ProcessManager, gathers status and logs, and returns a detailed JSON response.export async function stopDevServer(): Promise<string> { try { logger.info('Stopping dev server'); const processManager = ProcessManager.getInstance(); // Get current status before stopping const currentStatus = await processManager.getStatus(); if (!currentStatus) { return JSON.stringify({ success: true, message: 'Dev serverは既に停止しています', wasRunning: false }); } const logManager = processManager.getLogManager(); const finalLogStats = logManager.getLogStats(); // Stop the dev server const stopResult = await processManager.stopDevServer(); const result = { success: stopResult, message: stopResult ? 'Dev serverを正常に停止しました' : 'Dev serverの停止中にエラーが発生しましたが、プロセスは終了した可能性があります', wasRunning: true, stoppedProcess: { pid: currentStatus.pid, directory: currentStatus.directory, status: currentStatus.status, startTime: currentStatus.startTime, uptime: Date.now() - currentStatus.startTime.getTime(), ports: currentStatus.ports }, finalLogStats: { total: finalLogStats.total, errors: finalLogStats.errors, warnings: finalLogStats.warnings, info: finalLogStats.info } }; if (currentStatus.ports.length > 0) { result.message += `\nポート ${currentStatus.ports.join(', ')} が解放されました`; } if (finalLogStats.errors > 0) { result.message += `\n最終ログに${finalLogStats.errors}個のエラーが記録されています`; } logger.info('Dev server stop completed', { success: stopResult, pid: currentStatus.pid }); return JSON.stringify(result, null, 2); } catch (error) { logger.error('Failed to stop dev server', { error }); return JSON.stringify({ success: false, message: `Dev serverの停止に失敗しました: ${error}`, wasRunning: false, error: String(error) }); } }
- src/tools/stopDevServer.ts:7-15 (schema)Input schema definition for the 'stop_dev_server' tool, specifying no required input parameters.export const stopDevServerSchema: Tool = { name: 'stop_dev_server', description: 'npm run devプロセス停止', inputSchema: { type: 'object', properties: {}, additionalProperties: false } };
- src/index.ts:55-65 (registration)Registration of the tool schema in the list of available tools provided to the MCP server.const tools = [ scanProjectDirsSchema, startDevServerSchema, getDevStatusSchema, getDevLogsSchema, stopDevServerSchema, restartDevServerSchema, getHealthStatusSchema, recoverFromStateSchema, autoRecoverSchema, ];
- src/index.ts:167-175 (registration)Dispatch handler in the MCP server's CallToolRequestSchema that invokes the stopDevServer tool handler.case 'stop_dev_server': return { content: [ { type: 'text', text: await stopDevServer(), }, ], };
- Core implementation in ProcessManager that performs the actual dev server process termination using SIGTERM followed by SIGKILL if necessary.async stopDevServer(): Promise<boolean> { this.logger.info('Stopping dev server'); if (!this.currentProcess) { this.logger.info('No dev server is running'); return true; } try { const pid = this.currentProcess.pid; // Try graceful shutdown first if (this.childProcess) { this.childProcess.kill('SIGTERM'); } else { await killProcess(pid, 'SIGTERM'); } // Wait a moment for graceful shutdown await new Promise(resolve => setTimeout(resolve, 3000)); // Check if process is still running if (await isProcessRunning(pid)) { this.logger.warn('Process did not stop gracefully, forcing termination'); await killProcess(pid, 'SIGKILL'); } await this.cleanup(); this.logger.info('Dev server stopped successfully'); return true; } catch (error) { this.logger.error('Failed to stop dev server', { error }); await this.cleanup(); // Clean up anyway return false; } }