marketo_get_lead_activities
Retrieve activity records for a specified lead. Optionally filter by activity type IDs to target specific actions. Uses cursor-based pagination for efficient data retrieval.
Instructions
Fetch activity records for a specific lead. Filter by activity type IDs (e.g., 1=Visit Webpage, 2=Fill Out Form, 6=Send Email). Supports cursor-based pagination via nextPageToken.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| leadId | Yes | ||
| activityTypeIds | No | ||
| nextPageToken | No | ||
| batchSize | No |
Implementation Reference
- src/index.ts:315-344 (registration)Registration of the 'marketo_get_lead_activities' tool on the MCP server using server.tool(), with input schema and handler.
server.tool( 'marketo_delete_lead', 'Permanently delete a lead by its numeric ID. This action cannot be undone.', { leadId: z.number() }, tool(async ({ leadId }) => makeApiRequest(`/rest/v1/leads/${leadId}/delete.json`, 'POST')) ); // ============================================================================ // Marketo Lead Database API — Activities // ============================================================================ server.tool( 'marketo_get_lead_activities', 'Fetch activity records for a specific lead. Filter by activity type IDs (e.g., 1=Visit Webpage, 2=Fill Out Form, 6=Send Email). Supports cursor-based pagination via nextPageToken.', { leadId: z.number(), activityTypeIds: z.array(z.number()).optional(), nextPageToken: z.string().optional(), batchSize: z.number().optional(), }, tool(async ({ leadId, activityTypeIds, nextPageToken, batchSize = 100 }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (activityTypeIds) params.append('activityTypeIds', activityTypeIds.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/activities/lead/${leadId}.json?${params.toString()}`, 'GET' ); }) ); - src/index.ts:335-343 (handler)Handler logic: builds query parameters (batchSize, activityTypeIds, nextPageToken) and calls makeApiRequest to GET /rest/v1/activities/lead/{leadId}.json.
tool(async ({ leadId, activityTypeIds, nextPageToken, batchSize = 100 }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (activityTypeIds) params.append('activityTypeIds', activityTypeIds.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/activities/lead/${leadId}.json?${params.toString()}`, 'GET' ); }) - src/index.ts:329-334 (schema)Input schema using Zod: leadId (number, required), activityTypeIds (optional array of numbers), nextPageToken (optional string), batchSize (optional number).
{ leadId: z.number(), activityTypeIds: z.array(z.number()).optional(), nextPageToken: z.string().optional(), batchSize: z.number().optional(), }, - src/index.ts:23-53 (helper)Helper function makeApiRequest that handles authentication, HTTP requests, and error formatting for all Marketo API calls.
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)Helper wrapper function 'tool' that wraps handlers with try/catch and formats the MCP response content.
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, }; } }; }