restart_dev_server
Restarts the npm run dev process managed by the npm-dev-mcp server. Use this tool to refresh development environments without manual intervention, ensuring continuous workflow efficiency.
Instructions
npm run devプロセス再起動
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/restartDevServer.ts:17-92 (handler)The primary MCP tool handler for 'restart_dev_server'. It checks current status, calls ProcessManager.restartDevServer(), waits for new status, compares changes, and returns detailed JSON response.export async function restartDevServer(): Promise<string> { try { logger.info('Restarting dev server'); const processManager = ProcessManager.getInstance(); // Get current status before restarting const previousStatus = await processManager.getStatus(); if (!previousStatus) { return JSON.stringify({ success: false, message: 'Dev serverが起動していません。start_dev_serverを使用して開始してください。', restarted: false }); } const previousDirectory = previousStatus.directory; const previousPid = previousStatus.pid; const previousPorts = [...previousStatus.ports]; const previousUptime = Date.now() - previousStatus.startTime.getTime(); // Restart the dev server const newProcess = await processManager.restartDevServer(); // Wait a moment to get updated status await new Promise(resolve => setTimeout(resolve, 3000)); const newStatus = await processManager.getStatus(); const result = { success: true, message: 'Dev serverを正常に再起動しました', restarted: true, previousProcess: { pid: previousPid, directory: previousDirectory, ports: previousPorts, uptime: previousUptime }, newProcess: { pid: newProcess.pid, directory: newProcess.directory, status: newProcess.status, startTime: newProcess.startTime, ports: newStatus?.ports || newProcess.ports } }; if (newProcess.ports.length > 0) { result.message += `\n新しいプロセスのポート: ${newProcess.ports.join(', ')}`; } // Compare ports if they changed const portsChanged = JSON.stringify(previousPorts.sort()) !== JSON.stringify((newStatus?.ports || newProcess.ports).sort()); if (portsChanged) { result.message += `\nポートが変更されました: ${previousPorts.join(', ')} → ${(newStatus?.ports || newProcess.ports).join(', ')}`; } logger.info('Dev server restart completed', { previousPid: previousPid, newPid: newProcess.pid, newPorts: newProcess.ports }); return JSON.stringify(result, null, 2); } catch (error) { logger.error('Failed to restart dev server', { error }); return JSON.stringify({ success: false, message: `Dev serverの再起動に失敗しました: ${error}`, restarted: false, error: String(error) }); } }
- src/tools/restartDevServer.ts:7-15 (schema)Tool schema definition including name, description, and empty input schema (no parameters required).export const restartDevServerSchema: Tool = { name: 'restart_dev_server', description: 'npm run devプロセス再起動', inputSchema: { type: 'object', properties: {}, additionalProperties: false } };
- src/index.ts:177-185 (registration)Registration of the tool handler in the main MCP server switch statement within CallToolRequestSchema handler.case 'restart_dev_server': return { content: [ { type: 'text', text: await restartDevServer(), }, ], };
- src/index.ts:55-65 (registration)Registration of the tool schema in the tools array used for ListToolsRequestSchema.const tools = [ scanProjectDirsSchema, startDevServerSchema, getDevStatusSchema, getDevLogsSchema, stopDevServerSchema, restartDevServerSchema, getHealthStatusSchema, recoverFromStateSchema, autoRecoverSchema, ];
- Core helper method in ProcessManager that performs the actual restart by stopping the current dev server and starting a new one in the same directory.async restartDevServer(): Promise<DevProcess> { this.logger.info('Restarting dev server'); let directory = this.currentProcess?.directory; if (!directory) { const contextManager = ProjectContextManager.getInstance(); if (contextManager.isInitialized()) { directory = contextManager.getContext().rootDirectory; } else { directory = process.cwd(); } } await this.stopDevServer(); // Wait a moment before restarting await new Promise(resolve => setTimeout(resolve, 1000)); return this.startDevServer(directory); }