Skip to main content
Glama
masamunet

npm-dev-mcp

by masamunet

stop_dev_server

Stop npm run dev processes managed by the npm-dev-mcp server. Specify a directory to target specific projects when multiple processes are running.

Instructions

npm run devプロセス停止

Input Schema

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

Implementation Reference

  • The primary handler function for the 'stop_dev_server' MCP tool. It checks for the target process, stops it using ProcessManager, collects log stats, and returns a detailed JSON response.
    export async function stopDevServer(args: { directory?: string }): Promise<string> {
      try {
        const processManager = ProcessManager.getInstance();
    
        // Check if target process exists BEFORE stopping
        const targetProcess = processManager.getProcess(args.directory);
        if (!targetProcess) {
          return JSON.stringify({
            success: false,
            message: '指定されたディレクトリのDev serverは見つかりませんでした(または起動していません)',
            wasRunning: false
          });
        }
    
        logger.info('Stopping dev server', { directory: targetProcess.directory });
    
        const logManager = processManager.getLogManager(targetProcess.directory);
        const finalLogStats = logManager?.getLogStats();
    
        // Stop the dev server
        const stopResult = await processManager.stopDevServer(args.directory);
    
        const result: any = {
          success: stopResult,
          message: stopResult
            ? 'Dev serverを正常に停止しました'
            : 'Dev serverの停止中にエラーが発生しましたが、プロセスは終了した可能性があります',
          wasRunning: true,
          stoppedProcess: {
            pid: targetProcess.pid,
            directory: targetProcess.directory,
            ports: targetProcess.ports
          }
        };
    
        if (finalLogStats) {
          result.finalLogStats = {
            total: finalLogStats.total,
            errors: finalLogStats.errors,
            warnings: finalLogStats.warnings
          };
          if (finalLogStats.errors > 0) {
            result.message += `\n最終ログに${finalLogStats.errors}個のエラーが記録されています`;
          }
        }
    
        return JSON.stringify(result, null, 2);
    
      } catch (error) {
        logger.error('Failed to stop dev server', { error });
        return JSON.stringify({
          success: false,
          message: `Dev serverの停止に失敗しました: ${error}`,
          wasRunning: false,
          error: String(error)
        });
      }
    }
  • Input schema definition for the 'stop_dev_server' tool, defining the optional 'directory' parameter.
    export const stopDevServerSchema: Tool = {
      name: 'stop_dev_server',
      description: 'npm run devプロセス停止',
      inputSchema: {
        type: 'object',
        properties: {
          directory: {
            type: 'string',
            description: '停止対象のディレクトリ(複数起動時に指定。未指定時は唯一のプロセスまたはエラー)'
          }
        },
        additionalProperties: false
      }
    };
  • src/index.ts:167-175 (registration)
    Registration and dispatch of the 'stop_dev_server' tool handler in the main CallToolRequestSchema switch statement.
    case 'stop_dev_server':
      return {
        content: [
          {
            type: 'text',
            text: await stopDevServer(args as { directory?: string }),
          },
        ],
      };
  • Core helper method in ProcessManager that performs the actual process termination (SIGTERM then SIGKILL if needed) and cleanup, called by the tool handler.
    async stopDevServer(directory?: string): Promise<boolean> {
      this.logger.info(`Stopping dev server${directory ? ` for ${directory}` : ''}`);
    
      const targetDirectory = this.resolveTargetDirectory(directory);
      const processData = this.processes.get(targetDirectory);
    
      if (!processData) {
        this.logger.info(`No dev server running for ${targetDirectory}`);
        return true; // Already stopped or not found
      }
    
      try {
        const pid = processData.info.pid;
    
        // Try graceful shutdown first
        if (processData.child) {
          processData.child.kill('SIGTERM');
        } else {
          await killProcess(pid, 'SIGTERM');
        }
    
        // Wait a moment for graceful shutdown
        await new Promise(resolve => setTimeout(resolve, 3000));
    
        // Check if process is still running
        if (await isProcessRunning(pid)) {
          this.logger.warn(`Process ${pid} did not stop gracefully, forcing termination`);
          await killProcess(pid, 'SIGKILL');
        }
    
        await this.cleanupProcess(targetDirectory);
        this.logger.info(`Dev server stopped successfully for ${targetDirectory}`);
        return true;
    
      } catch (error) {
        this.logger.error(`Failed to stop dev server for ${targetDirectory}`, { error });
        await this.cleanupProcess(targetDirectory); // Clean up anyway
        return false;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose important behavioral traits like whether this is destructive (likely yes, but not stated), what happens if no process is running, error conditions, or side effects.

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?

Extremely concise single phrase that communicates the core purpose efficiently. No wasted words or unnecessary elaboration.

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?

For a destructive operation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'stop' entails, what gets terminated, error handling, or return values, leaving significant gaps for agent understanding.

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 already documents the single parameter well. The description adds no parameter information beyond what's in the schema, meeting the baseline for high schema 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 ('stop') and target ('npm run dev process'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'restart_dev_server' or 'auto_recover' that might also affect the dev server process.

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 explicit guidance on when to use this tool versus alternatives like 'restart_dev_server' or 'auto_recover'. The description only states what it does, not when it's appropriate versus other options.

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