marketo_get_email_by_id
Retrieve a single email by numeric ID. Returns full metadata including subject, from address, reply-to, and folder location.
Instructions
Retrieve a single email by its numeric ID. Returns full email metadata including subject, from address, reply-to, template, and folder location.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes |
Implementation Reference
- src/index.ts:518-523 (registration)Registration of the 'marketo_get_email_by_id' tool with its name, description, schema, and handler on the MCP server.
server.tool( 'marketo_get_email_by_id', 'Retrieve a single email by its numeric ID. Returns full email metadata including subject, from address, reply-to, template, and folder location.', { emailId: z.number() }, tool(async ({ emailId }) => makeApiRequest(`/asset/v1/email/${emailId}.json`, 'GET')) ); - src/index.ts:521-521 (schema)Input schema requiring a single 'emailId' parameter of type z.number(), validated via Zod.
{ emailId: z.number() }, - src/index.ts:522-522 (handler)Handler function for the tool: makes a GET request to /asset/v1/email/{emailId}.json using the makeApiRequest helper.
tool(async ({ emailId }) => makeApiRequest(`/asset/v1/email/${emailId}.json`, 'GET')) - src/index.ts:23-53 (helper)The makeApiRequest helper function that constructs and executes HTTP requests with authentication headers, used by the tool handler.
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 wraps handler functions to format successful responses as JSON text and errors with proper isError flag.
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, }; } }; }