marketo_get_program_members
Retrieve leads that are members of a specified program, including member status. Optionally select fields and use cursor-based pagination for efficient data retrieval.
Instructions
Get leads that are members of a specific program. Optionally specify which fields to return. Supports cursor-based pagination via nextPageToken. Returns member status alongside lead data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| programId | Yes | ||
| fields | No | ||
| batchSize | No | ||
| nextPageToken | No |
Implementation Reference
- src/index.ts:475-493 (registration)Registration of the 'marketo_get_program_members' tool with server.tool(), including schema definition and handler wiring.
server.tool( 'marketo_get_program_members', 'Get leads that are members of a specific program. Optionally specify which fields to return. Supports cursor-based pagination via nextPageToken. Returns member status alongside lead data.', { programId: z.number(), fields: z.array(z.string()).optional(), batchSize: z.number().optional(), nextPageToken: z.string().optional(), }, tool(async ({ programId, fields, batchSize = 200, nextPageToken }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (fields) params.append('fields', fields.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/leads/programs/${programId}.json?${params.toString()}`, 'GET' ); }) ); - src/index.ts:478-483 (schema)Schema definition for the tool's parameters: programId (required number), fields (optional string array), batchSize (optional number), nextPageToken (optional string).
{ programId: z.number(), fields: z.array(z.string()).optional(), batchSize: z.number().optional(), nextPageToken: z.string().optional(), }, - src/index.ts:484-492 (handler)Handler function that builds query params, calls Marketo REST API endpoint /rest/v1/leads/programs/{programId}.json via GET request to retrieve program members.
tool(async ({ programId, fields, batchSize = 200, nextPageToken }) => { const params = new URLSearchParams({ batchSize: batchSize.toString() }); if (fields) params.append('fields', fields.join(',')); if (nextPageToken) params.append('nextPageToken', nextPageToken); return makeApiRequest( `/rest/v1/leads/programs/${programId}.json?${params.toString()}`, 'GET' ); }) - src/index.ts:55-74 (helper)The 'tool' helper function wraps the handler to convert its return value into an MCP text content response, with error handling.
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, }; } }; } - src/index.ts:23-53 (helper)The makeApiRequest helper function that performs the actual HTTP call to the Marketo API with authentication and error handling.
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; } }