Commit d2130ff
Fix CallToolResult handling across all SDKs (#1049)
* Fix CallToolResult handling across all SDKs
When a tool handler returns an MCP CallToolResult object
({ content: [...], isError?: bool }), all four SDKs were
JSON-serializing it instead of converting it to ToolResultObject.
This caused the LLM to see raw JSON instead of actual tool output.
Add detection and conversion of CallToolResult in Node.js, Python,
Go, and .NET. The .NET SDK additionally handles Microsoft.Extensions.AI
content types (TextContent, DataContent, and unknown subtypes via
AIJsonUtilities serialization).
Fixes #937
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix formatting and lint issues
Run prettier on Node.js files, ruff format on Python files,
and remove unused ToolResultObject import from test file.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Remove unused _convert_call_tool_result import
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Address review feedback: add type guards in Python, fix Go comment typo
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix Python import sorting in test_tools_unit.py
Sort imports in copilot.tools import block to satisfy ruff I001 rule.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Remove isCallToolResult and convertCallToolResult from public exports
These are internal implementation details used by session.ts and client.ts.
Go and Python already keep them private (lowercase/underscore-prefixed).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* TypeScript formatting
Co-Authored-By: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
* Address review feedback: explicit MCP conversion, shared .NET helper, consistent guards
- Remove implicit duck-typing of MCP CallToolResult from all SDKs
- Add explicit public conversion: convertMcpCallToolResult (TS),
ConvertMCPCallToolResult (Go), convert_mcp_call_tool_result (Python)
- Extract shared ConvertFromInvocationResult helper in .NET
- Remove isCallToolResult type guard (TS) and _is_call_tool_result (Python)
- Rename types/functions to include 'Mcp' prefix across all languages
- Make McpCallToolResult type non-exported in TS (structural typing)
- Skip image blocks with empty data consistently across TS/Go/Python
- Update all tests to use explicit conversion functions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix CI: prettier formatting and ruff import sorting
- Fix prettier line-length violation in nodejs/src/types.ts (long if condition)
- Fix ruff I001 import sorting in python/e2e/test_tools_unit.py (_normalize_result before convert_mcp_call_tool_result)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>1 parent 6029b37 commit d2130ff
File tree
11 files changed
+789
-18
lines changed- dotnet/src
- go
- nodejs
- src
- test
- python
- copilot
- e2e
11 files changed
+789
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1549 | 1549 | | |
1550 | 1550 | | |
1551 | 1551 | | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
| 1552 | + | |
1559 | 1553 | | |
1560 | 1554 | | |
1561 | 1555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
| 571 | + | |
578 | 572 | | |
579 | 573 | | |
580 | 574 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
327 | 416 | | |
328 | 417 | | |
329 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
99 | 101 | | |
100 | 102 | | |
101 | 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 | + | |
102 | 202 | | |
103 | 203 | | |
104 | 204 | | |
| |||
0 commit comments