modelcontextprotocol / modelcontextprotocol/java-sdk
StdioClientTransport should support bounded child process termination
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
説明
StdioClientTransport starts and manages a child MCP server process. During graceful shutdown, the SDK transport currently calls process.destroy() and waits for process.onExit().
That works when the child process responds to SIGTERM, but it can hang indefinitely if the child process ignores termination or becomes stuck. Downstream, we had to implement a custom McpClientTransport to ensure proxied MCP server processes are always cleaned up when the parent shuts down.
Current behavior
The current shutdown flow is effectively:
if (this.process != null) {
this.process.destroy();
return Mono.fromFuture(process.onExit());
}
There is no configurable timeout and no fallback to destroyForcibly().
Expected behavior
StdioClientTransport.closeGracefully() should support bounded process termination:
- Stop accepting new messages.
- Complete the transport sinks.
- Send graceful termination with
process.destroy(). - Wait up to a configurable timeout.
- If the process is still alive, call
process.destroyForcibly(). - Dispose the transport schedulers.
This guarantees that child MCP server processes do not survive parent shutdown indefinitely.
Proposed fix
Add a configurable process termination timeout to StdioClientTransport, with a sensible default.
Conceptually:
process.destroy();
return Mono.fromFuture(process.onExit())
.timeout(processTerminationTimeout, Mono.defer(() -> {
if (process.isAlive()) {
process.destroyForcibly();
}
return Mono.fromFuture(process.onExit());
}));
This could be exposed through the existing ServerParameters builder or a dedicated StdioClientTransport constructor/builder option.
Suggested regression test
Add a test with a child process that ignores SIGTERM or does not exit promptly.
The test should verify that:
closeGracefully()completes within the configured timeout plus a small buffer.- The child process is no longer alive after
closeGracefully()completes. - The transport schedulers and sinks are cleaned up.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
StdioClientTransport.closeGracefully() から始め、ServerParameters が transport をどのように設定しているか、また process.onExit() がどのように待機されているかを調査します。設定可能な termination timeout を追加し、その後 SIGTERM を無視する child process を使って、提案された regression test を実行するか追加します。完了条件は、shutdown が timeout buffer 内に完了し、残存する child を強制終了し、schedulers と sinks をクリーンアップすることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100