fix(mcp-stdio): propagate isError from CallToolResult to wire response [cherry-pick #3625 → release/2.0]#3635
Open
Aniruddh25 wants to merge 1 commit into
Conversation
#3625) ## Summary Fixes a bug in the MCP stdio transport where `isError` was silently dropped from every `tools/call` response. ### Root Cause `HandleCallTool` in `McpStdioServer` used `CoerceToMcpContentBlocks` (reflection-based) to extract only the `Content` list from the `CallToolResult`, then constructed the JSON-RPC result with `new { content }`. The `IsError` property was never read, so all tool responses — successes and errors alike — looked identical on the wire. The HTTP transport was not affected; the MCP SDK serializes the full `CallToolResult` returned by `WithCallToolHandler`, correctly emitting `"isError": true` when set. ### Fix After `CoerceToMcpContentBlocks`, read `callResult.IsError` and include `isError` in the result object only when `== true`. The existing `WhenWritingNull` serializer option on `_jsonOptions` ensures a null `isError` (success path) is omitted from the wire — matching the MCP spec. ```csharp bool? isError = callResult.IsError; if (isError == true) { WriteResult(id, new { content, isError }); } else { WriteResult(id, new { content }); } ``` ### Tests Added (`McpStdioServerContentBlockTests`) - **`HandleCallTool_ErrorResult_EmitsIsErrorTrueOnWire`** — creates a real `CallToolResult { IsError = true }`, replicates the exact `HandleCallTool` conditional logic, and asserts `"isError": true` is present in the JSON-RPC wire output. - **`HandleCallTool_SuccessResult_OmitsIsErrorFromWire`** — verifies that a success result produces no `isError` field at all on the wire. --------- Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Cherry-pick of #3625 to release/2.0. Fixes an MCP stdio bug where IsError from CallToolResult was dropped when constructing the JSON-RPC tools/call response, making tool errors indistinguishable from successes on the wire.
Changes:
- Extract a new
HandleCallToolAsync(JsonElement, CallToolResult)overload that includesisErrorin the result only whentrue, relying onWhenWritingNullto omit it on success. - Add regression tests for both error (
isError: trueemitted) and success (isErroromitted) wire output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs | Adds an overload that propagates IsError into the JSON-RPC result. |
| src/Service.Tests/UnitTests/McpStdioServerContentBlockTests.cs | Adds regression tests verifying isError presence/absence on the wire. |
aaronburtle
approved these changes
May 23, 2026
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.
Cherry-pick of #3625 →
release/2.0This is a cherry-pick of PR #3625 (
fix(mcp-stdio): propagate isError from CallToolResult to wire response) frommaintorelease/2.0.Original PR Summary
Fixes a bug in the MCP stdio transport where
isErrorwas silently dropped from everytools/callresponse.Root Cause:
HandleCallToolusedCoerceToMcpContentBlocksto extract only theContentlist fromCallToolResult, then constructed the JSON-RPC result withnew { content }. TheIsErrorproperty was never read, so all tool responses looked identical on the wire.Fix: After
CoerceToMcpContentBlocks, readcallResult.IsErrorand includeisErrorin the result object only when== true. The existingWhenWritingNullserializer option ensuresisErroris omitted on the success path — matching the MCP spec.Tests Added (
McpStdioServerContentBlockTests):HandleCallTool_ErrorResult_EmitsIsErrorTrueOnWire— verifies"isError": trueis present for error resultsHandleCallTool_SuccessResult_OmitsIsErrorFromWire— verifiesisErroris absent for success resultsSquash commit cherry-picked:
2f824ffc2