get_dev_logs
Retrieve npm run dev logs to monitor development server output, with options to specify log lines and project directory.
Instructions
npm run devのログ取得
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_dev_logs"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lines | No | 取得行数(デフォルト:50) | |
| directory | No | 対象ディレクトリ(複数起動時に指定) |
Implementation Reference
- src/tools/getDevLogs.ts:28-101 (handler)The main handler function `getDevLogs` that executes the tool logic: retrieves logs from the dev server process using ProcessManager and LogManager, formats them, adds statistics, and returns JSON.
export async function getDevLogs(args: { lines?: number; directory?: string }): Promise<string> { try { const requestedLines = args.lines || 50; const processManager = ProcessManager.getInstance(); // Determine which process to look at const processInfo = processManager.getProcess(args.directory); if (!processInfo) { return JSON.stringify({ success: false, message: 'Dev serverが起動していません(または指定されたディレクトリが見つかりません)', logs: [] }); } const logManager = processManager.getLogManager(processInfo.directory); if (!logManager) { return JSON.stringify({ success: false, message: 'ログマネージャーが見つかりませんでした', logs: [] }); } 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: processInfo.pid, directory: processInfo.directory, status: processInfo.status } }; if (logStats.errors > 0) { result.message += `\n⚠️ ${logStats.errors}個のエラーが含まれています`; } 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-26 (schema)The Tool schema definition `getDevLogsSchema` including name, description, and inputSchema with properties for lines and directory.
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 }, directory: { type: 'string', description: '対象ディレクトリ(複数起動時に指定)' } }, additionalProperties: false } }; - src/index.ts:157-165 (registration)Registration and dispatch of the get_dev_logs handler in the main CallToolRequestSchema switch statement.
case 'get_dev_logs': return { content: [ { type: 'text', text: await getDevLogs(args as { lines?: number; directory?: string }), }, ], }; - src/index.ts:55-65 (registration)Registration of the getDevLogsSchema in the tools array used for ListToolsRequestSchema response.
const tools = [ scanProjectDirsSchema, startDevServerSchema, getDevStatusSchema, getDevLogsSchema, stopDevServerSchema, restartDevServerSchema, getHealthStatusSchema, recoverFromStateSchema, autoRecoverSchema, ]; - src/initialization/MCPServerInitializer.ts:13-23 (registration)Dependency registration for get_dev_logs tool, requiring 'stateManager' service in MCPServerInitializer.
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;