marketo_get_lead_lists
Fetch lead members of a Marketo static list by list ID, with pagination support via nextPageToken and batchSize, returning selected fields.
Instructions
Get leads that are members of a specific static list. Supports pagination via nextPageToken and batchSize.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listId | Yes | Static list ID | |
| fields | No | Lead field API names to return | |
| batchSize | No | Number of results per page (max 300) | |
| nextPageToken | No | Pagination token from previous response |
Implementation Reference
- src/tools/lists.ts:5-25 (registration)Registration of the 'marketo_get_lead_lists' tool via server.tool(), including its Zod schema definition and handler.
export function registerListTools(server: McpServer) { // ── marketo_get_lead_lists ───────────────────────────────────────────────── server.tool( "marketo_get_lead_lists", "Get leads that are members of a specific static list. Supports pagination via nextPageToken and batchSize.", { listId: z.number().describe("Static list ID"), fields: z.array(z.string()).optional().describe("Lead field API names to return"), batchSize: z.number().optional().describe("Number of results per page (max 300)"), nextPageToken: z.string().optional().describe("Pagination token from previous response"), }, async (args) => { try { const params: Record<string, unknown> = {}; if (args.fields?.length) params.fields = args.fields.join(","); if (args.batchSize) params.batchSize = args.batchSize; if (args.nextPageToken) params.nextPageToken = args.nextPageToken; return ok(await makeRequest(`/rest/v1/lists/${args.listId}/leads.json`, "GET", params)); } catch (e) { return err(e); } } ); - src/tools/lists.ts:16-24 (handler)Async handler function that constructs query parameters and calls makeRequest to GET /rest/v1/lists/{listId}/leads.json with optional fields, batchSize, and nextPageToken.
async (args) => { try { const params: Record<string, unknown> = {}; if (args.fields?.length) params.fields = args.fields.join(","); if (args.batchSize) params.batchSize = args.batchSize; if (args.nextPageToken) params.nextPageToken = args.nextPageToken; return ok(await makeRequest(`/rest/v1/lists/${args.listId}/leads.json`, "GET", params)); } catch (e) { return err(e); } } - src/tools/lists.ts:10-15 (schema)Zod schema defining input parameters: listId (required number), fields (optional string array), batchSize (optional number), nextPageToken (optional string).
{ listId: z.number().describe("Static list ID"), fields: z.array(z.string()).optional().describe("Lead field API names to return"), batchSize: z.number().optional().describe("Number of results per page (max 300)"), nextPageToken: z.string().optional().describe("Pagination token from previous response"), }, - src/client.ts:21-49 (helper)makeRequest helper function used by the handler to execute authenticated HTTP requests to the Marketo API.
export async function makeRequest<T = unknown>( endpoint: string, method: Method = "GET", data?: unknown, contentType?: string, ): Promise<T> { const token = await getAccessToken(); const config: AxiosRequestConfig = { url: `${MARKETO_BASE_URL}${endpoint}`, method, headers: { Authorization: `Bearer ${token}`, ...(contentType ? { "Content-Type": contentType } : {}), }, ...(data && method !== "GET" ? { data } : {}), ...(data && method === "GET" ? { params: data } : {}), }; const res = await axios(config); const body = res.data; // Marketo REST API returns errors inside the response body if (body?.errors?.length) { const e = body.errors[0]; throw new MarketoError(`${e.code}: ${e.message}`, res.status); } return body as T; } - src/client.ts:53-65 (helper)Response helpers ok() and err() used in the handler to format successful/error responses.
export function ok(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } export function err(e: unknown) { const msg = e instanceof Error ? e.message : String(e); return { isError: true, content: [{ type: "text" as const, text: `Error: ${msg}` }], }; }