modelcontextprotocol / modelcontextprotocol/java-sdk
io.modelcontextprotocol.client.transport.StdioClientTransport#closeGracefully
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 1.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 9
Description
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();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at io.modelcontextprotocol.client.transport.StdioClientTransport#closeGracefully and reproduce the Windows npx.cmd example from the issue. Investigate how the launched process and its child processes are terminated; done means closing the client also ends the subprocess tree and the main method can return normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, node.js
- Domain
- backend, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100