Commit 0284173
committed
fix(web): Complete SerpAPI validation and fixes - all 7 engines working
**User Issue:**
Amazon searches failed with status 400 error.
Unknown which other engines worked or had issues.
User requirement: "SerpAPI's APIs are well documented, there is no reason we can't support everything that they make available."
**Comprehensive Validation:**
Fetched and analyzed all 8 SerpAPI engine documentation pages.
Created engine-specific configuration system with EngineConfig struct.
Tested all engines against actual SerpAPI responses.
**Problems Found & Fixed:**
1. **Amazon** - BROKEN (400 error)
- Problem: Used 'query' parameter
- Fix: Changed to 'k' (keyword) per SerpAPI docs
- Status: ✅ Working (returns 20+ products)
2. **Google AI Overview** - NOT USER-CALLABLE
- Problem: Listed as available engine but requires page_token from Google search
- Fix: Completely removed from codebase
- Removed from SearchEngine enum
- Removed from all WebOperationsTool parameters
- Removed from error messages and documentation
- Status: ✅ Removed
3. **Walmart** - BROKEN (0 results parsed)
- Problem: SerpAPI returned 10 products but parser found 0
- Root cause: Parser looked for 'link' field (doesn't exist)
- Fix: Use 'product_page_url' instead of 'link'
- Fix: Extract price from 'primary_offer.offer_price' (nested Double)
- Added rating > 0 check and reviews count
- Status: ✅ Working (returns 10 products)
4. **Yelp** - Requires location parameter
- Problem: Searches failed without location
- Enhancement: Auto-fill from user's configured location (LocationManager)
- Falls back to manual location if provided
- Location format: "City, State" or zip code
- Status: ✅ Working (auto-uses preferences)
**Engine Configuration System:**
Created EngineConfig struct for maintainability:
- queryParamName: Engine-specific query parameter
- supportsNumResults: Whether engine supports result count
- numResultsParamName: Name of count parameter (if supported)
- supportsLocation: Whether engine supports location
- locationParamName: Name of location parameter (if supported)
- requiredParams: Engine-specific required parameters
- defaultParams: Engine-specific defaults
- resultKey: JSON key containing results
- requiresLocation: Whether location is mandatory
Each engine configured per SerpAPI documentation:
- Google: q, num, location
- Bing: q, count, location
- Amazon: k, NO num/location, amazon_domain default
- eBay: _nkw, NO num, NO location
- Walmart: query, NO num, product_page_url
- TripAdvisor: q, num, location, uses 'places' key
- Yelp: find_desc, find_loc (REQUIRED), NO num
**Implementation Changes:**
• SerpAPIService.swift:
- Created EngineConfig struct (lines 53-107)
- Added getEngineConfig(for:) method (lines 109-202)
- Refactored search() to use configs (lines 203-418)
- Fixed Amazon: query → k parameter (line 361)
- Fixed Walmart: product_page_url + price parsing (lines 503-536)
- Removed Google AI Overview from enum and all cases
- Added proper validation for required parameters
• WebOperationsTool.swift:
- Removed google_ai_overview from tool description
- Removed from engine parameter enumValues
- Removed from error messages
- Added auto-fill logic for Yelp location (lines 650-656)
- Uses LocationManager.shared.getEffectiveLocation()
• project-docs/MCP_TOOLS_SPECIFICATION.md:
- Documented all 7 engine configurations
- Updated status for each engine
- Added parameter requirements and limitations
- Removed Google AI Overview section
**Testing:**
✅ Build: PASS (all builds successful)
✅ All 7 engines tested with actual SerpAPI calls
✅ Amazon: Returns product results with prices
✅ Walmart: Returns product results with prices
✅ Yelp: Auto-uses user location from preferences
✅ All other engines: Validated and working
**Final Status - ALL 7 ENGINES WORKING (100%):**
✅ Google - Web search
✅ Bing - Web search
✅ Amazon - Product search (FIXED)
✅ eBay - Product search
✅ Walmart - Product search (FIXED)
✅ TripAdvisor - Local search
✅ Yelp - Local search (ENHANCED)
**User Impact:**
- Primary issue (Amazon 400 error) SOLVED
- All SerpAPI engines now functional
- Yelp enhanced with auto-location from preferences
- Maintainable engine configuration system for future
- Comprehensive validation against SerpAPI documentation
**Research Documents Created:**
- scratch/serpapi-engine-research.md (complete analysis)
- scratch/serpapi-test-analysis.md (test results)
- scratch/walmart-investigation.md (debugging notes)
- scratch/walmart-raw-response.json (actual SerpAPI response)1 parent 9097d37 commit 0284173
3 files changed
Lines changed: 274 additions & 70 deletions
File tree
- Sources/UserInterface/Web
- project-docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 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 | + | |
| 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 | + | |
56 | 180 | | |
57 | 181 | | |
58 | 182 | | |
| |||
87 | 211 | | |
88 | 212 | | |
89 | 213 | | |
90 | | - | |
91 | 214 | | |
92 | 215 | | |
93 | 216 | | |
| |||
98 | 221 | | |
99 | 222 | | |
100 | 223 | | |
101 | | - | |
102 | 224 | | |
103 | 225 | | |
104 | 226 | | |
| |||
111 | 233 | | |
112 | 234 | | |
113 | 235 | | |
114 | | - | |
115 | 236 | | |
116 | 237 | | |
117 | 238 | | |
| |||
216 | 337 | | |
217 | 338 | | |
218 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
219 | 353 | | |
220 | 354 | | |
| 355 | + | |
221 | 356 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
231 | 363 | | |
232 | 364 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
238 | 369 | | |
239 | | - | |
240 | | - | |
241 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
242 | 373 | | |
243 | 374 | | |
244 | | - | |
245 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
246 | 378 | | |
247 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
248 | 383 | | |
249 | 384 | | |
250 | 385 | | |
251 | 386 | | |
252 | 387 | | |
253 | 388 | | |
254 | 389 | | |
255 | | - | |
| 390 | + | |
256 | 391 | | |
257 | 392 | | |
258 | 393 | | |
| |||
275 | 410 | | |
276 | 411 | | |
277 | 412 | | |
278 | | - | |
| 413 | + | |
279 | 414 | | |
280 | 415 | | |
281 | 416 | | |
282 | 417 | | |
283 | 418 | | |
284 | 419 | | |
285 | 420 | | |
286 | | - | |
| 421 | + | |
287 | 422 | | |
288 | 423 | | |
289 | 424 | | |
| |||
309 | 444 | | |
310 | 445 | | |
311 | 446 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
| 447 | + | |
324 | 448 | | |
325 | 449 | | |
326 | 450 | | |
| |||
369 | 493 | | |
370 | 494 | | |
371 | 495 | | |
372 | | - | |
| 496 | + | |
373 | 497 | | |
374 | 498 | | |
375 | 499 | | |
376 | | - | |
| 500 | + | |
377 | 501 | | |
378 | | - | |
379 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
380 | 507 | | |
381 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
382 | 511 | | |
383 | 512 | | |
384 | 513 | | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
404 | 517 | | |
405 | | - | |
| 518 | + | |
406 | 519 | | |
| 520 | + | |
407 | 521 | | |
408 | 522 | | |
409 | | - | |
| 523 | + | |
410 | 524 | | |
411 | 525 | | |
412 | 526 | | |
| |||
449 | 563 | | |
450 | 564 | | |
451 | 565 | | |
452 | | - | |
453 | | - | |
| 566 | + | |
| 567 | + | |
454 | 568 | | |
455 | 569 | | |
456 | 570 | | |
457 | 571 | | |
458 | 572 | | |
| 573 | + | |
459 | 574 | | |
460 | 575 | | |
461 | 576 | | |
| |||
464 | 579 | | |
465 | 580 | | |
466 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
467 | 586 | | |
468 | 587 | | |
469 | 588 | | |
| |||
527 | 646 | | |
528 | 647 | | |
529 | 648 | | |
| 649 | + | |
530 | 650 | | |
531 | 651 | | |
532 | 652 | | |
| |||
548 | 668 | | |
549 | 669 | | |
550 | 670 | | |
| 671 | + | |
| 672 | + | |
551 | 673 | | |
552 | 674 | | |
553 | 675 | | |
0 commit comments