Skip to main content
Glama
masamunet

npm-dev-mcp

by masamunet

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のログ取得

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
linesNo取得行数(デフォルト:50)
directoryNo対象ディレクトリ(複数起動時に指定)

Implementation Reference

  • 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)
        });
      }
    }
  • 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,
    ];
  • 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;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/masamunet/npm-dev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server