-
Notifications
You must be signed in to change notification settings - Fork 154
Fix McpInspector HTTPS certificate trust for ASP.NET MCP servers #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…CP Inspector Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes MCP Inspector's inability to trust ASP.NET Core development certificates when connecting to HTTPS MCP servers. The fix adds certificate trust configuration to the Node.js-based MCP Inspector by setting appropriate environment variables for certificate handling.
Key changes:
- Adds
WithCertificateTrustConfigurationcallback to configure Node.js certificate trust - Sets
NODE_EXTRA_CA_CERTSforAppendscope andNODE_OPTIONSwith--use-openssl-cafor other scopes - Implementation handles existing
NODE_OPTIONSvalues by appending to them
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResourceBuilderExtensions.cs
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResourceBuilderExtensions.cs
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResourceBuilderExtensions.cs
Show resolved
Hide resolved
|
@dahlsailrunner can you give the pre-release build a try. Here's the feed it'll be on: https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-PullRequests/nuget/v3/index.json |
|
I've tried this but believe I'm not pulling the right package. I've set the above feed (https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-PullRequests/nuget/v3/index.json) as a source in Visual Studio and tried that, and then also tried from VS Code with this command: and in both cases the version I got was The change on the PR looks good though. The repo I'm using to try this (in case you want to try yourself) is dahlsailrunner/simple-mcp-aspire -- it should be runnable and if the running MCP Inspector connects to the MCP Server, then it's working. |
|
hmm that should be the correct feed, but I'll admit that I don't think I've tested it in like 12 months 🤣 |
|
ah, the problem was that the package wasn't the latest one in there, it was Tested and it looks ok with the right version |
|
Confirmed as working -- I eve tried version |
…tor-certificate-issue
Minimum allowed line rate is |
Closes #1012
MCP Inspector (Node.js) fails to connect to HTTPS MCP servers with
DEPTH_ZERO_SELF_SIGNED_CERTerror because it doesn't trust the ASP.NET Core dev certificate.Added
WithCertificateTrustConfigurationto configure Node.js certificate trust, matching the official Aspire JavaScript hosting pattern:NODE_EXTRA_CA_CERTSwhen certificate scope isAppendNODE_OPTIONSwith--use-openssl-caotherwise, preserving existing optionsPR Checklist
Other information
Implementation copied from upstream
dotnet/aspireWithNodeDefaults(lines 215-243) as suggested by @aaronpowell. All 18 existing unit tests pass.Original prompt
This section details on the original issue you should resolve
<issue_title>McpInspector does not trust the dotnet dev cert for ASP.NET MCP servers</issue_title>
<issue_description>### Describe the bug
When running the simplest possible ASP.NET 10 MCP server through Aspire and using the McpInspector integration in this toolkit, the McpInspector integration will fail if an https endpoint is not provided (which is fine for me). But when I use an https endpoint, everything DOES launch just fine, but when I try to actually connect from the Mcp Inspector to my mcp server, it will fail due to a certificate problem.
You can use this repo to see / experiment with the issue and solution: dahlsailrunner/simple-mcp-aspire. The working logic in the apphost is in place. Just comment it out to see the failure.
The error looks something like this (key part is this:
request to [https://localhost:7229/](https://localhost:7229/) failed, reason: self-signed certificate; if the root CA is installed locally, try running Node.js with --use-system-ca):🚀 MCP Inspector is up and running at: [http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=%7EuG%7BwKeA-%21DxJ42A%7E8mqM%29](http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=%7EuG%7BwKeA-%21DxJ42A%7E8mqM%29) New StreamableHttp connection request Query parameters: {"url":"[https://localhost:7229/](https://localhost:7229/)","transportType":"streamable-http"} Created StreamableHttp client transport Client <-> Proxy sessionId: 068ebc44-8d6c-46d2-aa19-af3c0d9ac433 Error from MCP server: FetchError: request to [https://localhost:7229/](https://localhost:7229/) failed, reason: self-signed certificate; if the root CA is installed locally, try running Node.js with --use-system-ca at ClientRequest.<anonymous> (file:///E:/demos/mcp-sample/node_modules/node-fetch/src/index.js:108:11) at ClientRequest.emit (node:events:520:35) at emitErrorEvent (node:_http_client:108:11) at TLSSocket.socketErrorListener (node:_http_client:575:5) at TLSSocket.emit (node:events:508:28) Starting process... {"Executable": "/mcp-bekavwzd", "Reconciliation": 6, "Cmd": "C:\\Program Files\\dotnet\\dotnet.exe", "Args": ["run", "--project", "E:\\demos\\mcp-sample\\HelloMcp\\HelloMcp.csproj", "--no-build", "--configuration", "Debug", "--no-launch-profile"]} at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at process.processTicksAndRejections (node:internal/process/task_queues:89:21) { type: 'system', errno: 'DEPTH_ZERO_SELF_SIGNED_CERT', code: 'DEPTH_ZERO_SELF_SIGNED_CERT', erroredSysCall: undefined }To resolve this, I modified the apphost's AddMcpInspector lines based on the official Aspire JavaScript integration:
This works and I have a fork with a feature branch ready for a PR. It's not easily testable with the tests that are in there (testing this would probably require adding a Playwright test project into the mix). But all of the existing tests still pass with the logic I've added.
Regression
No response
Steps to reproduce
Expected behavior
Connecting to an ASP.N...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.