Skip to content

MCP STDIO: a clean end of input aborts the requests in flight and logs a warning #1765

Done

Description

@jlouvel

Follow-up to #1706. Found while moving an MCP server onto the STDIO connector of org.restlet.ext.mcp (naftiko/ikanos#838).

StdioServerHelper treats a clean end of its input as a failure. When the reader gets end of stream, it calls fail(new IOException("MCP STDIO input ended")), which logs a WARNING with a stack trace, aborts every request still in flight and stops the stream.

So a client that sends its last request and then half-closes stdin, or a request piped into the server (echo '{...}' | server), loses the answer. Measured with one tools/list line followed by end of input: 611 bytes of answer from a plain line-by-line stdio handler, 0 bytes from the connector. Every normal client shutdown also logs a WARNING with a stack trace on stderr.

An end of input is how a stdio client says "no more requests", not a fault. The requests it already sent should be answered.

Delivery:

  1. On a clean end of input, stop reading but let the requests in flight finish and write their answers, bounded by the request timeout. Requests that never end by themselves, such as a subscriptions/listen stream, are cancelled at once.
  2. Then close as now. Whether getFailure() stays set for an ended input is for the connector's owners to monitor a subprocess by: keep it set, so they still see the end, but log it at FINE rather than WARNING (an I/O error on the input still fails and logs as now).
  3. Tests: a request followed by end of input is answered before the connector closes; a listen stream is cancelled at the end; an I/O error still aborts the requests in flight.
  4. A line under "Bugs fixed" in changes.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions