marketo_add_leads_to_list
Add leads to a Marketo static list by providing lead IDs, up to 300 per request.
Instructions
Add one or more leads to a static list by lead IDs. Max 300 leads per call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listId | Yes | Static list ID | |
| leadIds | Yes | Array of lead IDs to add (max 300) |
Implementation Reference
- src/tools/lists.ts:35-46 (handler)The handler function that executes the 'marketo_add_leads_to_list' tool logic. It maps lead IDs to {id} objects, then POSTs to Marketo's /rest/v1/lists/{listId}/leads.json with an application/json content type.
async (args) => { try { const input = args.leadIds.map(id => ({ id })); return ok(await makeRequest( `/rest/v1/lists/${args.listId}/leads.json`, "POST", { input }, "application/json" )); } catch (e) { return err(e); } } ); - src/tools/lists.ts:31-34 (schema)Zod schema definitions for the tool: 'listId' (number) and 'leadIds' (array of numbers, max 300 leads per call).
{ listId: z.number().describe("Static list ID"), leadIds: z.array(z.number()).describe("Array of lead IDs to add (max 300)"), }, - src/tools/lists.ts:28-46 (registration)Registration of the tool via server.tool('marketo_add_leads_to_list', ...) inside the registerListTools() function.
server.tool( "marketo_add_leads_to_list", "Add one or more leads to a static list by lead IDs. Max 300 leads per call.", { listId: z.number().describe("Static list ID"), leadIds: z.array(z.number()).describe("Array of lead IDs to add (max 300)"), }, async (args) => { try { const input = args.leadIds.map(id => ({ id })); return ok(await makeRequest( `/rest/v1/lists/${args.listId}/leads.json`, "POST", { input }, "application/json" )); } catch (e) { return err(e); } } ); - src/index.ts:26-29 (registration)The registerListTools(server) call that wires up all list tools including marketo_add_leads_to_list.
registerListTools(server); registerChannelTools(server); registerLandingPageTools(server); registerBulkExportTools(server); - src/client.ts:21-49 (helper)The makeRequest helper function used by the handler to perform the authenticated HTTP request 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; }