Repository navigation
Conversation
This branch has not been deployed
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.
Fixes #2060
Problem
On the server, a normal exception reaches the client only as "An error occurred.", but the span was recording the real exception message. So the trace leaked more than the client ever saw.
In
McpSessionHandler:AddResponseTagsset the span status description tocontent.ToJsonString()for any result withisError: true, putting tool result content into traces.AddExceptionTagsset it toe.Messagefor every exception.Change
isErrorresults:SetStatus(ActivityStatusCode.Error)with no description.error.type=tool_erroralready marks the failure.McpProtocolExceptionmessages are kept (the JSON-RPC error message the peer already sees); other exception messages are dropped.error.typeand status-code tags are unchanged.Since both helpers are shared, client spans for
isErrorresults also lose their description. Client-side remote errors areMcpProtocolExceptions, so client spans still keep a description for those.Open question for reviewers: a plain
McpExceptionstill sends its message over the wire, but this change drops it from the span to match the issue's wording. Happy to keep it if you'd prefer.Tests
Session_ErrorStatusDescription_DoesNotContainToolContentOrExceptionMessagetoDiagnosticTests.cs(a tool returning anisErrorresult plus a handler that throwsInvalidOperationException). It fails before the change (Actual: "[{\"type\":\"text\",\"text\":\"secret tool content"···, then"secret exception message") and passes after.dotnet build: 0 warnings, 0 errors.ModelContextProtocol.Testspasses on net10.0, net9.0, net8.0 and net472.ServerConformanceTestsin AspNetCore.Tests fail identically with and without this change on my machine (pre-existing, environment-related).AI assistance: Claude Code drafted the fix and tests; I reviewed every line and ran the suite locally.