marketo_get_emails
Retrieve Marketo email assets with pagination and status filtering. Get subject line, from address, and folder metadata for approved or draft emails.
Instructions
List email assets in Marketo. Supports pagination via maxReturn/offset and filtering by status (approved/draft). Returns email metadata including subject line, from address, and folder.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxReturn | No | Max emails to return (1-200, default 20) | |
| offset | No | Pagination offset | |
| status | No | Filter by approval status |
Implementation Reference
- src/tools/emails.ts:15-24 (handler)Handler function for marketo_get_emails tool. Builds query params (maxReturn, offset, status) and makes a GET request to the Marketo Asset API /rest/asset/v1/emails.json endpoint. Returns email metadata or an error.
async (args) => { try { const params: Record<string, unknown> = {}; if (args.maxReturn) params.maxReturn = args.maxReturn; if (args.offset) params.offset = args.offset; if (args.status) params.status = args.status; return ok(await makeRequest("/rest/asset/v1/emails.json", "GET", params)); } catch (e) { return err(e); } } ); - src/tools/emails.ts:10-14 (schema)Zod schema for marketo_get_emails input parameters: maxReturn (number), offset (number), status (enum: approved|draft), all optional.
{ maxReturn: z.number().optional().describe("Max emails to return (1-200, default 20)"), offset: z.number().optional().describe("Pagination offset"), status: z.enum(["approved", "draft"]).optional().describe("Filter by approval status"), }, - src/tools/emails.ts:7-9 (registration)Registration of the marketo_get_emails tool on the MCP server with its name and description.
server.tool( "marketo_get_emails", "List email assets in Marketo. Supports pagination via maxReturn/offset and filtering by status (approved/draft). Returns email metadata including subject line, from address, and folder.", - src/client.ts:21-49 (helper)Helper makeRequest function used by the handler to perform authenticated HTTP requests to the Marketo API. Handles token injection, query params for GET, body for POST, and Marketo error extraction.
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; } - src/auth.ts:14-34 (helper)Auth helper that obtains and caches a Marketo OAuth2 token using client credentials, used by makeRequest.
export async function getAccessToken(): Promise<string> { const now = Date.now(); if (cachedToken && now < tokenExpiresAt) { return cachedToken; } const url = `${MARKETO_BASE_URL}/identity/oauth/token`; const res = await axios.get(url, { params: { grant_type: "client_credentials", client_id: MARKETO_CLIENT_ID, client_secret: MARKETO_CLIENT_SECRET, }, }); const { access_token, expires_in } = res.data; cachedToken = access_token; // Refresh 60s before actual expiry tokenExpiresAt = now + (expires_in - 60) * 1000; return access_token; }