Skip to content

io.modelcontextprotocol.client.transport.StdioClientTransport#closeGracefully #496

@meng1995vip

Description

@meng1995vip

Bug description
When npx is launched on Windows, a related subprocess is initiated. When using the io.modelcontextprotocol.client.transport.StdioClientTransport#closeGracefully method to close, this.process.destroy() will only terminate the current process, but the subprocess cannot be closed, resulting in the main method not being able to end normally. Therefore, the taskkill pid /F /T command needs to be used to terminate it.

Environment
jdk 17
mcp 0.12.0-SNAPSHOT
windows 11
Steps to reproduce
StdioClientTransport stdioClientTransport = new StdioClientTransport(ServerParameters.builder("D:\dev\nodejs\npx.cmd").args(Arrays.asList("-y","@wopal/mcp-server-hotnews")).build());
McpSyncClient mcpClient = McpClient.sync(stdioClientTransport)
.requestTimeout(Duration.ofSeconds(20L))
.capabilities(McpSchema.ClientCapabilities.builder()
.roots(true)
.sampling()
.build())
.build();
mcpClient.initialize();
McpSchema.ListToolsResult listToolsResult = mcpClient.listTools();
List<McpSchema.Tool> tools = listToolsResult.tools();
System.out.println(tools.get(0).name());
mcpClient.closeGracefully();

Expected behavior
Close the child processes simultaneously

Minimal Complete Reproducible example
StdioClientTransport stdioClientTransport = new StdioClientTransport(ServerParameters.builder("D:\dev\nodejs\npx.cmd").args(Arrays.asList("-y","@wopal/mcp-server-hotnews")).build());
McpSyncClient mcpClient = McpClient.sync(stdioClientTransport)
.requestTimeout(Duration.ofSeconds(20L))
.capabilities(McpSchema.ClientCapabilities.builder()
.roots(true)
.sampling()
.build())
.build();
mcpClient.initialize();
McpSchema.ListToolsResult listToolsResult = mcpClient.listTools();
List<McpSchema.Tool> tools = listToolsResult.tools();
System.out.println(tools.get(0).name());
mcpClient.closeGracefully();

Image

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