Skip to content

Shutting down console application which uses mcpclient does not kill the stdio process #155

@StefH

Description

@StefH

Describe the bug
Shutting down console application with CTRL-C or just killing it and uses mcpclient does not kill the stdio process

To Reproduce
Install a dotnet tool mcpserver:

dotnet tool install --version 0.0.1-preview-02 --global mcpserver.everything.stdio

And this C# code in a console app:

using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Client;
using ModelContextProtocol.Configuration;
using ModelContextProtocol.Protocol.Transport;

var config = new McpServerConfig
{
    Id = "everything",
    Name = "everything",
    TransportType = TransportTypes.StdIo,
    TransportOptions = new Dictionary<string, string>
    {
        { "command", "mcpserver.everything.stdio" }
    }
};

var options = new McpClientOptions
{
    ClientInfo = new() { Name = "everything-client", Version = "1.0.0" }
};

var client = await McpClientFactory.CreateAsync(config, options, null, LoggerFactory.Create(c => c.AddConsole()));
_ = await client.ListToolsAsync();

See also https://github.com/StefH/mcptest

Expected behavior
When the application stops, is killed (using close) or using CTRL-C, it's expected that the spawned child process (the stdio server) is also killed.

This is not the case, using when manually calling DisposeAsync on the McpClient, the process is killed.

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