get_dev_logs
Retrieve npm run dev logs for monitoring and debugging purposes, with configurable line count up to 1000. Part of the npm-dev-mcp server managing npm processes and logs automatically.
Instructions
npm run devのログ取得
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lines | No | 取得行数(デフォルト:50) |
Implementation Reference
- src/tools/getDevLogs.ts:24-98 (handler)The main handler function that gets dev server logs using ProcessManager, formats them with timestamps and stats, and returns structured JSON response.export async function getDevLogs(args: { lines?: number }): Promise<string> { try { const requestedLines = args.lines || 50; logger.debug(`Getting dev server logs`, { lines: requestedLines }); const processManager = ProcessManager.getInstance(); const status = await processManager.getStatus(); if (!status) { return JSON.stringify({ success: false, message: 'Dev serverが起動していません。ログを取得できません。', logs: [] }); } const logManager = processManager.getLogManager(); const logs = await logManager.getLogs(requestedLines); // Format logs for better readability const formattedLogs = logs.map(log => ({ timestamp: log.timestamp.toISOString(), level: log.level, source: log.source, message: log.message })); const logStats = logManager.getLogStats(); const result = { success: true, message: `${logs.length}行のログを取得しました`, logs: formattedLogs, statistics: { totalLogs: logStats.total, errors: logStats.errors, warnings: logStats.warnings, info: logStats.info, requested: requestedLines, returned: logs.length }, process: { pid: status.pid, directory: status.directory, status: status.status, startTime: status.startTime } }; if (logStats.errors > 0) { result.message += `\n⚠️ ${logStats.errors}個のエラーが含まれています`; } if (logStats.warnings > 0) { result.message += `\n警告: ${logStats.warnings}個の警告が含まれています`; } logger.debug('Dev server logs retrieved', { logsCount: logs.length, errors: logStats.errors, warnings: logStats.warnings }); return JSON.stringify(result, null, 2); } catch (error) { logger.error('Failed to get dev server logs', { error }); return JSON.stringify({ success: false, message: `ログ取得に失敗しました: ${error}`, logs: [], error: String(error) }); } }
- src/tools/getDevLogs.ts:7-22 (schema)Tool schema defining the input schema with optional 'lines' parameter (1-1000, default 50).export const getDevLogsSchema: Tool = { name: 'get_dev_logs', description: 'npm run devのログ取得', inputSchema: { type: 'object', properties: { lines: { type: 'number', description: '取得行数(デフォルト:50)', minimum: 1, maximum: 1000 } }, additionalProperties: false } };
- src/index.ts:157-165 (registration)Registration of the tool handler in the main CallToolRequestSchema switch statement, invoking getDevLogs with arguments.case 'get_dev_logs': return { content: [ { type: 'text', text: await getDevLogs(args as { lines?: number }), }, ], };
- src/index.ts:55-65 (registration)Registration of the tool schema in the tools array used for ListToolsRequestHandler.const tools = [ scanProjectDirsSchema, startDevServerSchema, getDevStatusSchema, getDevLogsSchema, stopDevServerSchema, restartDevServerSchema, getHealthStatusSchema, recoverFromStateSchema, autoRecoverSchema, ];
- src/initialization/MCPServerInitializer.ts:13-23 (registration)Dependency registration specifying that get_dev_logs requires 'stateManager' service.export const SERVICE_DEPENDENCIES = { 'scan_project_dirs': ['projectContext'], 'start_dev_server': ['stateManager'], 'get_dev_status': ['stateManager'], 'get_dev_logs': ['stateManager'], 'stop_dev_server': ['stateManager'], 'restart_dev_server': ['stateManager'], 'get_health_status': ['healthChecker'], 'recover_from_state': ['stateManager'], 'auto_recover': ['stateManager', 'healthChecker'] } as const;