modelcontextprotocol / modelcontextprotocol/java-sdk

StdioClientTransport should support bounded child process termination

Đang mở
#937 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement P2 ready for work
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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:

  1. Stop accepting new messages.
  2. Complete the transport sinks.
  3. Send graceful termination with process.destroy().
  4. Wait up to a configurable timeout.
  5. If the process is still alive, call process.destroyForcibly().
  6. 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:

  1. closeGracefully() completes within the configured timeout plus a small buffer.
  2. The child process is no longer alive after closeGracefully() completes.
  3. The transport schedulers and sinks are cleaned up.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ StdioClientTransport.closeGracefully() và kiểm tra cách ServerParameters cấu hình transport cũng như cách chờ process.onExit(). Thêm một termination timeout có thể cấu hình, sau đó chạy hoặc thêm regression test được đề xuất với một child process bỏ qua SIGTERM. Được coi là hoàn tất khi shutdown hoàn thành trong khoảng đệm của timeout, buộc chấm dứt child còn tồn tại và dọn dẹp các scheduler cùng sink.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.