Files
assistant/mcp_servers/product_mcp/server.py
wangliang f4e77f39ce fix: 修复 Mall API 数据提取逻辑和添加配置字段
## 问题 1: Settings 缺少 Mall API 配置
**错误**: `'Settings' object has no attribute 'mall_api_url'`

**原因**: Settings 类只有 hyperf 配置,缺少 Mall API 相关字段

**解决方案**: 添加 Mall API 配置字段(第 20-25 行)
```python
mall_api_url: str
mall_tenant_id: str = "2"
mall_currency_code: str = "EUR"
mall_language_id: str = "1"
mall_source: str = "us.qa1.gaia888.com"
```

## 问题 2: Mall API 数据结构解析错误
**现象**: 商品搜索始终返回 0 个商品

**原因**: Mall API 返回的数据结构与预期不符

**Mall API 实际返回**:
```json
{
  "total": 0,
  "data": {
    "data": [],  // ← 商品列表在这里
    "isClothesClassification": false,
    "ad": {...}
  }
}
```

**代码原来查找**: `result.get("list", [])` 

**修复后查找**: `result["data"]["data"]` 

**解决方案**: 修改数据提取逻辑(第 317-323 行)
```python
if "data" in result and isinstance(result["data"], dict):
    products = result["data"].get("data", [])
else:
    products = result.get("list", [])  # 向后兼容
total = result.get("total", 0)
```

## 调试增强
添加 print 调试语句:
- 第 292 行:打印调用参数
- 第 315 行:打印 Mall API 返回结果

便于诊断 API 调用问题。

## 测试结果

修复前:
```
'Settings' object has no attribute 'mall_api_url'
```

修复后:
```json
{
  "success": true,
  "products": [],
  "total": 0,
  "keyword": "61607"
}
```

 工具调用成功
⚠️ 返回 0 商品(可能是关键词无匹配)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 18:43:46 +08:00

12 KiB