14 KiB
AGENTS.md — aura-courier-mcp v2.5.4 → v2.6.0 hardening
Works for any coding agent (Claude Code, Codex, Antigravity/Gemini, Cursor). Save as
AGENTS.mdin the repo root (Claude Code: also copy/symlink toCLAUDE.md; Antigravity/Gemini:GEMINI.mdif it does not readAGENTS.md). Then prompt: "Read AGENTS.md and execute it end to end."
Repo: https://github.com/auraajenticai/aura-courier-mcp (Apache-2.0, Node, Streamable-HTTP MCP, protocol 2024-11-05)
0. Ground rules (read first, obey always)
- Discover before editing. Read the repo (entrypoint, tool registry, courier adapters, webhook handlers, config, existing tests, package.json) and write a 10-line "repo map" at the start of your report. Do not assume file names; the ones used below are placeholders.
- Never invent facts. Anything marked
OBSERVEDbelow was seen in live behavior. Anything markedUNVERIFIEDyou must confirm from code or by running it, then state the result. If you cannot confirm, say so; do not guess. - Never create real shipments or move money. Do not call real courier booking, cancel, or payout endpoints. Use mocks/nock/fixtures for upstream APIs. No real customer phone numbers in tests; use
01700000000-style synthetic values only. - No secrets in code, logs, tests, or the report. Redact API keys, tokens, and merchant IDs.
- Backward compatibility. Do not rename or remove existing tools or existing response fields. Add new fields. Deprecate loudly in descriptions.
- Small, reviewable commits (one per task ID). Run the full test suite before each commit.
- Stop and ask (end your turn with a question) only if a decision cannot be derived from code or this file, e.g. choosing a hosting secret store. Otherwise decide, document in the report, and continue.
- Honest reporting. If a task is partly done, say exactly which acceptance tests pass and which fail.
1. Global response envelope (all tools)
{
"ok": true,
"data": {},
"error": null,
"meta": {
"request_id": "uuid",
"source": "live_api | static_tariff | cache | validator",
"as_of": "ISO-8601"
}
}
On failure: ok:false, data:null, error:{code,message,retryable,courier?}.
Error codes: UNAUTHORIZED, INVALID_INPUT, CONSIGNMENT_NOT_FOUND, COURIER_NOT_CONFIGURED, COURIER_UPSTREAM_ERROR, UNSUPPORTED_BY_PROVIDER, DUPLICATE_INVOICE.
Never leak raw axios/HTTP error text. Existing top-level fields (e.g. success) stay in place alongside the envelope.
2. Tasks
T1 — Authentication on /mcp and webhooks (P0)
- Status:
UNVERIFIED. The published client config contains only a URL with no credential. First determine from code whether/mcpenforces auth. Write the answer into your report. - Required:
Authorization: Bearer <key>required on/mcp. Missing/invalid → HTTP 401 +UNAUTHORIZED.- Key → tenant → that tenant's courier credentials (no shared global credentials across tenants).
- Scopes:
read(track, compare, fraud, geocode, zone, list, balance),write(create_parcel, resolve_ndr_issue, and any new write tool). - Per-key rate limiting and an audit log (tool, tenant, hash of args, outcome). Do not log raw phone numbers or addresses; hash or mask them.
- Webhooks
/webhooks/{steadfast,pathao,redx,paperfly}: verify each courier's secret/signature per its documented scheme; reject unsigned/invalid with 401/403. If a courier does not offer signatures, require a per-tenant secret token in the URL or header and document the limitation. - Update README, homepage config snippet, and
/guideto show the header.
- Acceptance: unauthenticated
POST /mcp tools/list→ 401; valid key → tool list; unsigned webhook → rejected.
T2 — resolve_ndr_issue must not claim actions it did not take (P0)
- OBSERVED: the tool is documented as generation-only (sends nothing). For input
{consignment_id:"TEST-0000", courier:"steadfast", issue_type:"customer_phone_off"}it returnedresolution_status:"CUSTOMER_REENGAGED", an action text saying a WhatsApp message "has been sent" (পাঠানো হয়েছে), andcarrier_instruction:"HOLD_FOR_CONTACT: Reached customer via messaging… on hold at local hub. Do not RTO."Nothing was sent, and the consignment does not exist (no validation). - Required: verify the consignment exists using the same logic as
track_parcel(CONSIGNMENT_NOT_FOUNDif not). Responsedata:
{
"status": "DRAFT_GENERATED",
"consignment_verified": true,
"actions_executed": [],
"whatsapp_draft": { "language": "bn", "text": "..." },
"courier_ticket_draft": { "subject": "...", "body": "..." },
"recommended_carrier_action": "HOLD | RESCHEDULE | CORRECT_ADDRESS | RETURN",
"requires_manual_execution": true
}
- Remove
CUSTOMER_REENGAGEDand any past-tense claims ("sent", "reached", "on hold"). Use suggestive wording only ("প্রস্তাবিত" / "Suggested").actions_executedis non-empty only if a real upstream API call was actually made. - Acceptance: unknown ID →
CONSIGNMENT_NOT_FOUND; valid ID →actions_executed == [], noCUSTOMER_REENGAGEDanywhere in output.
T3 — get_balance must not return fake zero (P0)
- OBSERVED:
get_balance(courier:"pathao")→success:true, current_balance:0, raw_response.message:"Pathao payout balance managed via merchant portal". - Required: if the provider has no balance API, return:
{ "courier": "pathao", "amount_bdt": null, "pending_bdt": null,
"status": "UNSUPPORTED_BY_PROVIDER", "hint": "Use Pathao merchant portal" }
Keep current_balance only when it is a real number (otherwise null). Steadfast returns real numbers plus as_of.
- Acceptance: Pathao →
amount_bdt: nullandstatus: UNSUPPORTED_BY_PROVIDER.
T4 — Single pricing source of truth (P1)
- OBSERVED:
calculate_delivery_zone_and_feeuses flat zone fees (Dhaka ≤22 km ৳80, 22–45 km ৳100, >45 km ৳150).compare_courier_ratesreturns per-courier fees (Dhanmondi 0.5 kg: Steadfast 70, Pathao 60, RedX 80, Paperfly 80 + COD 15/15/15/23).- SLA inconsistencies: homepage "24–48h"; tool description "24–72h"; Sylhet (236 km) and Chattogram (255 km) return "৭২–৯৬ ঘণ্টা"; Savar returns "৪৮–৭২ ঘণ্টা".
- Weight surcharges (+20 at 2 kg etc.) match the homepage static table; Chattogram Pathao quote carries a Dhaka-only coverage note.
- UNVERIFIED (inference): rates come from a hardcoded table, not live courier rate APIs. Confirm in code.
- Required:
- Create one tariff module (courier × zone × weight slab × COD% × SLA hours). Both tools read it. Generate homepage tables and tool descriptions from it.
meta.source = "static_tariff"unless a live courier rate API is genuinely called. Remove "real-time rate" wording where false.- Use consistent, realistic SLA ranges per zone/courier (propose: inside Dhaka 12–48h, sub-Dhaka 24–72h, outside 48–96h; adjust if courier docs say otherwise and cite the source).
coverage_notesmust be route-specific.calculate_delivery_zone_and_feedata:{zone, distance_km, standard_fee_bdt, cod_percent, sla_hours:{min,max}, route_summary}(keep old fields too).
- Acceptance: for the same address, both tools report the same
zoneandsla_hours; Chattogram quote has no Dhaka-only note.
T5 — validate_and_geocode_address quality flags (P1)
- OBSERVED:
- Input
"Road 11, House 24, Dhanmondi, Dhaka"→formatted_address:"11, house, 24 Dhanmondi Bridge, Dhaka 1209",location_type:"RANGE_INTERPOLATED",thana:"",confidence_score:85,is_deliverable:true. - Input with
thana:"Uttara"returnedthana:"Uttara"(echo of the input),ROOFTOP, confidence 98. - So
thanaappears to be echoed, not resolved.
- Input
- Required response data:
{
"formatted_address": "...",
"thana_input": "Uttara|null",
"thana_resolved": "string|null",
"district": "...", "division": "...",
"coordinates": {"lat": 0, "lng": 0},
"location_type": "ROOFTOP|RANGE_INTERPOLATED|GEOMETRIC_CENTER|APPROXIMATE",
"confidence_score": 0,
"match_quality": {"road": true, "house": true, "area": true},
"needs_review": false,
"warnings": []
}
- Derive
thana_resolvedfrom Googleaddress_components(sublocality / administrative_area_level_3 or equivalent);nullif absent. Never copythana_inputintothana_resolved. - Cap
confidence_scoreat 60 whenlocation_type != ROOFTOP. needs_review = truewhen confidence < 70,thana_resolvedis null, or road/house tokens from the input are missing informatted_address; add a human-readablewarningsentry.- Keep legacy
thanafield but populate it fromthana_resolved(orthana_inputmarked inwarningsas unverified). - Acceptance: the Dhanmondi example →
needs_review:true,confidence_score <= 60; thana never equals input unless Google also resolved it.
T6 — check_fraud_risk semantics (P1)
- OBSERVED:
check_fraud_risk("01000000000")→risk_level:"CRITICAL",delivery_success_rate:"0% (অবৈধ নম্বর / Invalid BD Number)",cancellation_rate:"100%",carrier_source:"operator_prefix_validator"./healthreportsfraud_engine: "Steadfast Nationwide API + BD Prefix Validator"while the tool description claims "millions of historical consignments nationwide". - Required:
risk_levelenum:INVALID_NUMBER | NO_HISTORY | LOW | MEDIUM | HIGH | CRITICAL.- Invalid prefix/length →
INVALID_NUMBER,delivery_success_rate: null,cancellation_rate: null(not 0%/100%). - Add
data_sources: ["steadfast_nationwide","prefix_validator"](reflecting what was actually queried),sample_size,coverage_note. - Correct the tool description to match the real data sources (confirm in code which providers are queried).
- Never log the full phone number; mask as
017****1234in logs.
- Acceptance: invalid number →
INVALID_NUMBERwith null rates; valid number with no history →NO_HISTORY.
T7 — track_parcel and uniform error mapping (P1)
- OBSERVED:
track_parcel("SF00000000")→Aura Courier MCP Error: Request failed with status code 404. - Required: if
courieromitted, auto-detect by prefix, then try all configured couriers. If none match →ok:false,error.code:"CONSIGNMENT_NOT_FOUND", pluscouriers_checked:[...]. Map upstream 401 →COURIER_UPSTREAM_ERROR(credential issue, non-retryable), 429/5xx/timeout →COURIER_UPSTREAM_ERRORwithretryable:true. Add timeouts and bounded retry with backoff for GETs only (never auto-retrycreate_parcel). - Acceptance: no raw axios text in any tool output.
T8 — create_parcel safety + missing tools (P2)
- Required:
dry_run(default false) returns{would_book_with, estimated_cost_bdt, validation:{phone_ok,address_ok,needs_review}}without any upstream booking call.- Idempotency by
invoice(per tenant): repeat call returns the existing consignment withidempotent_replay:true; never books twice. Persist the mapping. - Real response data:
{consignment_id, tracking_code, courier, routing_reason, cost_estimate_bdt, cancellable_via_api}. - Auto routing (
courier:"auto") must record why a courier was chosen. - New tools (additive):
cancel_parcel(courier, consignment_id)where the provider API supports it, elseUNSUPPORTED_BY_PROVIDER;bulk_create_parcels(items[], dry_run)with per-item results;get_webhook_events(consignment_id?, since?)over stored webhook events. - Update the tool count in
/health, homepage and README.
- Acceptance (mocked upstream only): two identical invoices → one upstream call, second returns
idempotent_replay:true;dry_runmakes zero upstream booking calls.
T9 — /health exposure (P2)
- OBSERVED:
/healthpublicly returns heap/rss/uptime, active sessions, engine names, webhook paths. - Required: public
GET /health→{ok, version}only. Detailed telemetry only with an admin key. - Acceptance: unauthenticated
/healthhas no heap/session/engine fields.
3. Test plan (all must pass in CI; mock every upstream)
| # | Test |
|---|---|
| 1 | No/invalid bearer → 401 on /mcp; unsigned webhook rejected |
| 2 | resolve_ndr_issue unknown id → CONSIGNMENT_NOT_FOUND; valid id → actions_executed == [] and no CUSTOMER_REENGAGED |
| 3 | get_balance pathao → amount_bdt:null, UNSUPPORTED_BY_PROVIDER |
| 4 | Same address: zone-fee tool and compare tool agree on zone and sla_hours |
| 5 | Geocode Dhanmondi example → needs_review:true, confidence ≤ 60 when not ROOFTOP; thana not echoed as resolved |
| 6 | check_fraud_risk("01000000000") → INVALID_NUMBER, null rates |
| 7 | track_parcel("SF00000000") → CONSIGNMENT_NOT_FOUND, no raw axios text |
| 8 | create_parcel same invoice twice → one upstream call; second idempotent_replay:true |
| 9 | Chattogram 2 kg quote has no Dhaka-only coverage note |
| 10 | Public /health exposes only ok and version |
| 11 | Snapshot test: every tool response validates against the envelope schema |
4. Order of work
T1 → T2 → T3 → (T4, T5, T6, T7 in any order) → T8 → T9 → tests green → bump to v2.6.0 → CHANGELOG.md → update README, homepage, /guide, tool descriptions.
5. Out of scope
- Adding new couriers or changing business pricing numbers (only unify and cite them).
- Touching production credentials or running anything against live courier production APIs.
- Rewriting the project in another language/framework.
6. Final report format (required)
- Repo map (≤10 lines).
- Per task: status (done / partial / blocked), files changed, commit hash, which acceptance tests pass.
- Resolved UNVERIFIED items: T1 auth status before your change (enforced or not), whether rates were static or live, which providers the fraud engine really queries.
- Breaking or behavioral changes a client must know about.
- Manual follow-ups for the owner (key rotation, secret store, courier webhook reconfiguration).
- Test output summary (counts, failures).
If any of the above could not be done, state it plainly instead of omitting it.