Skip to content

Unable to cleanly shutdown/close MCP Server #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidfiala opened this issue Jan 1, 2025 · 0 comments · Fixed by #115
Closed

Unable to cleanly shutdown/close MCP Server #113

davidfiala opened this issue Jan 1, 2025 · 0 comments · Fixed by #115
Labels
bug Something isn't working

Comments

@davidfiala
Copy link

davidfiala commented Jan 1, 2025

It appears that the most basic version of starting/stopping an MCP server leaves a handle or reference open which prevents node from exiting.

I've observed that if I process.stdin.destroy() then I can unblock MCP and get the whatever handles it is using to close.

Versions:
node: v23.2.0
@modelcontextprotocol/sdk: 1.0.4

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server(
  {
    name: 'foo/bar',
    version: '0.0.1',
  },
  {
    capabilities: {
      resources: {},
      tools: {},
    },
  },
);

async function main() {
  const transport = new StdioServerTransport();
  server.connect(transport);
  await server.close();
  await transport.close();

  console.warn('Will I hang forever here? Unfortunately, yes.');

  // Destroying stdin prevents the hang, but it's ugly:
  // process.stdin.destroy();
}

main();

The uncleaned handles appear to be added in server.connect(transport); since it will exit cleanly if I comment that line.

@davidfiala davidfiala added the bug Something isn't working label Jan 1, 2025
@jspahrsummers jspahrsummers linked a pull request Jan 3, 2025 that will close this issue
9 tasks
Pizzaface pushed a commit to RewstApp/mcp-inspector that referenced this issue May 2, 2025
…re/completions

Implement MCP Completion Support in Prompts and Resources Tabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant