Commit 2f824ff
fix(mcp-stdio): propagate isError from CallToolResult to wire response (#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>1 parent 4d92d12 commit 2f824ff
2 files changed
Lines changed: 134 additions & 5 deletions
File tree
- src
- Azure.DataApiBuilder.Mcp/Core
- Service.Tests/UnitTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 520 | + | |
525 | 521 | | |
526 | 522 | | |
527 | 523 | | |
528 | 524 | | |
529 | 525 | | |
530 | 526 | | |
531 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
532 | 556 | | |
533 | 557 | | |
534 | 558 | | |
| |||
Lines changed: 105 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
101 | 206 | | |
102 | 207 | | |
103 | 208 | | |
| |||
0 commit comments