> For the complete documentation index, see [llms.txt](https://docs.keewano.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keewano.com/analytics/mcp-for-agents.md).

# MCP for Agents

Connect Claude Code, Claude Desktop, or any MCP client to your Keewano analytics.

## Connecting to the Keewano MCP Server

The Keewano MCP server lets an AI client — Claude Code, Claude Desktop, or any other Model Context Protocol client — query your Keewano analytics directly, in natural language, using your own data.

It's a standard remote MCP server over HTTPS. Connecting takes two things: a **personal access token** and the **server URL**.

| Setting            | Value                                                                             |
| ------------------ | --------------------------------------------------------------------------------- |
| **Server URL**     | `https://api.keewano.com/mcp`                                                     |
| **Transport**      | Streamable HTTP                                                                   |
| **Authentication** | `k-token` request header                                                          |
| **Manage tokens**  | [**Settings → Access Token**](https://app.keewano.com/settings/personal/security) |

***

## Create a personal access token

1. Open [**Settings → Access Token**](https://app.keewano.com/settings/personal/security).
2. Create a personal access token and copy it somewhere safe.

This token authenticates every request — it's sent in the `k-token` header on each call — so treat it like a password. You can revoke and regenerate it from the same page at any time.

It is the same personal access token (`kwpat-…`) used as the password when [connecting a Postgres client](https://docs.keewano.com/sql-query-studio/guide.md#connect); one token serves both.

{% hint style="warning" %}
Reference the token through an environment variable where your client supports it, rather than pasting the literal value into a file that might be shared or committed to source control.
{% endhint %}

***

## Standard configuration (any MCP client)

Most MCP clients accept a remote server as a URL plus a set of request headers. Use these values:

```json
{
  "mcpServers": {
    "keewano": {
      "type": "http",
      "url": "https://api.keewano.com/mcp",
      "headers": {
        "k-token": "YOUR_TOKEN"
      }
    }
  }
}
```

Replace `YOUR_TOKEN` with the token you created above. The sections below cover the two most common clients specifically.

***

## Claude Code

Claude Code supports remote HTTP MCP servers natively.

### Choose a scope

| Scope     | Flag              | Stored in                       | Visible to                 |
| --------- | ----------------- | ------------------------------- | -------------------------- |
| `local`   | *(default)*       | `~/.claude.json`, project entry | You, this project only     |
| `user`    | `--scope user`    | `~/.claude.json`, top-level     | You, all projects          |
| `project` | `--scope project` | `.mcp.json` in project root     | Anyone who clones the repo |

`--scope user` is usually the right choice — the server is then available in every project, not just the directory you were in when you added it.

{% hint style="danger" %}
Avoid putting a token into a `--scope project` `.mcp.json`, since that file is committed to source control. Use an environment-variable reference there instead.
{% endhint %}

### Add it (recommended)

Run this in your terminal — **not** inside a `claude` session:

```bash
claude mcp add --scope user --transport http keewano \
  https://api.keewano.com/mcp \
  --header "k-token: YOUR_TOKEN"
```

On Windows PowerShell, use a backtick (`` ` ``) at each line end instead of `\`, or put it on one line. Claude Code writes the configuration for you.

### Or edit the config by hand

Add the entry under the top-level `mcpServers` key in `~/.claude.json` (`%USERPROFILE%\.claude.json` on Windows):

```json
{
  "mcpServers": {
    "keewano": {
      "type": "http",
      "url": "https://api.keewano.com/mcp",
      "headers": { "k-token": "YOUR_TOKEN" }
    }
  }
}
```

Claude Code reads its config at startup, so restart `claude` after editing.

### Confirm

```bash
claude mcp list          # Connected means it's working
claude mcp get keewano   # details for this server
```

Then start a session; `/mcp` shows the server status and its tools. The first time Claude calls a tool it asks for permission — approve it to continue.

***

## Claude Desktop

Register the server through a local bridge (`mcp-remote`) that forwards to the Keewano endpoint and attaches your token. This needs [Node.js](https://nodejs.org) installed.

Open the config file:

* **macOS** — `~/Library/Application Support/Claude/claude_desktop_config.json`
* **Windows** — `%APPDATA%\Claude\claude_desktop_config.json`

Add the following, merging into an existing `mcpServers` object if there is one:

```json
{
  "mcpServers": {
    "keewano": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://api.keewano.com/mcp",
        "--header",
        "k-token:${KEEWANO_TOKEN}"
      ],
      "env": {
        "KEEWANO_TOKEN": "YOUR_TOKEN"
      }
    }
  }
}
```

Keeping the token in `env` and referencing it as `${KEEWANO_TOKEN}` in the header keeps the value in one place.

{% hint style="info" %}
Fully **quit and reopen** Claude Desktop — reloading the window isn't enough, since the config is read only at startup.
{% endhint %}

To confirm, open a new conversation, click **Search & tools**, and check that `keewano` is connected with its tools listed.

***

## Reference

| Setting              | Value                                                                             |
| -------------------- | --------------------------------------------------------------------------------- |
| **Server URL**       | `https://api.keewano.com/mcp`                                                     |
| **Transport**        | Streamable HTTP                                                                   |
| **Auth header**      | `k-token: <your personal access token>`                                           |
| **Token management** | [**Settings → Access Token**](https://app.keewano.com/settings/personal/security) |

***

## Troubleshooting

<details>

<summary>401 / 403</summary>

The token is missing, wrong, expired, or revoked. Generate a fresh one under [**Settings → Access Token**](https://app.keewano.com/settings/personal/security) and update your configuration.

</details>

<details>

<summary>Claude Code: ✘ Failed to connect</summary>

Check the URL and header with `claude mcp get keewano`. If startup times out, raise the limit:

```bash
MCP_TIMEOUT=60000 claude
```

On PowerShell:

```powershell
$env:MCP_TIMEOUT = "60000"; claude
```

</details>

<details>

<summary>Claude Desktop drops the entry or shows nothing</summary>

Claude Desktop's config accepts local (bridge) servers — use the `mcp-remote` form above rather than a bare `url` entry.

If `npx` isn't found even though it works in your terminal, use its absolute path (Claude Desktop launches commands with a minimal `PATH`); on Windows, try `npx.cmd`.

</details>

<details>

<summary>Connected but no tools appear</summary>

Restart the client — tools are discovered at startup.

</details>

***

## What your agent is querying

The MCP server reads the same event history every other Keewano interface reads. Two pages are worth knowing when you want to understand or shape what an agent gets back:

* [SQL Query Studio](https://docs.keewano.com/sql-query-studio/guide.md) — the query model behind most answers: one `events` table where every column holds its last value forward.
* [Lua Scripting](https://docs.keewano.com/lua-scripting/guide.md) — for questions about sequence and order, which a row-based query cannot phrase.

For the reasoning that powers the same data inside the app, see [Keewano Ask](https://docs.keewano.com/analytics/keewano-ask.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keewano.com/analytics/mcp-for-agents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
