Skip to main content
Glama
store-link-resolver

store-link-resolver

README.md
# Store Link Resolver — MCP Server

Give an AI assistant a product name and get back a store's current
offer for it: the real price, checked at call time, and the
affiliate link to buy it. Built for shopping assistants, buying
agents, and any MCP client that needs to turn "a 48 inch standing
desk under $300" into a link a person can actually click.

**Affiliate disclosure, up front:** if a buyer purchases through a
link this server returns, the server's operator may earn a
commission from the store at no extra cost to the buyer. That
disclosure is not just on this page — the resolver puts it in the
tool description, on every response envelope, and on every single
result, and it refuses to serve a result that lacks a lawful
affiliate URL. Results are ranked by match to the query, exactly
in the order the store's search returned them. The code contains
no commission data and never re-sorts.

## Tools

| Tool | What it does |
|---|---|
| `resolve_product(q, category, max_price, condition, limit)` | Resolve a product query to current offers: title, store, live price with a `checked_at` stamp, condition, and the affiliate URL served byte for byte as the store returned it. `condition` is `new`, `used` or `any`; `limit` defaults to 5, max 25. |
| `list_product_stores()` | The stores the resolver can route to today, each with its honest live status and price source. |
| `list_product_categories()` | The category taxonomy the resolver accepts, what each category includes, and which stores cover it. |

Categories: `tech-for-small-business` (laptops, monitors, docking
stations, networking, printers), `office-and-desk-gear` (desks,
chairs, monitor arms, lighting), `tools` (power tools, hand
tools), and `home-office` (home office furniture, desk decor).

## Stores, honestly

- **eBay** is the one built store, on the eBay Browse API. It is
  live only when the operator's own credentials are in the
  environment (below). Prices are live per call — nothing is
  cached beyond a two minute quota-protection window, and the
  `checked_at` stamp always says when the price was really read.
- **Walmart is not built.** Its adapter is gated on Walmart
  program approval and on reading the Walmart I/O API terms at
  credential issuance. Until both happen, `list_product_stores`
  reports it as `not_built` and no Walmart offer is ever returned.

## Run it

```bash
pip install -r requirements.txt
python3 mcp_server.py                    # stdio (default)
python3 mcp_server.py --transport streamable-http --port 8794
```

The HTTP transport also answers `GET /health` with the service
status and each store's status. Tests:
`python3 -m unittest discover -s tests -v`.

### Credentials (the operator's own)

Live eBay resolution needs three environment values, all from the
operator's own accounts — never from files, never logged:

- `EBAY_APP_ID` and `EBAY_CERT_ID`: an eBay Developers production
  keyset (used only for the OAuth client-credentials grant).
- `EBAY_EPN_CAMPAIGN_ID`: the operator's eBay Partner Network
  campaign id. It rides on every Browse request as the campaign
  header, it is what makes the returned URLs affiliate URLs, and
  commissions flow to that campaign's owner — whoever operates
  the server.

Without them the server still runs and answers: `resolve_product`
returns an empty result set with a note explaining the resolver is
built but not live. It never fabricates offers to fill the gap.

### Fixture mode

`PRODUCTS_FIXTURE_MODE=1` returns the bundled sample Browse
response for envelope testing. Fixture results are marked
`"fixture": true` with link type `fixture`, and the envelope
carries `data_source: "fixture"` plus a note saying the data is
not real offers and the URLs are not affiliate links.

## How it is put together

- `ebay_resolver.py` — the resolver itself (Python standard
  library only): query validation, Browse request construction
  with the campaign header, the envelope mapping rules, the live
  OAuth + Browse adapter, and the honest empty envelope.
- `mcp_server.py` — the FastMCP surface: three thin tools over
  the resolver, plus the `/health` route.
- `fixtures/browse_search_fixture.json` — the labeled sample
  Browse response used by fixture mode and the tests.
- `tests/` — the resolver rule battery (disclosure everywhere,
  URLs byte for byte, prices only from the response, dead and
  URL-less items dropped, campaign header required) and the MCP
  surface tests.

## Honest limits

- **One store today.** eBay only; Walmart is a named placeholder,
  not a hidden gap.
- **Category coverage is by keyword match.** The resolver
  validates the category slug and describes its scope, but leaf
  eBay taxonomy ids are deliberately not hardcoded — a wrong id
  would silently misroute queries. They get pinned from the eBay
  Taxonomy API by whoever operates the server with a live keyset.
- **No credentials, no offers.** By design: the honest empty
  envelope is the answer until a real keyset is present.
- **Prices move.** Every price is the store's price at its
  `checked_at` moment; a listing can sell out or reprice between
  the call and the click.

## License

MIT — see `LICENSE`.