The getOrderStatus tool retrieves the current status information for a specific order by its numeric sequential orderId from the Firebase/Firestore database.
Important:
orderIdis the human-facing numeric ID stored as a field on the order document — not the Firestore document ID. If you have a Firestore document ID, usegetOrderByIdinstead.
tools/getOrderStatus.js
Retrieves essential status information for an order by querying the Orders collection where orderId == <number>. This is a lightweight alternative to getOrderById when you only need status information and you only know the numeric orderId.
{
orderId: number; // REQUIRED: Numeric sequential orderId (NOT the Firestore document ID)
}
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
orderId |
integer | Yes | - | Numeric sequential orderId (the human-facing ID). Use getOrderById if you have a Firestore document ID. |
{
status: OrderStatus | ErrorStatus;
}
{
orderId: number; // The numeric orderId
stage: number | null; // Current stage/status number (null if unset)
closed: boolean; // Whether the order is closed
title: string; // Order title (empty string if unset)
}
{
error: "not-found";
message: string; // Error message
}
// Get status for order with orderId 1234
const result = await getOrderStatus(context, {
orderId: 1234
});
if (result.status.error) {
console.log(result.status.message); // "Order 1234 not found"
} else {
console.log(`Order #${result.status.orderId}: ${result.status.title}`);
console.log(`Stage: ${result.status.stage}`);
console.log(`Closed: ${result.status.closed}`);
}
const result = await getOrderStatus(context, {
orderId: 1234
});
if (!result.status.error && result.status.closed) {
console.log("This order is closed");
} else if (!result.status.error) {
console.log(`Order is open, currently at stage ${result.status.stage}`);
}
const result = await getOrderStatus(context, {
orderId: 9999
});
if (result.status.error === "not-found") {
console.log("Order does not exist");
} else {
console.log("Order found:", result.status);
}
Unlike getOrderById, this tool searches by the orderId field rather than the Firestore document ID:
const q = query(
collection(db, "Accounts", accountId, "Orders"),
where("orderId", "==", Number(orderId)),
);
const snap = await getDocs(q);
Returns only essential status fields, with safe defaults for missing data:
return {
status: {
orderId: data.orderId,
stage: data.stage ?? null,
closed: !!data.closed,
title: data.title || "",
},
};
The tool uses the Zod inputSchema to validate that orderId is provided as an integer. Missing or non-integer values will throw a ZodError.
Returns a structured error response when no order matches the given orderId:
if (snap.empty) {
return {
status: {
error: "not-found",
message: `Order ${orderId} not found`,
},
};
}
| Error | Cause | Solution |
|---|---|---|
ZodError (orderId required / not an integer) |
Missing or non-numeric orderId |
Provide a numeric integer orderId in params |
Failed to fetch order status: ... |
Firestore error | Check Firebase connection and permissions |
When an order is not found, the tool returns a structured error object instead of throwing:
{
status: {
error: "not-found",
message: "Order 1234 not found"
}
}
Firestore errors are logged via the project logger and re-thrown:
catch (error) {
logger.error(`Error fetching order status for orderId=${orderId}:`, error);
throw new Error(`Failed to fetch order status: ${error.message}`);
}
orderId field which should be indexed in productionUse getOrderStatus when:
Use getOrderById when:
/Accounts/{accountId}/Orders/{documentId}
- orderId: number (queried field)
- stage: number
- closed: boolean
- title: string
- ... other fields