marketo_get_lead_changes
Retrieve field-change history for a lead to audit data changes and track lifecycle progression. Optionally filter by specific fields.
Instructions
Fetch field-change history for a specific lead. Optionally filter to specific field names. Useful for auditing data changes and tracking lead lifecycle progression.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| leadId | Yes | ||
| fields | No | ||
| nextPageToken | No | ||
| batchSize | No |
Implementation Reference
- src/index.ts:355-363 (handler)The handler function for the marketo_get_lead_changes tool. It constructs query parameters (batchSize, fields, nextPageToken) and makes a GET request to the Marketo API endpoint /rest/v1/activities/lead/{leadId}/changes.json.
tool(async ({ leadId, fields, nextPageToken, batchSize = 100 }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (fields) params.append('fields', fields.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/activities/lead/${leadId}/changes.json?${params.toString()}`, 'GET' ); }) - src/index.ts:349-353 (schema)Input schema for the tool, using Zod validation: leadId (number, required), fields (array of strings, optional), nextPageToken (string, optional), batchSize (number, optional).
{ leadId: z.number(), fields: z.array(z.string()).optional(), nextPageToken: z.string().optional(), batchSize: z.number().optional(), - src/index.ts:346-364 (registration)Registration of the marketo_get_lead_changes tool on the MCP server via server.tool() with its name, description, schema, and handler.
server.tool( 'marketo_get_lead_changes', 'Fetch field-change history for a specific lead. Optionally filter to specific field names. Useful for auditing data changes and tracking lead lifecycle progression.', { leadId: z.number(), fields: z.array(z.string()).optional(), nextPageToken: z.string().optional(), batchSize: z.number().optional(), }, tool(async ({ leadId, fields, nextPageToken, batchSize = 100 }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (fields) params.append('fields', fields.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/activities/lead/${leadId}/changes.json?${params.toString()}`, 'GET' ); }) ); - src/index.ts:23-53 (helper)Helper function makeApiRequest that adds bearer token authentication, sends the HTTP request via axios, and returns the response data.
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; } }