Skip to main content
Glama
h382110229

price-hunter

by h382110229
README.md
# 🎯 Price Hunter — 全网比价聚合搜索服务

基于 MCP (Model Context Protocol) 的全网比价聚合引擎,对接淘宝联盟、京东联盟、多多进宝三大电商联盟 API,提供统一的商品搜索、优惠券查询与跨平台比价能力。

## 架构

```
Client (LLM / Agent)
  │  MCP Protocol (stdio / SSE)
  ▼
MCPServer (server.py)
  │
  ├── config.py          # pydantic-settings 凭据加载
  ├── models.py          # 统一数据模型 (Product, Coupon, CompareResult)
  └── engines/
      ├── base.py        # 引擎基类 (签名、重试、Mock/Dry-run)
      ├── taobao.py      # 淘宝联盟 TOP API
      ├── jd.py          # 京东联盟 API
      └── pdd.py         # 多多进宝 API
```

## 快速开始

```bash
# 1. 安装依赖
uv sync

# 2. 配置凭据
cp .env.example .env
# 编辑 .env 填入联盟 API Key(见下方生产配置)

# 3. 检查连通性
uv run python scripts/check_keys.py

# 4. 启动 MCP Server
uv run python -m src.server
```

## 生产配置

三大联盟 API 凭据获取指南详见 [docs/union_api_guide.md](docs/union_api_guide.md)。

`.env` 文件格式:

```
TB_APP_KEY=你的淘宝AppKey
TB_APP_SECRET=你的淘宝AppSecret
TB_ADZONE_ID=你的推广位ID

JD_APP_KEY=你的京东AppKey
JD_APP_SECRET=你的京东AppSecret
JD_SITE_ID=你的推广位SiteID

PDD_CLIENT_ID=你的拼多多ClientID
PDD_CLIENT_SECRET=你的拼多多ClientSecret
PDD_PID=你的推广位PID
```

### 连通性探测

```bash
uv run python scripts/check_keys.py
```

输出示例:

```
╔══════════════════════════════════════════════════════╗
║       Price Hunter — 联盟 API 连通性探测             ║
╠══════════════════════════════════════════════════════╣

  🟢  淘宝联盟 (TOP API)
     已连通 — 返回 1 条结果
  🟡  京东联盟 (JD Union)
     未配置 (Dry-run 运行中)
  🔴  多多进宝 (PDD DDK)
     签名错误: ...

╠══════════════════════════════════════════════════════╣
║  汇总: 🟢 1 连通  🟡 1 未配置  🔴 1 失败    ║
╚══════════════════════════════════════════════════════╝
```

| 图标 | 含义 |
|------|------|
| 🟢 | 真实 API 已连通 |
| 🟡 | 未配置凭据 (Dry-run 模式) |
| 🔴 | 鉴权失败 / 签名错误 / 网络错误 |

## MCP Tools

| Tool | 说明 |
|------|------|
| `search_products` | 跨平台商品搜索 (并发) |
| `get_product_detail` | 单品详情 + 优惠券信息 |
| `compare_prices` | 多平台比价 (并发 + 排序 + 摘要) |
| `get_coupons` | 按商品/关键词搜索优惠券 |

## 容错机制

- **自动重试**: 网络超时/连接失败自动重试 2 次 (指数退避 1s → 3s)
- **错误分类**: 明确区分「未配置密钥」「网络超时」「签名错误」「限流」
- **Mock/Dry-run**: 无凭据时自动返回真实结构的模拟数据,测试无需 API Key
- **生产级超时**: 连接 5s、读取 10s

## 开发状态

- Phase 1 ✅ 工程脚手架与安全基线
- Phase 2 ✅ 三大平台联盟 API 签名算法与比价核心
- Phase 3 ✅ MCP 接入与端到端验证
- Phase 4 ✅ 生产级错误处理与连通性探测

## License

MIT

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation2/5

search_products and compare_prices both perform keyword searches and largely overlap, with compare_prices essentially being a sorted multi-platform version of search_products. get_product_detail already includes coupon information while get_coupons re-searches coupons separately, and parse_and_compare is compare_prices with link parsing added. Agents may struggle to choose the correct tool for a given task.

Naming Consistency4/5

Most tools follow a clear verb_noun snake_case pattern: search_products, get_product_detail, compare_prices, get_coupons. parse_and_compare breaks the noun-object pattern with a compound verb, but the naming is still readable and generally predictable.

Tool Count5/5

Five tools is well-scoped for a cross-platform price-hunting server. Each tool maps to a meaningful user workflow such as searching, viewing detail, comparing prices, finding coupons, and parsing shared links, without bloating the surface.

Completeness4/5

The core price-hunting workflow is covered: search, product detail, coupon lookup, multi-platform comparison, and share-link parsing. Minor gaps exist, such as comparing by a specific product ID across platforms or a dedicated coupon-detail endpoint, but agents can generally work around these.

Maintenance

ActivityMaintained
ResponsivenessNo issues