marketo_get_lead_lists
Retrieve all static lists associated with a lead using Marketo API. Supports cursor-based pagination to handle large results.
Instructions
Get all static lists that a lead belongs to. Supports cursor-based pagination via nextPageToken. Returns list IDs and names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| leadId | Yes | ||
| batchSize | No | ||
| nextPageToken | No |
Implementation Reference
- src/index.ts:370-386 (registration)Registration of the 'marketo_get_lead_lists' tool on the MCP server with name, description, and Zod schema.
server.tool( 'marketo_get_lead_lists', 'Get all static lists that a lead belongs to. Supports cursor-based pagination via nextPageToken. Returns list IDs and names.', { leadId: z.number(), batchSize: z.number().optional(), nextPageToken: z.string().optional(), }, tool(async ({ leadId, batchSize = 100, nextPageToken }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/lists/${leadId}/leads.json?${params.toString()}`, 'GET' ); }) ); - src/index.ts:373-377 (schema)Zod schema defining input parameters: leadId (number, required), batchSize (optional number), nextPageToken (optional string).
{ leadId: z.number(), batchSize: z.number().optional(), nextPageToken: z.string().optional(), }, - src/index.ts:378-385 (handler)Handler function for 'marketo_get_lead_lists' - constructs URL with leadId, batchSize, and optional nextPageToken parameters, then calls makeApiRequest with GET method.
tool(async ({ leadId, batchSize = 100, nextPageToken }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/lists/${leadId}/leads.json?${params.toString()}`, 'GET' ); }) - src/index.ts:23-53 (helper)Helper function called by the handler - makeApiRequest performs the actual HTTP GET request to the Marketo API with authentication headers.
async function makeApiRequest( endpoint: string, method: string, data?: any, contentType: string = 'application/json' ) { const token = await tokenManager.getToken(); const headers: Record<string, string> = { Authorization: `Bearer ${token}`, }; if (contentType) { headers['Content-Type'] = contentType; } try { const response = await axios({ url: `${MARKETO_BASE_URL}${endpoint}`, method, data: contentType === 'application/x-www-form-urlencoded' ? new URLSearchParams(data).toString() : data, headers, }); return response.data; } catch (error: any) { console.error('API request failed:', error.response?.data || error.message); throw error; } } - src/index.ts:55-73 (helper)Helper 'tool' wrapper function that wraps the handler with try/catch and formats the response as MCP content with JSON stringification.
function tool<T>(handler: (args: T) => Promise<unknown>) { return async (args: T) => { try { const response = await handler(args); return { content: [{ type: 'text' as const, text: JSON.stringify(response, null, 2) }], }; } catch (error: any) { return { content: [ { type: 'text' as const, text: `Error: ${error.response?.data?.message || error.message}`, }, ], isError: true, }; } };