Commit 52956bc
fix: handle MCP error responses without structuredContent (#34)
* fix: handle MCP error responses without structuredContent gracefully
When an MCP tool returns an error (isError=True), it may only populate
the content field with an error message and leave structuredContent as
None. The SDK now handles this case gracefully by:
1. Checking isError flag before requiring structuredContent
2. Extracting error message from content field for error responses
3. Returning a proper TaskResult with success=False and the error message
4. Only requiring structuredContent for successful responses (isError=False)
This allows the CLI to display agent-provided error messages instead of
raising SDK validation errors.
Updated tests to cover both cases:
- Error responses without structuredContent (now valid)
- Success responses without structuredContent (still invalid)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: split long error message to satisfy line length limit
Split the structuredContent error message across multiple lines
to keep each line under 100 characters for linter compliance.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: explicitly set isError=False in test mocks for successful responses
MagicMock objects return truthy MagicMock instances for any attribute access,
so mock_result.isError was returning a truthy value even when not explicitly
set. This caused the code to incorrectly treat successful test responses as
errors. Now explicitly setting isError=False for all successful response mocks.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5202141 commit 52956bc
2 files changed
+65
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 248 | + | |
| 249 | + | |
257 | 250 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 251 | + | |
263 | 252 | | |
264 | 253 | | |
265 | | - | |
266 | 254 | | |
267 | 255 | | |
268 | 256 | | |
| |||
271 | 259 | | |
272 | 260 | | |
273 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
274 | 296 | | |
275 | 297 | | |
276 | 298 | | |
277 | 299 | | |
278 | 300 | | |
279 | 301 | | |
280 | 302 | | |
281 | | - | |
| 303 | + | |
282 | 304 | | |
283 | 305 | | |
284 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
207 | 209 | | |
208 | 210 | | |
209 | 211 | | |
210 | | - | |
| 212 | + | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
215 | | - | |
| 217 | + | |
216 | 218 | | |
217 | 219 | | |
| 220 | + | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
223 | | - | |
| 226 | + | |
224 | 227 | | |
225 | 228 | | |
226 | 229 | | |
227 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
228 | 252 | | |
229 | 253 | | |
230 | 254 | | |
| |||
0 commit comments