marketo_get_lead_activities
Retrieve timestamped activity records for a specific lead, filterable by activity type IDs like Visit Web Page or Send Email. Supports pagination via nextPageToken for efficient log browsing.
Instructions
Get activity log for a specific lead. Filter by activity type IDs (e.g. 1=Visit Web Page, 6=Send Email). Supports pagination via nextPageToken. Returns timestamped activity records.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| leadId | Yes | Lead ID to get activities for | |
| activityTypeIds | No | Filter to specific activity type IDs | |
| nextPageToken | No | Pagination token from previous response | |
| batchSize | No | Number of results per page (max 300) |
Implementation Reference
- src/tools/leads.ts:77-96 (registration)Tool registration for marketo_get_lead_activities. Calls server.tool() with name, description, Zod schema for leadId/activityTypeIds/nextPageToken/batchSize, and an async handler.
// ── marketo_get_lead_activities ──────────────────────────────────────────── server.tool( "marketo_get_lead_activities", "Get activity log for a specific lead. Filter by activity type IDs (e.g. 1=Visit Web Page, 6=Send Email). Supports pagination via nextPageToken. Returns timestamped activity records.", { leadId: z.number().describe("Lead ID to get activities for"), activityTypeIds: z.array(z.number()).optional().describe("Filter to specific activity type IDs"), nextPageToken: z.string().optional().describe("Pagination token from previous response"), batchSize: z.number().optional().describe("Number of results per page (max 300)"), }, async (args) => { try { const params: Record<string, unknown> = {}; if (args.activityTypeIds?.length) params.activityTypeIds = args.activityTypeIds.join(","); if (args.nextPageToken) params.nextPageToken = args.nextPageToken; if (args.batchSize) params.batchSize = args.batchSize; return ok(await makeRequest(`/rest/v1/activities/lead/${args.leadId}.json`, "GET", params)); } catch (e) { return err(e); } } ); - src/tools/leads.ts:87-95 (handler)Async handler that builds query params (activityTypeIds joined as comma string, nextPageToken, batchSize) and calls makeRequest to GET /rest/v1/activities/lead/{leadId}.json. Returns result via ok() helper, catches errors via err().
async (args) => { try { const params: Record<string, unknown> = {}; if (args.activityTypeIds?.length) params.activityTypeIds = args.activityTypeIds.join(","); if (args.nextPageToken) params.nextPageToken = args.nextPageToken; if (args.batchSize) params.batchSize = args.batchSize; return ok(await makeRequest(`/rest/v1/activities/lead/${args.leadId}.json`, "GET", params)); } catch (e) { return err(e); } } - src/tools/leads.ts:81-86 (schema)Zod input schema: leadId (number, required), activityTypeIds (array of numbers, optional), nextPageToken (string, optional), batchSize (number, optional).
{ leadId: z.number().describe("Lead ID to get activities for"), activityTypeIds: z.array(z.number()).optional().describe("Filter to specific activity type IDs"), nextPageToken: z.string().optional().describe("Pagination token from previous response"), batchSize: z.number().optional().describe("Number of results per page (max 300)"), }, - src/client.ts:21-49 (helper)makeRequest function that handles authenticated HTTP requests to the Marketo API, used by the tool handler.
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; } - src/client.ts:53-65 (helper)ok() and err() response formatters that wrap results in the MCP content format.
export function ok(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } export function err(e: unknown) { const msg = e instanceof Error ? e.message : String(e); return { isError: true, content: [{ type: "text" as const, text: `Error: ${msg}` }], }; }