Skip to content

McpServer Endpoint resources never disposed once MCP client connects #766

@slomangino123

Description

@slomangino123

Describe the bug
It seems as though once my MCP Client establishes a connection with the MCP Server. I see these three logs repeating every ~5 minutes until the instance running the MCP Server runs out of memory because some resources are never being released.

To Reproduce
Steps to reproduce the behavior:

var builder = WebApplication.CreateBuilder(args);

builder
    .Services
    .AddMcpServer()
    .WithHttpTransport(options =>
        options.IdleTimeout = TimeSpan.FromMinutes(30)
    )
    .WithToolsFromAssembly(Assembly.GetAssembly(typeof(ReverseStringTool)));

...

var app = builder.Build();

app.MapMcp();

Expected behavior
I would expect that once sessions are closed, their respective resources are released

Logs

LogMessage SourceContext RequestPath Timestamp
{EndpointName} shut down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:47:54.2048221Z
{EndpointName} shutting down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:47:54.2047999Z
{EndpointName} message processing canceled. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:47:54.2044897Z
{EndpointName} shut down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:42:43.0598339Z
{EndpointName} shutting down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:42:43.0598079Z
{EndpointName} message processing canceled. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:42:43.0595247Z
{EndpointName} shut down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:37:39.5033921Z
{EndpointName} shutting down. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:37:39.5033670Z
{EndpointName} message processing canceled. ModelContextProtocol.Server.McpServer /sse 2025-09-12T18:37:39.5030414Z

Additional context
Using langchainjs/mcp-adapters as an MCP client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions