marketo_add_lead_to_list
Add one or more leads to a Marketo static list by providing the list ID and an array of lead IDs, up to 300 per request.
Instructions
Add one or more leads to a static list by list ID. Accepts an array of lead IDs. Max 300 leads per call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listId | Yes | ||
| leadIds | Yes |
Implementation Reference
- src/index.ts:388-400 (registration)Registration of the 'marketo_add_lead_to_list' tool via server.tool() with name, description, schema, and handler.
server.tool( 'marketo_add_lead_to_list', 'Add one or more leads to a static list by list ID. Accepts an array of lead IDs. Max 300 leads per call.', { listId: z.number(), leadIds: z.array(z.number()), }, tool(async ({ listId, leadIds }) => makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', { input: leadIds.map(id => ({ id })), }) ) ); - src/index.ts:391-394 (schema)Input schema for the tool: listId (z.number()) and leadIds (z.array(z.number())).
{ listId: z.number(), leadIds: z.array(z.number()), }, - src/index.ts:395-399 (handler)Handler function that calls makeApiRequest with POST to /rest/v1/lists/{listId}/leads.json, mapping leadIds to the required Marketo input format.
tool(async ({ listId, leadIds }) => makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', { input: leadIds.map(id => ({ id })), }) ) - src/index.ts:23-54 (helper)The makeApiRequest helper function used by the handler to execute the Marketo REST API call.
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-74 (helper)The tool() wrapper helper that handles response formatting and error wrapping for tool handlers.
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, }; } }; }