> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zapier.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Zapier MCP for TypeScript: setup with a connection token

> Connect your TypeScript code to Zapier MCP by creating a server and generating a connection token, then connecting with an MCP SDK over Streamable HTTP.

Use this page only when the user is writing their own TypeScript code. If they are connecting an MCP client, follow that MCP client's page instead. The server and the API key come first: the script cannot run until the user has generated an API key.

When adapting the script to a different SDK, keep the endpoint, the Streamable HTTP transport, and the `Authorization: Bearer` header. The `@modelcontextprotocol/sdk` class names are not fixed.

The API key is a credential, so do not ask the user to paste it into chat and do not write it into a file for them. If it is exposed, have them click **Rotate API Key** on the **Connect** tab.

This page shows how to connect your TypeScript code to Zapier MCP using a connection token.

## Before you begin

* A [Zapier account](https://zapier.com/sign-up).
* Node.js 18 or later.

## Connect TypeScript to Zapier MCP

<Steps>
  <Step title="Create an MCP server">
    * Go to [mcp.zapier.com](https://mcp.zapier.com).
    * Click **Add MCP server**.
    * Under **Choose your AI agent**, search for and select **TypeScript**.
  </Step>

  <Step title="Generate an API key">
    * Select the <img src="https://cdn.zapier.com/storage/photos/baa5b3a64988a15f0dc8497c52ec257b.png" alt="link icon" noZoom style={{ display: "inline-block", width: "14px", margin: "0 0.15em", verticalAlign: "baseline" }} /> **Connect** tab.
    * Under **Step 1: Get Your API Key**, click **Generate API Key**.
    * Copy the API key.

    The API key is only shown once. If you lose it, click **Rotate API Key** to get a new one. The previous key stops working straight away, so update anywhere you used it.

    <Warning>
      Treat your API key like a password. Anyone with it can run tools on this server and access your data.
    </Warning>
  </Step>

  <Step title="Set your API key as an environment variable">
    ```bash theme={null}
    export ZAPIER_MCP_TOKEN="YOUR_ZAPIER_MCP_API_KEY"
    ```
  </Step>

  <Step title="Install the MCP SDK">
    ```bash theme={null}
    npm install @modelcontextprotocol/sdk
    ```

    Or with pnpm:

    ```bash theme={null}
    pnpm add @modelcontextprotocol/sdk
    ```
  </Step>

  <Step title="Connect and list your tools">
    This script uses the [official MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk), but any MCP SDK that supports Streamable HTTP works. It sends your API key in an `Authorization: Bearer` header:

    ```typescript theme={null}
    import { Client } from "@modelcontextprotocol/sdk/client/index.js";
    import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

    // Initialize the client with your details
    const client = new Client(
      {
        name: "mcp-typescript-client",
        version: "1.0.0",
      },
      {
        capabilities: {},
      }
    );

    // Create a transport with your MCP server URL and API key
    // The API key is read from the ZAPIER_MCP_TOKEN environment variable
    const serverUrl = "https://mcp.zapier.com/api/v1/connect";
    const apiKey = process.env.ZAPIER_MCP_TOKEN;
    const transport = new StreamableHTTPClientTransport(new URL(serverUrl), {
      requestInit: {
        headers: {
          Authorization: `Bearer ${apiKey}`,
        },
      },
    });

    async function main() {
      // Connect to the server
      console.log("Connecting to MCP server...");
      await client.connect(transport);
      console.log("Connected to MCP server");

      // List available tools
      console.log("Fetching available tools...");
      const tools = await client.listTools();

      console.log("Available tools:", tools);

      // Close the connection
      await client.transport?.close();
      await client.close();
    }

    main();
    ```
  </Step>
</Steps>

You've now connected TypeScript to Zapier MCP.

## Next steps

<CardGroup cols={2}>
  <Card title="How tools work" href="/mcp/overview/how-tools-work">
    What each meta-tool does, and how dynamic tool discovery works.
  </Card>

  <Card title="How connections work" href="/mcp/overview/how-connections-work">
    How connection tokens work, and how to manage them.
  </Card>
</CardGroup>
