marketo_get_form_by_id
Retrieve a Marketo form's complete metadata, including fields, submit button, and thank-you page configuration, by its numeric ID.
Instructions
Retrieve a single form by its numeric ID. Returns full form metadata including fields, submit button, and thank-you page configuration.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| formId | Yes |
Implementation Reference
- src/index.ts:99-104 (registration)Registration of the 'marketo_get_form_by_id' tool with the MCP server, defining its name, description, input schema (formId as number), and handler.
server.tool( 'marketo_get_form_by_id', 'Retrieve a single form by its numeric ID. Returns full form metadata including fields, submit button, and thank-you page configuration.', { formId: z.number() }, tool(async ({ formId }) => makeApiRequest(`/asset/v1/form/${formId}.json`, 'GET')) ); - src/index.ts:103-103 (handler)The handler function for marketo_get_form_by_id. It calls makeApiRequest with a GET request to the Marketo API endpoint /asset/v1/form/{formId}.json.
tool(async ({ formId }) => makeApiRequest(`/asset/v1/form/${formId}.json`, 'GET')) - src/index.ts:102-102 (schema)Input schema using Zod; expects a single parameter 'formId' of type number.
{ formId: z.number() }, - src/index.ts:23-53 (helper)The makeApiRequest helper function that handles authentication, HTTP requests to the Marketo API, and error handling. Used by the tool handler to make the GET request.
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 (registration)The 'tool' wrapper function that wraps handler logic, catches errors, and formats responses as MCP content.
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, }; } }; }