Skip to main content
Glama
alexleventer

Marketo MCP Server

by alexleventer

marketo_add_lead_to_list

Add leads to a Marketo list by specifying list ID and lead IDs to organize and manage marketing contacts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
listIdYes
leadIdsYes

Implementation Reference

  • The handler function that adds specified lead IDs to a Marketo list by constructing input data and making a POST request to the Marketo Leads API endpoint /rest/v1/lists/{listId}/leads.json. Returns the API response as text or an error message.
    async ({ listId, leadIds }) => {
      try {
        const data = {
          input: leadIds.map(id => ({ id })),
        };
    
        const response = await makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', data);
    
        return {
          content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
        };
      } catch (error: any) {
        return {
          content: [
            { type: 'text', text: `Error: ${error.response?.data?.message || error.message}` },
          ],
        };
      }
    }
  • Zod input schema defining listId as number and leadIds as array of numbers.
    {
      listId: z.number(),
      leadIds: z.array(z.number()),
    },
  • src/index.ts:640-665 (registration)
    Registration of the tool using McpServer.tool method with name 'marketo_add_lead_to_list', input schema, and inline handler function.
    server.tool(
      'marketo_add_lead_to_list',
      {
        listId: z.number(),
        leadIds: z.array(z.number()),
      },
      async ({ listId, leadIds }) => {
        try {
          const data = {
            input: leadIds.map(id => ({ id })),
          };
    
          const response = await makeApiRequest(`/rest/v1/lists/${listId}/leads.json`, 'POST', data);
    
          return {
            content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
          };
        } catch (error: any) {
          return {
            content: [
              { type: 'text', text: `Error: ${error.response?.data?.message || error.message}` },
            ],
          };
        }
      }
    );
  • Shared helper function used by the tool to make authenticated HTTP requests to the Marketo API using axios, handling token retrieval and content types.
    async function makeApiRequest(
      endpoint: string,
      method: string,
      data?: any,
      contentType: string = 'application/json'
    ) {
      const token = await tokenManager.getToken();
      const headers: any = {
        Authorization: `Bearer ${token}`,
      };
    
      if (contentType) {
        headers['Content-Type'] = contentType;
      }
    
      try {
        const response = await axios({
          url: `${MARKETO_BASE_URL}${endpoint}`,
          method: 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;
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/alexleventer/marketo-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server