Commit 87af369
authored
feat(mcp): add batch read tools — get_orders_batch, lookup_orders_batch, summarize_active_orders (#49)
Three new read tools that fan out parallel calls under the hood when
the StatusPro server has no native batch endpoint, eliminating the
per-item tool-call overhead for reconciliation flows.
### get_orders_batch(order_ids: list[int])
Fetch up to 50 orders by id in one tool call. Internally uses
asyncio.gather over client.orders.get; transport-layer 429 retry
handles rate-limit backoff. Returns a BatchOrderResponse with one
BatchOrderResult per requested id, partitioned into found vs error
(not_found, etc.) so the agent can act on partial-success batches.
Live timing (this tenant): 10 ids in 0.68s, 50 ids ~3-5s with
rate limiting.
### lookup_orders_batch(order_numbers: list[str])
Resolve up to 50 order numbers to orders in one tool call. Internally
uses list_orders(search=number) per number with EXACT-MATCH
disambiguation (search is fuzzy across order_number, name, customer
name, and email — blindly taking the first match risks false
positives). Marks ambiguous and not-found cases explicitly so callers
can see why a number didn't resolve.
Useful when an external system (e.g. Katana) hands you order numbers
without ids.
### summarize_active_orders()
One-shot dashboard. Returns counts of non-cancelled orders by:
- workflow status_code (one count per defined status)
- financial_status enum (paid, partially_paid, refunded, ...)
- fulfillment_status enum (fulfilled, partial, ...)
- "no status set" — active orders with no workflow code
Internally issues ~12 list calls in parallel; cached at the
response middleware (30s TTL). Replaces the manual paginate-per-
status-and-count pattern.
Live timing (this tenant, 475 active orders): 2.81s.
### Out of scope
- bulk_add_order_comment / bulk_update_order_due_date — server has no
native bulk endpoint AND add_order_comment is rate-limited to 5/min,
so a "batch" wrapper would just be slower than serial fan-out. Filed
as follow-up if a real need surfaces.
- True batching at the StatusPro server level — that's #32 (id[]
filter), still blocked on upstream feature request per #30 probes.
### Tests
11 new tests covering schema contracts (BatchOrderResult / Response,
ActiveOrdersSummary) and the exact-match disambiguation predicate
used by lookup_orders_batch (the non-trivial piece — verifies search
fuzziness doesn't silently produce false positives).
247 total tests pass.
Help resource updated with descriptions of all three. Tools added to
_READ_ONLY_TOOLS for response caching.1 parent f23fe4a commit 87af369
5 files changed
Lines changed: 761 additions & 4 deletions
File tree
- statuspro_mcp_server
- src/statuspro_mcp
- resources
- tools
- tests/tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
| |||
0 commit comments