marketo_get_emails
List Marketo email assets filtered by approval status and paginated. Returns email metadata including subject, from address, and template ID.
Instructions
List email assets in Marketo. Filter by approval status (approved/draft) and paginate with maxReturn/offset. Returns email metadata including subject line, from address, and template ID.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxReturn | No | ||
| offset | No | ||
| status | No |
Implementation Reference
- src/index.ts:508-515 (handler)The handler function for the 'marketo_get_emails' tool. It constructs query params (maxReturn, offset, status) and calls the Marketo Asset API GET /asset/v1/emails.json endpoint.
tool(async ({ maxReturn = 200, offset = 0, status }) => { const params = new URLSearchParams({ maxReturn: maxReturn.toString(), offset: offset.toString(), }); if (status) params.append('status', status); return makeApiRequest(`/asset/v1/emails.json?${params.toString()}`, 'GET'); }) - src/index.ts:503-507 (schema)Input schema for the 'marketo_get_emails' tool: optional maxReturn (number), offset (number), and status (enum: approved/draft), validated with Zod.
{ maxReturn: z.number().optional(), offset: z.number().optional(), status: z.enum(['approved', 'draft']).optional(), }, - src/index.ts:500-516 (registration)Registration of the 'marketo_get_emails' tool on the MCP server via server.tool(), including its name, description, input schema, and handler.
server.tool( 'marketo_get_emails', 'List email assets in Marketo. Filter by approval status (approved/draft) and paginate with maxReturn/offset. Returns email metadata including subject line, from address, and template ID.', { maxReturn: z.number().optional(), offset: z.number().optional(), status: z.enum(['approved', 'draft']).optional(), }, tool(async ({ maxReturn = 200, offset = 0, status }) => { const params = new URLSearchParams({ maxReturn: maxReturn.toString(), offset: offset.toString(), }); if (status) params.append('status', status); return makeApiRequest(`/asset/v1/emails.json?${params.toString()}`, 'GET'); }) ); - src/index.ts:23-53 (helper)The makeApiRequest helper function used by the handler to execute HTTP requests to Marketo's REST API with proper auth headers.
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 each handler to catch errors and return a standardized MCP content response.
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, }; } }; }