Skip to content

Conversation

@halter73
Copy link
Contributor

Before this PR, tests in classes deriving from KestrelInMemoryTest would fail using the Dev Container configured by this project's devcontainer.json based on mcr.microsoft.com/devcontainers/dotnet:1-8.0-jammy. The HttpClient would timeout trying to connect to Kestrel using the in-memory test transport. Some investigation uncovered this was caused by the Dockerfile setting a non-default ASPNETCORE_HTTP_PORTS environment variable of 8080 instead of the normal default port of 5000 used by default by the test.

I noticed that the tests using SseServerIntegrationTestFixture still passed on the Dev Container while KestrelInMemoryTest wouldn't, and this is because ModelContextProtocol.TestSseServer referenced by the test fixture uses WebApplication.CreateEmptyBuilder() which doesn't read environment variables as configuration instead of WebApplication.CreateSlimBuilder() which does. I could have fixed the default port issue by explicitly calling something like ListenLocalhost(5000) which would override configuration, but I discovered that CreateEmptyBuilder() actually will automatically add the routing middleware if you don't add it manually just like the other builders despite what I claimed in the comment I deleted. Had I known that to begin with, I would have used CreateEmptyBuilder() all along for simplicity and avoiding potential environmental issues like this.

I also updated the Dev Container's "postCreateCommand" to install and trust a developer certificate. Technically, only the installation is necessary, since the tests use RemoteCertificateValidationCallback = (_, _, _, _) => true, but I think trusting makes sense for running samples. Currently, only the TestOAuthServer uses HTTPS. This wouldn't be necessary if we updated the tests and ProtectedMCPServer sample to set RequireHttpsMetadata to false. But for the sample in particular, I'd rather not do this.

@halter73 halter73 requested a review from mikekistler November 15, 2025 04:20
Copy link
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are now all passing for me. Thanks!

@stephentoub stephentoub merged commit b9c9f44 into main Nov 17, 2025
10 checks passed
@stephentoub stephentoub deleted the halter73/devcontainers branch November 17, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants