> ## 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 Python: setup with a connection token

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

Use this page only when the user is writing their own Python code. If they are connecting an MCP client, follow that MCP client's page instead. The server and the 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 FastMCP 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 Python code to Zapier MCP using a connection token.

## Before you begin

* A [Zapier account](https://zapier.com/sign-up).
* Python 3.10 or later.

## Connect Python 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 **Python**.
  </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 FastMCP">
    ```bash theme={null}
    pip install fastmcp
    ```

    Or with uv:

    ```bash theme={null}
    uv pip install fastmcp
    ```
  </Step>

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

    ```python theme={null}
    import asyncio
    import json
    import os

    from fastmcp import Client
    from fastmcp.client.transports import StreamableHttpTransport

    # Create the transport with your MCP server URL and API key
    # The API key is read from the ZAPIER_MCP_TOKEN environment variable
    server_url = "https://mcp.zapier.com/api/v1/connect"
    api_key = os.environ["ZAPIER_MCP_TOKEN"]
    transport = StreamableHttpTransport(
        server_url,
        headers={"Authorization": f"Bearer {api_key}"}
    )

    # Initialize the client with the transport
    client = Client(transport=transport)


    async def main():
        # Connection is established here
        print("Connecting to MCP server...")
        async with client:
            print(f"Client connected: {client.is_connected()}")

            # Make MCP calls within the context
            print("Fetching available tools...")
            tools = await client.list_tools()

            print(f"Available tools: {json.dumps([t.name for t in tools], indent=2)}")

        # Connection is closed automatically when exiting the context manager
        print("Example completed")


    if __name__ == "__main__":
        asyncio.run(main())
    ```
  </Step>
</Steps>

You've now connected Python 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>
