Agent API & MCP Reference
The developer reference for the StockCraft Agent API and MCP server. For an overview of what agents can do, see the Agent API & MCP guide.
Endpoints
| Transport | URL |
|---|---|
MCP server (POST only) |
https://api-prod.stockcraft.org/mcp |
| REST base path | https://api-prod.stockcraft.org/api/v1/agent |
Both transports share one implementation. They use the same per-account API key and enforce the same scopes and tenant isolation. The Agent API deliberately does not expose generative-AI actions, user management, sign-in or MFA, subscription changes, billing or admin.
Authentication
Agents authenticate with a per-account API key of the form sk_live_<keyId><secret>.
- Create, list, rotate and revoke keys in the web app under Settings → Agent API keys. This needs an account administrator. The full secret is shown once, when the key is created.
- Send it as a bearer token on every request.
Authorization: Bearer sk_live_ab12cd...
- The key fixes the account. No request, tool argument or body can name or override it.
- Keys are stored hashed. A lost key is rotated, not recovered. Creating, revoking or rotating a key emails the account administrators.
- Every failed authentication returns the same
401. The API never reveals whether a key exists, is revoked or has expired.
Scopes
A key is granted a set of scopes when it is created. A call without the needed scope is refused
(403 on REST, a tool error on MCP).
| Scope | Grants | Plans |
|---|---|---|
read |
List, get and search products, materials, components, orders, customers, categories, suppliers, quotes and market events. Low stock report. | All |
write |
Create, update and delete single items, including products, components and orders. | All |
finance |
List, record, edit and delete expenses. Profit and loss report. | All |
bulk_import |
Bulk create and load rows, for onboarding a catalog. | All |
bulk_mutate |
Bulk edit of existing rows across a filter. | Plus only |
bulk_mutate is refused for a Free account when the key is created, and checked again on every call,
so downgrading after creating a key still blocks it. Bulk import is free on every plan.
REST surface
All paths are under /api/v1/agent and return JSON.
Reads (read)
| Method | Path | Purpose |
|---|---|---|
| GET | /whoami |
Account, granted scopes, key id and available areas. |
| GET | /{area}?limit=&cursor= |
List a page of an area. The response carries an opaque nextCursor. |
| GET | /{area}/{id} |
Get one item. |
| GET | /{area}/search?q= |
Search products, components and materials by name or SKU. |
| GET | /reports/low-stock-materials |
Materials below their reorder point. Optional nameFilter. |
{area} is one of products, variants, components,
materials, orders, customers, categories,
suppliers, quotes, marketevents.
Single-item writes (write)
| Method | Path | Notes |
|---|---|---|
| POST | /write/{area} |
Create. The server assigns the id and account. A client-supplied id or
tenantId is ignored. |
| PUT | /write/{area}/{id} |
Update. Include version in the body for optimistic concurrency. A mismatch returns
409. |
| DELETE | /write/{area}/{id} |
Delete. Repeating it is safe. |
Writable areas are materials, suppliers, categories,
customers, marketevents, products, components and
orders. Product and component writes recalculate cost, and a component update cascades to everything
that uses it. Every change is audited with source Agent.
Finance (finance)
| Method | Path | Purpose |
|---|---|---|
| GET | /finance/expenses?from=&to= |
Expenses in a date range (last 30 days by default). |
| POST | /finance/expenses |
Record an expense. |
| PUT | /finance/expenses/{id} |
Correct an expense. State only the fields to change. version opts into optimistic
concurrency. |
| DELETE | /finance/expenses/{id} |
Delete an expense record. |
| GET | /finance/profit-report?from=&to= |
Net revenue, cost of goods, gross profit, expenses and net profit. |
Expense edits accept only these fields: provider, reference, saleDate,
totalAmount, taxAmount, isTaxExempt, category,
categoryId, notes and items. An unknown field is refused, and the
claim and tax-reporting fields are never writable by an agent.
Bulk (bulk_import, bulk_mutate)
| Method | Path | Scope |
|---|---|---|
| POST | /bulk/{area}/import?apply=&planToken= |
bulk_import |
| POST | /bulk/{area}/mutate?apply=&planToken= |
bulk_mutate (Plus) |
| GET | /jobs/{id} |
read. Poll a background job. |
Bulk areas are materials, products and components.
Bulk safety: dry-run, then apply
Every bulk call is a dry-run by default. A dry-run changes nothing and returns:
affectedCount: how many rows the operation touches.- A bounded before-and-after
sample. cascadeImpact: how far a cost change rolls through your product costs.planToken: a single-use token tied to your account that binds this preview. It expires after 15 minutes.
To run it, call again with apply: true and that planToken. Apply checks that the affected
rows have not changed since the preview. If they have, the call is refused and you run the dry-run again. A
synchronous bulk call is capped at 1000 affected rows. Above that, an apply is accepted as a background job
(202 with a jobId), and you poll /jobs/{id} for its status and per-row
errors. Bulk changes run through the same logic as the app, so cost roll-ups stay correct.
MCP server
POST https://api-prod.stockcraft.org/mcp. The server speaks both MCP protocol eras:
- Handshake era (
2025-06-18): open withinitialize, then send thenotifications/initializednotification, which the server accepts with HTTP 202 and no body.pingworks before and after. - Stateless era (
2026-07-28): no handshake. Carry the version in theio.modelcontextprotocol/protocolVersionfield of_metaand/or theMCP-Protocol-Versionheader. If both are present they must agree, otherwise the error is-32020. An unsupported version returns-32022. Then callserver/discover.
server/discover returns supportedVersions, capabilities and
serverInfo. tools/list returns the tools your key can use and
tools/call runs one. A tools/call that fails because of its inputs, a missing scope, a
plan limit, a version conflict or a rate limit is a tool error (result.isError: true), not a
JSON-RPC error. A malformed request is a JSON-RPC -32xxx error, and retrying it is pointless.
Tools
| Tool | Scope |
|---|---|
stockcraft.whoami, stockcraft.list, stockcraft.get,
stockcraft.search, stockcraft.low_stock_materials,
stockcraft.products_by_sales_ranking |
read |
stockcraft.reorders.list, stockcraft.reorders.get,
stockcraft.order_states.list |
read |
stockcraft.create, stockcraft.update, stockcraft.delete,
stockcraft.recalculate_product_cost |
write |
stockcraft.reorders.create, stockcraft.reorders.update,
stockcraft.reorders.mark_received, stockcraft.reorders.cancel |
write |
stockcraft.orders.set_state |
write |
stockcraft.finance.list_expenses, stockcraft.finance.record_expense,
stockcraft.finance.update_expense, stockcraft.finance.delete_expense,
stockcraft.finance.profit_report |
finance |
stockcraft.bulk_import |
bulk_import |
stockcraft.bulk_mutate |
bulk_mutate (Plus) |
Example: raise the reorder point on every LED strip material. Run it as a dry-run first, then send the returned
planToken with apply: true.
{ "name": "stockcraft.bulk_mutate",
"arguments": {
"area": "materials",
"filter": { "field": "Name", "value": "LED strip" },
"patch": { "reorderPoint": 50 } } }
Rate limits
- Read and write: a per-account budget, keyed on the key and account rather than IP address and
split by operation type. Exceeding it returns
429with aRetry-Afterheader. - Bulk: a per-account budget charged by affected rows when you apply. A dry-run costs nothing.
Exceeding it returns
429, or a tool error with a retry hint.
The limits are there to stop a runaway loop, not to restrict normal agent work such as bulk loads and reporting sweeps.
Quickstart
- In Settings → Agent API keys, create a key with the scopes your agent needs and copy the
sk_live_...secret. - Point your MCP client at
https://api-prod.stockcraft.org/mcpwithAuthorization: Bearer sk_live_.... - Run
server/discoverandtools/list, then callstockcraft.whoamito confirm your account and scopes. - To load a catalog, call
stockcraft.bulk_importas a dry-run, review the sample, then apply with theplanToken.