> ## 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 connection token come first: the script cannot run until the user has generated a token.

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 connection token 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 token** in the **API token** section of the **Settings** 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

**1. 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**.

**2. Generate a connection token**

* Select the ![settings icon](https://cdn.zapier.com/storage/photos/3451c46a93d480da52444589a8fc84ff.png) **Settings** tab.
* In the **API token** section, click **Generate token**.
* Copy the **Token**.

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

> [!WARNING]
>
> Treat your connection token like a password. Anyone with it can run tools on this server and access your data.

**3. Set your token as an environment variable**

```bash theme={null}
export ZAPIER_MCP_TOKEN="YOUR_ZAPIER_MCP_TOKEN"
```

**4. Install the MCP SDK**

```bash theme={null}
npm install @modelcontextprotocol/sdk
```

Or with pnpm:

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

**5. 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 token 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 token
// The token 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();
```

You've now connected TypeScript to Zapier MCP.

## Next steps

> [card] [How tools work](https://docs.zapier.com/mcp/overview/how-tools-work.md)
>
> What each meta-tool does, and how dynamic tool discovery works.

> [card] [How connections work](https://docs.zapier.com/mcp/overview/how-connections-work.md)
>
> How connection tokens work, and how to manage them.
