marketo_get_lead_by_id
Retrieve a Marketo lead by its unique ID, with optional field selection to return only the data you need.
Instructions
Get a single lead by Marketo lead ID. Optionally specify which fields to return. Returns lead record with all requested fields.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Marketo lead ID | |
| fields | No | List of field API names to return (e.g. ['email','firstName','company']) |
Implementation Reference
- src/tools/leads.ts:14-21 (handler)The async handler function for marketo_get_lead_by_id. It extracts optional 'fields' from args, joins them into a comma-separated string, and calls makeRequest to GET /rest/v1/lead/{id}.json.
async (args) => { try { const params: Record<string, unknown> = {}; if (args.fields?.length) params.fields = args.fields.join(","); return ok(await makeRequest(`/rest/v1/lead/${args.id}.json`, "GET", params)); } catch (e) { return err(e); } } ); - src/tools/leads.ts:10-13 (schema)Input schema for marketo_get_lead_by_id: 'id' (required number) and 'fields' (optional array of strings).
{ id: z.number().describe("Marketo lead ID"), fields: z.array(z.string()).optional().describe("List of field API names to return (e.g. ['email','firstName','company'])"), }, - src/tools/leads.ts:7-8 (registration)Registration of the tool via server.tool('marketo_get_lead_by_id', ...) with description and schema.
server.tool( "marketo_get_lead_by_id", - src/index.ts:6-22 (registration)Import of registerLeadTools from leads.ts (file containing the tool registration).
import { registerLeadTools } from "./tools/leads.js"; import { registerProgramTools } from "./tools/programs.js"; import { registerEmailTools } from "./tools/emails.js"; import { registerSmartListTools } from "./tools/smartLists.js"; import { registerListTools } from "./tools/lists.js"; import { registerChannelTools } from "./tools/channels.js"; import { registerLandingPageTools } from "./tools/landingPages.js"; import { registerBulkExportTools } from "./tools/bulkExport.js"; const server = new McpServer({ name: "marketo-mcp", version: "0.1.0", }); // Register all tool groups registerFormTools(server); registerLeadTools(server); - src/client.ts:21-49 (helper)The makeRequest helper that performs authenticated HTTP requests to the Marketo REST API, called by the tool handler.
export async function makeRequest<T = unknown>( endpoint: string, method: Method = "GET", data?: unknown, contentType?: string, ): Promise<T> { const token = await getAccessToken(); const config: AxiosRequestConfig = { url: `${MARKETO_BASE_URL}${endpoint}`, method, headers: { Authorization: `Bearer ${token}`, ...(contentType ? { "Content-Type": contentType } : {}), }, ...(data && method !== "GET" ? { data } : {}), ...(data && method === "GET" ? { params: data } : {}), }; const res = await axios(config); const body = res.data; // Marketo REST API returns errors inside the response body if (body?.errors?.length) { const e = body.errors[0]; throw new MarketoError(`${e.code}: ${e.message}`, res.status); } return body as T; }