lb_orders_list
Retrieve a paginated list of Amazon organic ranking orders, sorted newest first. View order status, campaign details, region, and issue report status for each order.
Instructions
List Listing Bureau orders (paginated, newest first). Includes order status, campaign, region, and issue report status.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number (default 1) | |
| per_page | No | Results per page (default 50, max 100) |
Implementation Reference
- src/tools/orders.tools.ts:22-43 (handler)The handler function for the lb_orders_list tool. It builds query params from page/per_page inputs, makes a GET request to /api/v1/orders, and formats the paginated result.
async (params) => { try { const query: Record<string, string> = {}; if (params.page !== undefined) query.page = String(params.page); if (params.per_page !== undefined) query.per_page = String(params.per_page); const res = await client.request<Order[]>( "GET", "/api/v1/orders", undefined, query, "lb_orders_list", ); if (res.meta) { return formatPaginatedResult(res.data, res.meta); } return formatResult(res.data); } catch (e) { return formatErrorResult(e); } }, - src/tools/orders.tools.ts:11-20 (schema)Input schema for lb_orders_list using Zod: optional 'page' (int >=1) and 'per_page' (int 1-100) parameters.
{ page: z.number().int().min(1).optional().describe("Page number (default 1)"), per_page: z .number() .int() .min(1) .max(100) .optional() .describe("Results per page (default 50, max 100)"), }, - src/tools/orders.tools.ts:7-9 (registration)Registration function registerOrdersTools that registers the tool on the MCP server via server.tool().
export function registerOrdersTools(server: McpServer, client: LBClient) { server.tool( "lb_orders_list", - src/utils/response.ts:60-78 (helper)formatPaginatedResult helper - formats the paginated API response with data and pagination metadata.
export function formatPaginatedResult( data: unknown, meta: { page: number; per_page: number; total: number; total_pages: number }, ): CallToolResult { const result = { data, pagination: meta, }; let text = JSON.stringify(result, null, 2); const notice = getUpdateNotice(); if (notice) { text += `\n\n${notice}`; } return { content: [{ type: "text", text }], }; } - src/client/lb-client.ts:188-270 (helper)The LBClient.request() method handles authenticated API requests, including 401 retry logic. The tool passes 'lb_orders_list' as the toolName for identification.
async request<T>( method: string, path: string, body?: Record<string, unknown>, query?: Record<string, string>, toolName?: string, ): Promise<ApiSuccessResponse<T>> { await this.ensureAuth(); const response = await this.doRequest<T>(method, path, body, query, toolName); // Single retry on 401 if (response.status === "error" && response._statusCode === 401) { this.jwt = null; await this.ensureAuth(); const retry = await this.doRequest<T>(method, path, body, query, toolName); if (retry.status === "error") { throw new LBApiError( retry._statusCode ?? 500, retry.error.code, retry.error.message, ); } return retry as ApiSuccessResponse<T>; } if (response.status === "error") { throw new LBApiError( response._statusCode ?? 500, response.error.code, response.error.message, ); } return response as ApiSuccessResponse<T>; } private async doRequest<T>( method: string, path: string, body?: Record<string, unknown>, query?: Record<string, string>, toolName?: string, ): Promise<ApiResponse<T> & { _statusCode?: number }> { let url = `${this.baseUrl}${path}`; if (query) { const params = new URLSearchParams( Object.entries(query).filter(([, v]) => v !== undefined && v !== ""), ); const qs = params.toString(); if (qs) url += `?${qs}`; } const headers: Record<string, string> = { Authorization: `Bearer ${this.jwt!.access_token}`, "X-LB-Source": "mcp", ...(toolName && { "X-LB-Tool": toolName }), }; const options: RequestInit = { method, headers }; if (body && method !== "GET") { headers["Content-Type"] = "application/json"; options.body = JSON.stringify(body); } const res = await fetch(url, options); // Note: non-JSON responses (e.g., gateway 502/401) throw here and bypass // the 401-retry path in request(). This is acceptable -- gateway-level 401s // are not recoverable via token refresh anyway. let json: ApiResponse<T>; try { json = (await res.json()) as ApiResponse<T>; } catch { throw new LBApiError( res.status, "PARSE_ERROR", `Server returned non-JSON response (HTTP ${res.status})`, ); } // Attach status code for retry logic return { ...json, _statusCode: res.status }; }