marketo_create_or_update_leads
Batch create or update up to 300 leads in Marketo using email dedup. Choose create, update, or upsert action to sync lead data.
Instructions
Batch create or update leads in Marketo. Upserts up to 300 leads per call. Uses 'email' as the default dedup field. Set action to createOnly, updateOnly, or createOrUpdate.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Array of lead objects (max 300). Each must include a dedup key like 'email'. | |
| action | No | Sync action | createOrUpdate |
| lookupField | No | Field used for deduplication |
Implementation Reference
- src/tools/leads.ts:52-61 (handler)The async handler function that executes the logic for marketo_create_or_update_leads. It calls makeRequest to POST to /rest/v1/leads.json with the action, lookupField, and input array.
async (args) => { try { return ok(await makeRequest("/rest/v1/leads.json", "POST", { action: args.action, lookupField: args.lookupField, input: args.input, }, "application/json")); } catch (e) { return err(e); } } ); - src/tools/leads.ts:48-51 (schema)Zod schema for the tool's input parameters: input (array of lead objects), action (enum: createOnly/updateOnly/createOrUpdate, default createOrUpdate), lookupField (string, default 'email').
input: z.array(z.record(z.unknown())).describe("Array of lead objects (max 300). Each must include a dedup key like 'email'."), action: z.enum(["createOnly", "updateOnly", "createOrUpdate"]).default("createOrUpdate").describe("Sync action"), lookupField: z.string().default("email").describe("Field used for deduplication"), }, - src/tools/leads.ts:44-61 (registration)Registration of the tool on the MCP server via server.tool() with name 'marketo_create_or_update_leads' and its description.
server.tool( "marketo_create_or_update_leads", "Batch create or update leads in Marketo. Upserts up to 300 leads per call. Uses 'email' as the default dedup field. Set action to createOnly, updateOnly, or createOrUpdate.", { input: z.array(z.record(z.unknown())).describe("Array of lead objects (max 300). Each must include a dedup key like 'email'."), action: z.enum(["createOnly", "updateOnly", "createOrUpdate"]).default("createOrUpdate").describe("Sync action"), lookupField: z.string().default("email").describe("Field used for deduplication"), }, async (args) => { try { return ok(await makeRequest("/rest/v1/leads.json", "POST", { action: args.action, lookupField: args.lookupField, input: args.input, }, "application/json")); } catch (e) { return err(e); } } ); - src/index.ts:22-29 (registration)Registration of the registerLeadTools function which registers all lead-related tools including marketo_create_or_update_leads.
registerLeadTools(server); registerProgramTools(server); registerEmailTools(server); registerSmartListTools(server); registerListTools(server); registerChannelTools(server); registerLandingPageTools(server); registerBulkExportTools(server); - src/client.ts:21-49 (helper)The makeRequest helper that executes authenticated HTTP requests to the Marketo REST API. Called by the tool handler with POST method and 'application/json' content type.
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; }