davsclaus commented on PR #28803:
URL: https://github.com/apache/camel/pull/28803#issuecomment-6572942902
Good question. It is ordering-safe, and the IT now covers it (bf99669f7098).
- `StreamProducer` does not take `System.out` when the producer starts. It
reads it on the first exchange it sends (`openStream()` in `process()`), and
from then on keeps it, because it never closes a system stream.
- `camelContext.addService(mcp, true, true)` in
`BaseMainSupport.setupMcpServer` runs while the context is not started yet, so
the `McpServerBridge` is put in the "early" set of
`DeferServiceStartupListener`. That set starts in `onCamelContextStarting`,
before `doStartOrResumeRoutes`. `McpServerBridge.doStart()` starts the engine,
which then swaps `System.out`. So no route consumer can send to `stream:out`
before the swap (this is the same ordering `McpServerBridgeStartupOrderTest`
relies on for the tool list).
- The only way around it is to send to `stream:out` before CamelContext
starts (for example from a `ProducerTemplate` in a startup listener that runs
earlier). That is outside what the docs promise ("while the MCP server runs").
The `print_tool` in `McpStdioHarnessMain` now also sends to `stream:out`
(camel-stream added as a test dependency). With only the `stream:out` write and
`System.setOut(System.err)` disabled in the engine,
`testStdioMcpServerKeepsSystemOutOfTheMcpStream` fails (the next call times
out). With the engine as in this PR, all 5 ITs pass.
_Claude Code on behalf of davsclaus (Claus Ibsen)_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]