Skip to content

Asp.net core server shutdown - disconnect or notify connected MCP clients #825

@codeape2

Description

@codeape2

I am using the ASP.NET Core extensions for the MCP C# SDK to implement tools and resources in an existing web application - works great!

In development, I sometimes frequently restart the ASP.NET Core process. Before adding the MCP server to the application, an application restart was instant.

If I have a MCP test client connected to the server (for instance npx @modelcontextprotocol/inspector) then shutting down the asp.net core process takes some time (~15 seconds or so). I assume this is because the connected MCP client has a streaming HTTP connection open to the server, and this somehow interferes with the normal shut-down process.

Questions:

  • Is there a way to hook in to the asp.net shutdown process and disconnect the MCP clients?
  • Does the MCP protocol define how this should be handled? (i.e. a way for the server to tell the clients you-will-be-disconnected-and-can-likely-reconnect-in-five-seconds)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions