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

# Claude Code

> Connect Detrics to Claude Code, one command, one API key

<Note>
  If you primarily want to chat with your data (not code), [Claude Web](/claude/claude-web) is the easiest path, no API key needed, just OAuth in 30 seconds.
</Note>

## Prerequisites

* A [Detrics account](https://detrics.io/get-started?utm_source=detrics-support\&utm_medium=claude-code-setup)
* [Claude Code](https://docs.anthropic.com/en/docs/claude-code) installed
* At least one [connected platform](/connect/connect-a-platform) in your Detrics workspace

## Setup

<Steps>
  <Step title="Generate a Detrics API key">
    Go to [app.detrics.io/mcp/api-keys](https://app.detrics.io/mcp/api-keys) and click **Generate New Key**. Copy it, you will need it in the next step.

    <Warning>
      Treat your API key like a password. Never share it publicly or commit it to version control. See [API Keys](/claude/api-keys) for security best practices.
    </Warning>
  </Step>

  <Step title="Register the Detrics MCP server">
    Run the following command in your terminal. Replace `your-api-key` with the key you just generated.

    ```bash theme={null}
    claude mcp add detrics-mcp https://mcp.detrics.io -e DETRICS_API_KEY=your-api-key -t streamable-http
    ```
  </Step>

  <Step title="Start querying">
    Open Claude Code and try a test prompt:

    ```
    What platforms do I have connected in Detrics?
    ```

    Claude Code will call the Detrics MCP server and return your connected platforms. If you see results, you are all set.
  </Step>
</Steps>

## Example prompts

Once connected, try these:

* "What was my total ad spend across all platforms last month?"
* "Compare my Google Ads and Meta Ads ROAS for the last 30 days"
* "Show me my top 5 campaigns by conversions this week"
* "What's my Shopify revenue trend over the last 90 days?"
* "What metrics are available for TikTok Ads?"

Or browse the [Prompt Templates](/claude/use-prompt-templates) for 40+ ready-made marketing prompts.

## Updating your API key

If you need to rotate your API key:

1. Generate a new key at [app.detrics.io/mcp/api-keys](https://app.detrics.io/mcp/api-keys)
2. Remove the existing server: `claude mcp remove detrics-mcp`
3. Re-add with the new key:
   ```bash theme={null}
   claude mcp add detrics-mcp https://mcp.detrics.io -e DETRICS_API_KEY=new-key -t streamable-http
   ```

## Troubleshooting

<AccordionGroup>
  <Accordion title="'Server not found' or 'Connection refused'">
    The MCP server URL may be incorrect.

    **Fix:** Make sure the URL is exactly `https://mcp.detrics.io`. Enter the base URL by itself, with no trailing slash and no `/sse` suffix.
  </Accordion>

  <Accordion title="'Unauthorized' or '401' errors">
    Your API key is missing or invalid.

    **Fix:** Remove and re-add the server, making sure the `-e DETRICS_API_KEY=...` flag is included with your full API key.
  </Accordion>

  <Accordion title="'No connections found' response">
    Your MCP connection works, but there are no platforms connected in your Detrics workspace.

    **Fix:**

    1. Go to [app.detrics.io](https://app.detrics.io) and connect at least one data source
    2. Or ask Claude Code: "Connect my Meta Ads account", it will generate an OAuth link for you
  </Accordion>
</AccordionGroup>

For more issues, see [Troubleshooting](/claude/troubleshooting).
