modelcontextprotocol / modelcontextprotocol/java-sdk

StdioClientTransport should support bounded child process termination

Abierto
#937 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement P2 ready for work
Lenguaje dominante
Java
Estrellas
3.7k
Forks
1.1k
Merge medio
1 d 15 h
PR fusionados (30 d)
9

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en StdioClientTransport.closeGracefully() e inspecciona cómo ServerParameters configura el transporte y cómo se espera a process.onExit(). Añade un tiempo de espera de terminación configurable y, después, ejecuta o añade la prueba de regresión sugerida con un proceso hijo que ignore SIGTERM. Se considera terminado cuando el apagado se completa dentro del margen de tiempo de espera, se termina forzosamente cualquier proceso hijo que siga activo y se limpian los schedulers y sinks.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.