Avoid starting web host in MCP stdio mode#3676
Open
jstar0 wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes MCP stdio mode (dab start --mcp-stdio) so it no longer starts the ASP.NET Core web host (and therefore doesn’t attempt to bind HTTP ports via Kestrel) before completing the MCP initialize handshake.
Changes:
- Remove the
IHost.Start()/StopAsync()lifecycle calls from the MCP stdio helper path. - Keep MCP tool discovery/registration via DI, then run the stdio JSON-RPC loop.
- Add a regression unit test asserting stdio mode does not start the host while still running the stdio server loop.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Service/Utilities/McpStdioHelper.cs | Stops starting/stopping the host in MCP stdio mode; runs tool registry init + stdio loop without binding HTTP ports. |
| src/Service.Tests/UnitTests/McpStdioHelperTests.cs | Adds a regression test validating stdio mode doesn’t start the web host while still running the stdio server loop. |
JerryNixon
approved these changes
Jun 22, 2026
JerryNixon
left a comment
Contributor
There was a problem hiding this comment.
Clean and simple. Thank you for the PR. Looks great. Small tweaks.
RubenCerna2079
requested changes
Jun 24, 2026
RubenCerna2079
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Just need you to address the comments made by copilot. If you think they are not necessary, just give your reasoning and resolve the issue.
8ea2547 to
1a12bf9
Compare
RubenCerna2079
approved these changes
Jun 25, 2026
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
|
@jstar0 this PR is ready to merge in. Thanks for your work! |
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.
Summary
dab start --mcp-stdiocommunicates over stdin/stdout, but the stdio helper was callinghost.Start(). That starts the web host and Kestrel, so stdio mode still tried to bind the configured HTTP port. When the port was occupied, the process exited before the MCPinitializehandshake.The stdio path already initializes and registers MCP tools directly from DI, so it can run the stdio JSON-RPC loop without starting Kestrel.
Fixes #3675.
Changes
StartAsync()orStopAsync().RunMcpStdioHost()does not callIHost.StartAsync()/StopAsync(), still starts the stdio server loop, and disposes the host.Verification
A runtime smoke also occupied
127.0.0.1:5155, pointedASPNETCORE_URLSat that occupied port, and verified that the service completed MCPinitializeandshutdownover stdio without an address-in-use error.