Skip to main content
Glama
Order Margin Exposure

Order Margin Exposure

by gptenv
README.md
# Order Margin Exposure

A stateless MCP service and HTTP report for checking which open customer quotes and orders may be affected by an upcoming supplier cost change. It matches exact SKUs, compares the effective date with each line's expected purchase date, estimates the gross-margin change if the sell price stays fixed, and suggests a quote price that preserves the current gross-margin dollars. It never updates an ERP, changes a quote, or interprets contract terms.

## Trial and pricing

- Free preview: one supplier SKU change and up to two open customer quote/order lines, with no account or external API.
- Full report: up to 500 supplier changes and 500 commitment lines for **0.04 USDC on Base** through x402, via Streamable HTTP MCP or `POST /v1/analyze`.
- Optional Stripe Checkout: **C$0.50** per report when `STRIPE_SECRET_KEY` is configured. Checkout binds the payment to a SHA-256 hash of the submitted report data. The same data must be supplied to retrieve the result. No input is retained.
- Manual options are listed at `/payments`. Manual transfers are reviewed by a person and are not automatically verified or credited to a report.

The free preview performs deterministic calculations in the Worker. It uses no paid model, database, external data API, or background job. A Stripe charge is attempted only after the customer starts Checkout.

## Connect an MCP client

Use the stateless Streamable HTTP endpoint:

```json
{
  "mcpServers": {
    "order-margin-exposure": {
      "url": "https://order-margin-exposure.defcronyke.workers.dev/mcp"
    }
  }
}
```

Call `preview_order_margin_exposure` for a small free result. For the full report, call `analyze_order_margin_exposure`; x402 compatible clients receive a payment challenge for 0.04 USDC on Base.

## HTTP API

- `GET /example` — synthetic input and free preview plus full sample report
- `POST /v1/preview` — free preview; caps input to one supplier change and two commitment rows
- `POST /v1/analyze` — full x402 gated report
- `POST /v1/stripe-checkout` — create a C$0.50 Stripe Checkout session when configured
- `POST /v1/stripe-result` — return a report only after Stripe confirms the same input hash was paid
- `GET /payments` — payment information and limitations
- `GET /openapi.json` — OpenAPI description
- `GET /.well-known/x402` — payment discovery
- `POST /mcp` — Streamable HTTP MCP

The request includes the cost-change SKU rows and commitments with reference, SKU, quantity, current sell price, whether the price is locked, line type, and expected purchase date. Use decimal strings for money, a three-letter currency code, and ISO calendar dates. Rows without an exact supplier SKU match remain unclassified. The service does not infer aliases, taxes, freight, discounts, exchange rates, supplier acceptance, or contract rights. Review the result before acting.

## Payment setup

Set `PAY_TO` to the seller's EVM address before deployment. To activate Stripe, store a SaladFinder Stripe secret as a Worker secret:

```sh
npx wrangler secret put STRIPE_SECRET_KEY
```

Until that secret is configured, Stripe routes return `503` and the payment page says Stripe is inactive. The application never writes the key to source control.

## Development

```sh
npm ci
npm test
npm run build
npx wrangler deploy
```

## Market context

The workflow is based on recurring supplier-spreadsheet cleanup questions and reports that price changes can leave open quotes and orders using stale costs. See [a small-business discussion of messy supplier Excel sheets](https://www.reddit.com/r/smallbusiness/comments/1y0ck2p/how_do_you_actually_handle_messy_supplier_excel/), [a distributor discussion of supplier price-list updates and open orders](https://www.reddit.com/r/InventoryManagement/comments/1xw1moq/how_do_distributors_actually_manage_supplier/), and this [supplier price-increase workflow guide](https://wholesalemanagers.com/articles-and-guides/your-supplier-wants-a-price-increase-how-to-assess-it-and-put-an-agreement-into-practice/). Existing procurement and pricing systems also serve this broader category; this tool is a small, input-only report for teams that need a review before changing their systems.

## License

MIT. See [LICENSE](LICENSE).