Skip to content

Stdio MCP Server sending messages to stderr when receiving SIGTERM breaks the inspector #416

@Areo-Joe

Description

@Areo-Joe

Describe the bug
If the inspector connects to a STDIO MCP server, which sends messages to stderr when receiving SIGTERM, it will break when disconnecting.
The STDIO MCP server sends messages to stderr, then the inspector sends it through the webAppTrarnsport, which is already closed by now, which leads to an error that breaks the inspector and prevent further connections.

To Reproduce
Steps to reproduce the behavior:

  1. Write a STDIO MCP server that sends messages to stderr when receiving SIGTERM.
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

// Define a simple calculator tool
const CalculatorToolSchema = {
  operation: z.enum(["add", "subtract", "multiply", "divide"]),
  a: z.number(),
  b: z.number(),
};

const createServer = () => {
  // Create an MCP server instance
  const server = new McpServer({
    name: "stateless-mcp-server",
    version: "1.0.0",
  });
}

// ...register tools and anything

const server = createServer();
const transport = new StdioServerTransport();
await server.connect(transport);

process.on('SIGINT', () => {
  console.error("SIGINT")
  process.exit()
})

process.on('SIGTERM', () => {
  console.error("SIGTERM")
  process.exit()
})

process.on('SIGHUP', () => {
  console.error("SIGHUP")
  process.exit()
})
  1. Run the inspector and connect to it, then disconnect, then connect again, and the inspect cannot go on.
Image

Expected behavior
The error is true that the transport is closed and should not send though it, but it is not that important and should not block further interactions with the inspector. Maybe logging it is enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions