Commit c93528b
Samuel LEGROS
mcp: factor empty-filter normalization into _normalize_optional_filter helper
Follow-up to eb27e00 (port of upstream PR MemPalace#1097). The original port only
fixed tool_search; tool_list_rooms and tool_find_tunnels still treated
whitespace-only filters as truthy, which let an LLM-supplied wing=" "
turn into a literal `WHERE wing = ' '` SQL filter that returned zero
rows.
Extracts the strip-and-empty-as-None logic into _normalize_optional_filter
and routes every LLM-callable tool with optional filter args through it:
tool_search(wing, room) — replaced inline normalization
tool_list_rooms(wing) — was the latent bug
tool_find_tunnels(wing_a, wing_b) — was the latent bug
tool_diary_write(wing) — replaced inline normalization
tool_diary_read(wing) — replaced inline normalization
The helper also strips leading/trailing whitespace on real values, so
wing=" wing_code " is now treated as wing="wing_code" instead of
silently matching nothing.
Six tests added: helper itself (3 cases), tool_list_rooms with empty +
real wing (2 cases), tool_find_tunnels with empty + real wings (1 case).
Found during second-order analysis of the 2026-04-25 upstream sync —
caught before any LLM agent hit the latent bug in the wild.1 parent 2e23e49 commit c93528b
2 files changed
Lines changed: 123 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
| |||
131 | 145 | | |
132 | 146 | | |
133 | 147 | | |
| 148 | + | |
134 | 149 | | |
135 | 150 | | |
136 | 151 | | |
| |||
159 | 174 | | |
160 | 175 | | |
161 | 176 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 177 | + | |
| 178 | + | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| |||
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
224 | | - | |
| 234 | + | |
225 | 235 | | |
226 | 236 | | |
227 | 237 | | |
| |||
329 | 339 | | |
330 | 340 | | |
331 | 341 | | |
332 | | - | |
333 | | - | |
334 | | - | |
| 342 | + | |
| 343 | + | |
335 | 344 | | |
336 | 345 | | |
337 | 346 | | |
| |||
380 | 389 | | |
381 | 390 | | |
382 | 391 | | |
383 | | - | |
384 | | - | |
385 | | - | |
| 392 | + | |
386 | 393 | | |
387 | 394 | | |
388 | | - | |
| 395 | + | |
389 | 396 | | |
390 | 397 | | |
391 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 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 | + | |
141 | 166 | | |
142 | 167 | | |
143 | 168 | | |
| |||
240 | 265 | | |
241 | 266 | | |
242 | 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 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
243 | 344 | | |
244 | 345 | | |
245 | 346 | | |
| |||
0 commit comments