marketo_get_lead_by_email
Retrieve a lead record from Marketo by email address. Optionally specify fields to return. Uses the Marketo leads filter API.
Instructions
Look up a lead by email address using the Marketo leads filter API. Optionally specify which fields to return. Returns matching lead records.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | |||
| fields | No |
Implementation Reference
- src/index.ts:269-284 (registration)Registration of the 'marketo_get_lead_by_email' tool via server.tool() on the McpServer instance. Defines name, description, input schema, and handler.
server.tool( 'marketo_get_lead_by_email', 'Look up a lead by email address using the Marketo leads filter API. Optionally specify which fields to return. Returns matching lead records.', { email: z.string().email(), fields: z.array(z.string()).optional(), }, tool(async ({ email, fields }) => { const params = new URLSearchParams({ filterType: 'email', filterValues: email, }); if (fields) params.append('fields', fields.join(',')); return makeApiRequest(`/rest/v1/leads.json?${params.toString()}`, 'GET'); }) ); - src/index.ts:272-275 (schema)Input schema for 'marketo_get_lead_by_email' using zod: requires 'email' (validated .email()) and optional 'fields' (array of strings).
{ email: z.string().email(), fields: z.array(z.string()).optional(), }, - src/index.ts:276-283 (handler)Handler function for 'marketo_get_lead_by_email'. Builds query params with filterType=email and filterValues=<email>, optionally appends fields, then calls makeApiRequest to GET /rest/v1/leads.json.
tool(async ({ email, fields }) => { const params = new URLSearchParams({ filterType: 'email', filterValues: email, }); if (fields) params.append('fields', fields.join(',')); return makeApiRequest(`/rest/v1/leads.json?${params.toString()}`, 'GET'); }) - src/index.ts:23-53 (helper)The makeApiRequest helper function that executes the actual HTTP request to the Marketo 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 function that wraps the handler to format successful responses as text content and handle errors consistently.
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, }; } }; }