Skip to main content
Glama
masamunet

npm-dev-mcp

by masamunet

restart_dev_server

Restart the npm run dev process to apply changes or resolve issues during development. Specify a directory when multiple processes are running.

Instructions

npm run devプロセス再起動

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryNo再起動対象のディレクトリ(複数起動時に指定。未指定時は唯一のプロセスまたはエラー)

Implementation Reference

  • The primary handler function for the 'restart_dev_server' MCP tool. It checks for existing processes, calls ProcessManager to restart, gathers status info, and returns a formatted JSON response with success/error details.
    export async function restartDevServer(args: { directory?: string } = {}): Promise<string> {
      try {
        const processManager = ProcessManager.getInstance();
    
        // Check if target process exists BEFORE restarting
        const targetProcess = processManager.getProcess(args.directory);
        const directoryToRestart = targetProcess?.directory || args.directory;
    
        if (!targetProcess && !args.directory) {
          return JSON.stringify({
            success: false,
            message: 'Dev serverが起動していません(またはディレクトリが指定されていません)。start_dev_serverを使用して開始してください。',
            restarted: false
          });
        }
    
        logger.info('Restarting dev server', { directory: directoryToRestart });
    
        const previousDirectory = targetProcess?.directory || args.directory || 'unknown';
        const previousPid = targetProcess?.pid;
        const previousPorts = targetProcess ? [...targetProcess.ports] : [];
        const previousUptime = targetProcess ? Date.now() - targetProcess.startTime.getTime() : 0;
    
        // Restart the dev server
        const newProcess = await processManager.restartDevServer(args.directory);
    
        // Wait a moment to get updated status
        await new Promise(resolve => setTimeout(resolve, 3000));
    
        // Get new status from correct process
        const allProcesses = await processManager.getStatus();
        const newStatus = allProcesses.find(p => p.directory === newProcess.directory);
    
        const result: any = {
          success: true,
          message: 'Dev serverを正常に再起動しました',
          restarted: true,
          newProcess: {
            pid: newProcess.pid,
            directory: newProcess.directory,
            status: newProcess.status,
            startTime: newProcess.startTime,
            ports: newStatus?.ports || newProcess.ports
          }
        };
    
        if (previousPid) {
          result.previousProcess = {
            pid: previousPid,
            directory: previousDirectory,
            ports: previousPorts,
            uptime: previousUptime
          };
        }
    
        if (newProcess.ports.length > 0) {
          result.message += `\n新しいプロセスのポート: ${newProcess.ports.join(', ')}`;
        }
    
        // Compare ports if they changed
        const currentPorts = newStatus?.ports || newProcess.ports;
        const portsChanged = JSON.stringify(previousPorts.sort()) !== JSON.stringify([...currentPorts].sort());
        if (portsChanged && previousPorts.length > 0) {
          result.message += `\nポートが変更されました: ${previousPorts.join(', ')} → ${currentPorts.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)
        });
      }
    }
  • The input schema definition for the 'restart_dev_server' tool, defining the optional 'directory' parameter.
    export const restartDevServerSchema: Tool = {
      name: 'restart_dev_server',
      description: 'npm run devプロセス再起動',
      inputSchema: {
        type: 'object',
        properties: {
          directory: {
            type: 'string',
            description: '再起動対象のディレクトリ(複数起動時に指定。未指定時は唯一のプロセスまたはエラー)'
          }
        },
        additionalProperties: false
      }
    };
  • src/index.ts:177-185 (registration)
    The registration and dispatch point in the main MCP server handler (CallToolRequestSchema), which calls the tool handler function.
    case 'restart_dev_server':
      return {
        content: [
          {
            type: 'text',
            text: await restartDevServer(args as { directory?: string }),
          },
        ],
      };
  • src/index.ts:55-65 (registration)
    The tools array registration where restartDevServerSchema is included for ListToolsRequestSchema.
    const tools = [
      scanProjectDirsSchema,
      startDevServerSchema,
      getDevStatusSchema,
      getDevLogsSchema,
      stopDevServerSchema,
      restartDevServerSchema,
      getHealthStatusSchema,
      recoverFromStateSchema,
      autoRecoverSchema,
    ];
  • Supporting helper method in ProcessManager that performs the actual stop + start logic for restarting the dev server process.
    async restartDevServer(directory?: string): Promise<DevProcess> {
      this.logger.info(`Restarting dev server${directory ? ` for ${directory}` : ''}`);
    
      const targetDirectory = this.resolveTargetDirectory(directory);
    
      await this.stopDevServer(targetDirectory);
    
      // Wait a moment before restarting
      await new Promise(resolve => setTimeout(resolve, 1000));
    
      return this.startDevServer(targetDirectory);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the action. It doesn't disclose behavioral traits such as whether it requires specific permissions, how it handles errors, or if it affects other processes. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste, clearly front-loading the core action. It's appropriately sized for the tool's simplicity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a mutation tool with behavioral gaps, the description is incomplete. It lacks details on outcomes, error handling, or interaction with sibling tools, making it inadequate for safe agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents the single parameter. The description adds no additional meaning beyond what the schema provides, such as examples or edge cases, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('restart') and target ('npm run dev process'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'start_dev_server' or 'stop_dev_server' beyond the restart action, missing explicit sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'start_dev_server' or 'stop_dev_server'. The description only states what it does, without context for selection among siblings or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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