Skip to main content
Glama

m9k_restart

Restart the MCP server to load fresh code after building, enabling automatic reconnection with updated builds.

Instructions

Restart the MCP server. Use after npm run build to load fresh code. The server disconnects; next MCP call auto-reconnects with the new build.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoUse SIGKILL instead of SIGTERM (for stuck processes)

Implementation Reference

  • Registration and implementation of the 'm9k_restart' tool, which schedules a process termination (SIGTERM or SIGKILL) to allow for server restart.
    server.registerTool(
      'm9k_restart',
      {
        description:
          'Restart the MCP server. Use after npm run build to load fresh code. ' +
          'The server disconnects; next MCP call auto-reconnects with the new build.',
        inputSchema: {
          force: z
            .boolean()
            .optional()
            .default(false)
            .describe('Use SIGKILL instead of SIGTERM (for stuck processes)'),
        },
        annotations: {
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ force }) => {
        // Detect daemon vs local mode
        let mode: 'daemon' | 'local' = 'local';
        try {
          const pidStr = fs.readFileSync(DAEMON_PID_PATH, 'utf8').trim();
          if (parseInt(pidStr, 10) === process.pid) {
            mode = 'daemon';
          }
        } catch {
          // No PID file → local mode
        }
    
        const signal = force ? 'SIGKILL' : 'SIGTERM';
    
        // Schedule kill after 200ms to let the MCP response flush
        setTimeout(() => {
          process.kill(process.pid, signal);
        }, 200);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                restarting: true,
                mode,
                graceful: !force,
              }),
            },
          ],
        };
      },
    );

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/louis49/melchizedek'

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