Commit 6cfdd98
fix: surface upstream body on 5xx and unbreak review_urgent_order_requirements 415 (#203)
Two fixes driven by the 2026-05-26 MCP bug report.
1. utils.unwrap() now appends a truncated body excerpt to the error message
when the response has no parsed body and a non-2xx status. StockTrim's
Order Plan endpoint sometimes returns 500 with an HTML stack trace or
415 with a plaintext reason; the previous "API error with status N"
message was opaque without those bodies. Excerpts are bounded at 500
chars with a "…[+N chars]" suffix so log lines stay readable, and
UTF-8 decode errors fall back to a byte-count placeholder.
2. review_urgent_order_requirements built an OrderPlanFilterCriteriaDto
(list-shaped, used by the V2 PO generation endpoint) and passed it to
client.order_plan.query() which targets /api/OrderPlan and expects
OrderPlanFilterCriteria (singular `location`/`supplier`/`category`).
StockTrim rejected the wrong-shaped body with 415. Switch to the
singular schema; for list-shaped MCP inputs, send the first element
to the API and log `order_plan_multifilter_narrowed` so operators see
that further filtering was dropped (multi-filter is an API limitation).
Tests:
- test_utils.py: 4 new cases for body-excerpt formatting (basic, long-body
truncation, empty body, undecodable bytes).
- test_urgent_orders.py: 2 new cases pinning the OrderPlanFilterCriteria
type (vs Dto) and the multi-element warning.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent be4657a commit 6cfdd98
4 files changed
Lines changed: 371 additions & 14 deletions
File tree
- stocktrim_mcp_server
- src/stocktrim_mcp_server/tools/workflows
- tests/test_tools/test_workflows
- stocktrim_public_api_client
- tests
Lines changed: 50 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
27 | 59 | | |
28 | 60 | | |
29 | 61 | | |
| |||
100 | 132 | | |
101 | 133 | | |
102 | 134 | | |
| 135 | + | |
103 | 136 | | |
104 | 137 | | |
105 | 138 | | |
| |||
122 | 155 | | |
123 | 156 | | |
124 | 157 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
131 | 174 | | |
132 | 175 | | |
133 | 176 | | |
| |||
Lines changed: 116 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 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 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
206 | 316 | | |
207 | 317 | | |
208 | 318 | | |
| |||
470 | 580 | | |
471 | 581 | | |
472 | 582 | | |
473 | | - | |
| 583 | + | |
| 584 | + | |
474 | 585 | | |
475 | 586 | | |
476 | 587 | | |
| |||
485 | 596 | | |
486 | 597 | | |
487 | 598 | | |
488 | | - | |
| 599 | + | |
489 | 600 | | |
490 | 601 | | |
491 | 602 | | |
| |||
506 | 617 | | |
507 | 618 | | |
508 | 619 | | |
509 | | - | |
| 620 | + | |
510 | 621 | | |
511 | 622 | | |
512 | 623 | | |
| |||
530 | 641 | | |
531 | 642 | | |
532 | 643 | | |
533 | | - | |
534 | | - | |
| 644 | + | |
| 645 | + | |
535 | 646 | | |
536 | 647 | | |
537 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 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 | + | |
70 | 134 | | |
71 | 135 | | |
72 | 136 | | |
| |||
139 | 203 | | |
140 | 204 | | |
141 | 205 | | |
142 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
143 | 210 | | |
144 | 211 | | |
145 | 212 | | |
| |||
149 | 216 | | |
150 | 217 | | |
151 | 218 | | |
152 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
153 | 222 | | |
154 | 223 | | |
155 | 224 | | |
| |||
0 commit comments