marketo_add_lead_to_list
Add leads to a Marketo list by specifying list ID and lead IDs to organize and manage marketing contacts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listId | Yes | ||
| leadIds | Yes |
Implementation Reference
- src/index.ts:646-664 (handler)The handler function that adds specified lead IDs to a Marketo list by constructing input data and making a POST request to the Marketo Leads API endpoint /rest/v1/lists/{listId}/leads.json. Returns the API response as text or an error message.async ({ listId, leadIds }) => { try { const data = { input: leadIds.map(id => ({ id })), }; const response = await makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', data); return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error: ${error.response?.data?.message || error.message}` }, ], }; } }
- src/index.ts:642-645 (schema)Zod input schema defining listId as number and leadIds as array of numbers.{ listId: z.number(), leadIds: z.array(z.number()), },
- src/index.ts:640-665 (registration)Registration of the tool using McpServer.tool method with name 'marketo_add_lead_to_list', input schema, and inline handler function.server.tool( 'marketo_add_lead_to_list', { listId: z.number(), leadIds: z.array(z.number()), }, async ({ listId, leadIds }) => { try { const data = { input: leadIds.map(id => ({ id })), }; const response = await makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', data); return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error: ${error.response?.data?.message || error.message}` }, ], }; } } );
- src/index.ts:22-52 (helper)Shared helper function used by the tool to make authenticated HTTP requests to the Marketo API using axios, handling token retrieval and content types.async function makeApiRequest( endpoint: string, method: string, data?: any, contentType: string = 'application/json' ) { const token = await tokenManager.getToken(); const headers: any = { Authorization: `Bearer ${token}`, }; if (contentType) { headers['Content-Type'] = contentType; } try { const response = await axios({ url: `${MARKETO_BASE_URL}${endpoint}`, method: 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; } }