marketo_get_lead_by_id
Retrieve a lead record using its Marketo ID. Optionally specify fields to return for customized data.
Instructions
Retrieve a lead by its numeric Marketo ID. Optionally specify which fields to return (defaults to standard fields). Returns lead record with all requested field values.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| leadId | Yes | ||
| fields | No |
Implementation Reference
- src/index.ts:254-267 (registration)Registration of the 'marketo_get_lead_by_id' tool using server.tool() on the McpServer instance.
server.tool( 'marketo_get_lead_by_id', 'Retrieve a lead by its numeric Marketo ID. Optionally specify which fields to return (defaults to standard fields). Returns lead record with all requested field values.', { leadId: z.number(), fields: z.array(z.string()).optional(), }, tool(async ({ leadId, fields }) => { const params = new URLSearchParams(); if (fields) params.append('fields', fields.join(',')); const query = params.toString() ? `?${params.toString()}` : ''; return makeApiRequest(`/rest/v1/lead/${leadId}.json${query}`, 'GET'); }) ); - src/index.ts:257-260 (schema)Input schema for 'marketo_get_lead_by_id': leadId (required number) and fields (optional array of strings).
{ leadId: z.number(), fields: z.array(z.string()).optional(), }, - src/index.ts:261-266 (handler)Handler function that constructs a Marketo REST API GET request to /rest/v1/lead/{leadId}.json with optional fields query parameter.
tool(async ({ leadId, fields }) => { const params = new URLSearchParams(); if (fields) params.append('fields', fields.join(',')); const query = params.toString() ? `?${params.toString()}` : ''; return makeApiRequest(`/rest/v1/lead/${leadId}.json${query}`, 'GET'); }) - src/index.ts:23-53 (helper)The makeApiRequest helper function that executes the actual HTTP call to Marketo's API with Bearer token authentication.
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)The 'tool' wrapper helper that handles formatting responses and error handling for all tool handlers.
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, }; } }; }