Handle stdin EOF gracefully in MCP stdio mode (#3428)#3647
Open
anushakolan wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the robustness of DAB’s MCP stdio hosting path by treating stdin EOF (client closes the pipe) as a normal shutdown signal rather than an error condition that terminates the process with a noisy non-zero exit code.
Changes:
- Updated
McpStdioServer.RunAsyncto read fromConsole.Inand to exit cleanly whenReadLineAsyncreturnsnull(EOF). - Added unit tests validating clean exit on EOF and correct handling of blank lines followed by a
shutdownrequest.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Service.Tests/UnitTests/McpStdioServerRunAsyncTests.cs | Adds unit coverage for EOF-on-stdin and blank-line handling in the MCP stdio loop. |
| src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs | Treats stdin EOF as graceful shutdown by returning from the read loop when ReadLineAsync yields null. |
aaronburtle
reviewed
Jun 3, 2026
aaronburtle
reviewed
Jun 3, 2026
aaronburtle
reviewed
Jun 3, 2026
aaronburtle
approved these changes
Jun 3, 2026
Contributor
aaronburtle
left a comment
There was a problem hiding this comment.
Looks good, just a couple nits.
Aniruddh25
reviewed
Jun 3, 2026
Aniruddh25
approved these changes
Jun 3, 2026
Collaborator
Aniruddh25
left a comment
There was a problem hiding this comment.
Approving with some questions to avoid regression around UTFNoBOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why make this change?
When
dab start --mcp-stdiowas launched by a client (such as MCP Inspector or VS Code) and the client closed the stdin pipe (EOF), the process crashed with exit code4294967295instead of exiting cleanly. This caused noisy error signals in any tool or host that expected a clean0exit on shutdown.What is this change?
Modified
McpStdioServer.RunAsyncto handle stdin EOF as a normal shutdown signal:Console.OpenStandardInput()+StreamReaderwithConsole.In(testable, injectable)nullcheck on the return value ofReadLineAsync—nullmeans EOF, which now triggers a cleanreturninstead of an unhandled exceptionHow was this tested?
Unit Tests
Added
McpStdioServerRunAsyncTests:RunAsync_EofOnStdin_ExitsGracefullyWithoutOutput— feeds empty stdin, verifies clean exit with no stdout outputRunAsync_BlankLineThenShutdown_IgnoresBlankLineAndHandlesShutdown— feeds blank line + shutdown request, verifies single valid response and clean exitManual Testing
initializerequest then closed stdin — verifiedEXIT_CODE=0EXIT_CODE=0for normalshutdownrequest pathread_records,describe_entities) continue to work after the change