---
title: Connect a coding agent to Kovlet (MCP)
overline: HOW-TO
nav: Connect a coding agent (MCP)
updated: 2026-12
minutes: 6
next: multi-app-sync
---

# Connect a coding agent to Kovlet (MCP)

Let Claude Code, Cursor, Windsurf, Codex or any MCP client find your Data Spaces, read their live schema and write typed app code. One command sets it up, and you approve the agent once in the browser, with no API key.

> **At a glance**
>
> - Set up every agent on this machine: `npx -y @kovlet/mcp init` (Node.js 22.12 or newer).
> - MCP server: `https://api.kovlet.com/mcp` (Streamable HTTP). Local `kovletd --dev`: `http://127.0.0.1:8080/mcp`.
> - The first tool call returns an approval link and code. You pick the Data Spaces the agent may use. Its access is capped by your own role.
> - Clients that connect to `/mcp` over HTTP need only the URL: they sign in by themselves with OAuth. Clients that only take a static header use `Authorization: Bearer <token>` from `npx -y @kovlet/mcp token`.
> - Tools: `list_spaces`, `inspect_space_schema`, `create_space`, `request_space_access`, `propose_schema_addition`, `propose_rules`, `list_connected_apps`, `generate_app_connection`.

MCP, the Model Context Protocol, is how coding agents call outside tools. The [Kovlet MCP server](/docs/glossary#kovlet-mcp-server "The Model Context Protocol server that lets coding agents list Data Spaces, read schemas and generate app code.") gives your agent a set of Kovlet tools.

## Before you start

- Node.js 22.12 or newer, for `npx -y @kovlet/mcp`.
- A Kovlet account. You sign in on `https://kovlet.com` when you approve the agent.
- At least one MCP client: Claude Code, Cursor, Windsurf, Codex, or any client that can launch a stdio server or connect to a Streamable HTTP server.

## 1. Run the installer

Run this in a terminal. With no options, it sets up every coding agent it finds on this machine, for every project.

```sh title="terminal"
npx -y @kovlet/mcp init
```

> **You should see**
>
> - A list of the agents it found, with the files it created for each.
> - `Wrote 3 file(s).` on a machine with Claude Code and Cursor.
> - Next steps: restart the agents, then approve the agent on its first tool call.

The full output, on a machine with Claude Code and Cursor:

```text title="output"
Kovlet → https://api.kovlet.com (kovlet-mcp stdio bridge, user scope)
Project: no known project type here. Docs: https://kovlet.com/docs (other languages: https://kovlet.com/docs/quickstart-rest)

Claude Code
  + MCP server         ~/.claude.json  (create)
  + agent instructions ~/.claude/skills/kovlet/SKILL.md  (create)

Cursor
  + MCP server         ~/.cursor/mcp.json  (create)
  note: Cursor keeps user rules in Settings, not in a file: run `kovlet-mcp init --client cursor --scope project` in a project to add .cursor/rules/kovlet.mdc.

Wrote 3 file(s).

Next:
  1. Restart Claude Code, Cursor so they load the Kovlet server.
  2. Ask your agent to use Kovlet. On the first tool call it shows an approval link: open it,
     pick the Data Spaces the agent may use, and approve.
  Reference for agents: https://kovlet.com/llms.txt
```

`init` registers two things with each agent:

- **The Kovlet MCP server.**
- **The Kovlet agent skill.** It tells the agent how to build on Kovlet. It is a Claude Code skill, a Cursor or Windsurf rule, or a section in Codex's `AGENTS.md`.

`init` is safe to run again. It only changes Kovlet's own entries. It copies every file it changes to `<file>.kovlet.bak` first. Running it a second time changes nothing.

| Option | What it does |
| --- | --- |
| `--client <name>` | `auto` (default: every agent found), `claude-code`, `cursor`, `windsurf` or `codex`. Repeat it or comma-separate names to pick several. |
| `--scope <scope>` | `user` (default: every project on this machine) or `project` (only the current directory). |
| `--url <url>` | The Kovlet server. Default `https://api.kovlet.com`; use `http://127.0.0.1:8080` for a local `kovletd --dev`. |
| `--stdio` / `--http` | Launch the local `kovlet-mcp` bridge (default), or connect to `<url>/mcp` directly with a bearer token ([Connect over HTTP](#connect-over-http)). |
| `--dry-run` | Print the changes as a diff and write nothing. |
| `-y`, `--yes` | Don't ask for confirmation. |

Where `init` writes, per agent:

| Agent | MCP server (`user` / `project` scope) | Agent instructions (`user` / `project` scope) |
| --- | --- | --- |
| Claude Code | `~/.claude.json` / `.mcp.json` | `~/.claude/skills/kovlet/SKILL.md` / `.claude/skills/kovlet/SKILL.md` |
| Cursor | `~/.cursor/mcp.json` / `.cursor/mcp.json` | none (user rules live in Cursor's Settings) / `.cursor/rules/kovlet.mdc` |
| Windsurf | `~/.codeium/windsurf/mcp_config.json` (both scopes) | `~/.codeium/windsurf/memories/global_rules.md` / `.windsurf/rules/kovlet.md` |
| Codex | `~/.codex/config.toml` / `.codex/config.toml` | `~/.codex/AGENTS.md` / `AGENTS.md` |

`CLAUDE_CONFIG_DIR` and `CODEX_HOME` are honored.

> **Note:** Codex loads a project's `.codex/config.toml` only when you have marked the project as trusted.

## 2. Restart the agent and approve it

Restart the agent so it loads the Kovlet server. The first time the agent calls a Kovlet tool, the tool answers with an approval link instead of data:

```text title="tool result"
Kovlet needs the user to approve this agent first. Ask them to open https://kovlet.com/activate?user_code=2QV6-3NEU (or https://kovlet.com/activate and enter the code 2QV6-3NEU), sign in, choose which Data Spaces the agent may use, and approve. Then call this tool again. The code expires in 10 minutes.
```

1. Open the link. Sign in to Kovlet if you aren't signed in.
2. Pick the Data Spaces the agent may use, and approve.
3. Tell the agent to call the tool again. From now on its tool calls go through.

The agent's access is always capped by your own role. On each space it gets `min(your role, the agent's grant)`.

Approving creates an app for the agent, named "Kovlet MCP agent" by default. The app sits on a new machine named after your computer. To cut the agent off at once, revoke that app in the console.

> **Tip:** To sign in before you start the agent, run `npx -y @kovlet/mcp login` and approve the link it prints. The session is saved per server in `$XDG_CONFIG_HOME/kovlet/mcp-tokens.json` (mode 0600). The bridge asks you to approve again when the session expires or is revoked.

## 3. Give the agent a first prompt

Paste this prompt into the agent, in an empty folder or an existing React project. It runs the whole loop: find or create a space, read its schema, and write the typed client.

```text title="Prompt"
Use the Kovlet MCP server for this project. 1) Call list_spaces. If a tool answers sign_in_required, show me the link and code, wait until I have approved, then call the tool again. 2) If no Data Space fits a todo app, call create_space with name "Todos" and a table "todos" with columns title (string) and done (boolean). 3) Call inspect_space_schema on it. 4) Call generate_app_connection with target "react" and app_name "Todo web", and write the returned files into this project. Do not run npm install. Finish with a short summary of the space, its tables and the files you wrote.
```

> **You should see**
>
> - The agent calls `list_spaces`, `create_space`, `inspect_space_schema` and `generate_app_connection`.
> - It writes `src/kovlet.ts`: the typed `@kovlet/client` connection for the "Todos" space. It has a `todos` table (`title` string, `done` boolean) and `autoConnect: false`, so the app calls `kovlet.connect()` from a click.
> - It writes `src/KovletExample.tsx`: a small React component with a Connect button, the sync status and a live list of todos.

The app itself holds no API key either. Its users approve it on first run, the same way you approved the agent. To build the rest of the app, follow the [web quickstart](/docs/quickstart-web).

## Configure a client by hand

Use these entries if you don't want to run `init`. Every client launches the same stdio command: `npx -y @kovlet/mcp --url <server>`. For a local `kovletd --dev`, replace `https://api.kovlet.com` with `http://127.0.0.1:8080`.

<!-- tabs: MCP client -->

### Claude Code

```sh title="terminal"
claude mcp add kovlet -- npx -y @kovlet/mcp --url https://api.kovlet.com
```

Or install the Kovlet plugin, which adds the MCP server, the agent skill and the `/kovlet:connect` command:

```text title="Claude Code"
/plugin marketplace add kovlethq/kovlet-plugin
/plugin install kovlet@kovlet
```

### Cursor

```json title="~/.cursor/mcp.json"
{
  "mcpServers": {
    "kovlet": {
      "command": "npx",
      "args": ["-y", "@kovlet/mcp", "--url", "https://api.kovlet.com"]
    }
  }
}
```

### Windsurf

```json title="~/.codeium/windsurf/mcp_config.json"
{
  "mcpServers": {
    "kovlet": {
      "command": "npx",
      "args": ["-y", "@kovlet/mcp", "--url", "https://api.kovlet.com"]
    }
  }
}
```

### Codex

```toml title="~/.codex/config.toml"
[mcp_servers.kovlet]
command = "npx"
args = ["-y", "@kovlet/mcp", "--url", "https://api.kovlet.com"]
```

### Other MCP clients

Register a stdio server named `kovlet` with command `npx` and arguments `-y @kovlet/mcp --url https://api.kovlet.com`. The `KOVLET_URL` environment variable sets the server instead of `--url`.

<!-- /tabs -->

> **Note:** On Windows, `npx` is a `.cmd` shim that clients can't start without a shell. Use command `cmd` with arguments `/c npx -y @kovlet/mcp --url https://api.kovlet.com`. `init` does this for you.

## Connect over HTTP

Some clients connect to a remote MCP server instead of launching a command. They use `https://api.kovlet.com/mcp` directly. The endpoint speaks Streamable HTTP. `initialize` and `tools/list` work without a token, but every tool call needs one.

### Let the client sign in (OAuth)

Claude Code, Cursor, Windsurf, Codex and other clients that follow the MCP authorization spec need only the URL. Add the server with no header:

```sh title="terminal"
claude mcp add --transport http kovlet https://api.kovlet.com/mcp
```

```json title="~/.cursor/mcp.json"
{ "mcpServers": { "kovlet": { "url": "https://api.kovlet.com/mcp" } } }
```

What happens on the first tool call:

1. The client gets a 401.
2. It finds Kovlet's sign-in through the OAuth discovery metadata and registers itself (dynamic client registration).
3. It opens `https://kovlet.com/activate` in your browser.
4. You pick the Data Spaces the agent may use, and approve. The browser hands the sign-in back to the client.

> **Caution:** This screen has no code to compare. Instead, it shows where the sign-in returns to, for example `127.0.0.1` or `cursor:`. Only approve when you just asked the agent to connect.

- The token works only on `/mcp`, and lasts 30 days. Then the client opens the approval page again. The spaces you shared stay shared.
- Each agent gets one app, named after the client and the place it returns to, and one [headless machine](/docs/glossary#headless-machine "A machine with no person at the keyboard: a server, CI job or agent sandbox. Counts toward the machines limit."). Approving the same agent again reuses both, so reconnecting never uses another machine slot.
- To disconnect the agent, revoke the app (or the machine) in the console.
- Cursor registers three return addresses (`cursor://…`, `https://cursor.com/…` and `http://localhost:…`). The one it uses decides which "Cursor" app you see in the console, so you may see more than one over time.

### Use a bearer token

Some clients only take a static header. They send a Kovlet session token as `Authorization: Bearer`. A session lasts 30 days. Then you get a new token the same way.

**1. Get a token.** With the `kovlet-mcp` command:

```sh title="terminal"
npx -y @kovlet/mcp login
export KOVLET_TOKEN="$(npx -y @kovlet/mcp token)"
```

Or, without it, use the [device-code](/docs/glossary#device-code "A sign-in for apps without a browser redirect: the app shows a short code, and the user approves it at https://kovlet.com/activate. Codes expire after 10 minutes.") sign-in with `scope=agent`:

```sh title="terminal"
curl -s -X POST https://api.kovlet.com/v1/oauth/device_authorization \
  -d client_name="My agent" -d machine_name=laptop -d scope=agent
```

```json title="response"
{"device_code":"kvc_...","user_code":"4FKD-XMMY","verification_uri":"https://kovlet.com/activate","verification_uri_complete":"https://kovlet.com/activate?user_code=4FKD-XMMY","expires_in":600,"interval":5}
```

Open `verification_uri_complete`, pick the spaces and approve. Then poll the token endpoint every `interval` seconds until it returns the token:

```sh title="terminal"
curl -s -X POST https://api.kovlet.com/v1/oauth/token \
  -d grant_type=urn:ietf:params:oauth:grant-type:device_code -d device_code=kvc_...
```

Until you approve, it answers `{"error":"authorization_pending",...}`. After that it answers `{"access_token":"kvs_...","token_type":"Bearer","expires_in":2591999,...}`. Export the `access_token` as `KOVLET_TOKEN`.

**2. Register the server.** `npx -y @kovlet/mcp init --http` writes these entries for you. Or add them by hand:

<!-- tabs: MCP client -->

### Claude Code

```sh title="terminal"
claude mcp add --transport http kovlet https://api.kovlet.com/mcp \
  --header 'Authorization: Bearer ${KOVLET_TOKEN}'
```

The single quotes keep `${KOVLET_TOKEN}` in the config, so Claude Code reads the variable when it starts instead of storing the token.

### Cursor

```json title="~/.cursor/mcp.json"
{
  "mcpServers": {
    "kovlet": {
      "url": "https://api.kovlet.com/mcp",
      "headers": { "Authorization": "Bearer ${env:KOVLET_TOKEN}" }
    }
  }
}
```

### Windsurf

```json title="~/.codeium/windsurf/mcp_config.json"
{
  "mcpServers": {
    "kovlet": {
      "serverUrl": "https://api.kovlet.com/mcp",
      "headers": { "Authorization": "Bearer ${env:KOVLET_TOKEN}" }
    }
  }
}
```

### Codex

```toml title="~/.codex/config.toml"
[mcp_servers.kovlet]
url = "https://api.kovlet.com/mcp"
bearer_token_env_var = "KOVLET_TOKEN"
```

<!-- /tabs -->

**3. Check it.** A tool call with the token lists the spaces you approved:

```sh title="terminal"
curl -s https://api.kovlet.com/mcp -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $KOVLET_TOKEN" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"list_spaces","arguments":{}}}'
```

> **You should see**
>
> - A JSON-RPC result whose `structuredContent.spaces` lists each space with your agent's `role`.

## What the agent can do

Every tool goes through the same access checks as apps and the REST API. The agent never sees or changes more than you could.

| Tool | What it does |
| --- | --- |
| `list_spaces` | The spaces this agent can reach, with its role on each. If you have more spaces than you shared, it says how many (`not_shared_with_agent`). |
| `inspect_space_schema` | Tables, columns, types and optionality, file paths, pending proposals and the current end-user rules of a space. |
| `create_space` | A new space owned by you, with optional initial tables. The agent gets editor access to it. |
| `request_space_access` | An approve link you open to share more spaces with the agent, without signing in again. |
| `propose_schema_addition` | Adds tables and optional columns at once. Destructive changes become proposals a space owner approves in the console. |
| `propose_rules` | Proposes a space's end-user rules document. Nothing changes until an owner approves it. |
| `list_connected_apps` | The apps and headless machines with access to a space. |
| `generate_app_connection` | Typed `@kovlet/client` code (`client`, `react` or `node`) from the live schema. |

Tool errors carry a stable `code`, a `message`, and a `hint` with the next step. The full tool reference, with arguments, is the "Kovlet MCP server" section of [/llms-full.txt](/llms-full.txt).

## Troubleshooting

| What you see | What to do |
| --- | --- |
| A tool answers `sign_in_required` with a link and code | Open the link, approve, then call the tool again. The code expires after 10 minutes; the next tool call gets a new one. |
| `401` with `unauthenticated` from `/mcp` over HTTP | The token is missing, expired or revoked. A client that signs in with OAuth does it again by itself; otherwise get a new token (`npx -y @kovlet/mcp login`, then `token`) and restart the client. |
| "Kovlet could not start this sign-in" in the browser | The client sent a sign-in request Kovlet can't accept (an unknown client, a return address it didn't register, or no PKCE). Remove and re-add the server in the client so it registers again. |
| `list_spaces` reports `not_shared_with_agent` | Ask the agent to call `request_space_access` and open the approve link it returns. |
| The agent doesn't list any Kovlet tools | Restart the agent after `init`. For Codex with `--scope project`, mark the project as trusted. |
| `init` says it found no coding agents | Pass `--client claude-code` (or `cursor`, `windsurf`, `codex`) to configure one anyway. |

### Local development

Run `init` and `login` with `--url http://127.0.0.1:8080`. The approval link then points at the local console (`http://localhost:5173/activate`).

With no console running, approve the code from a terminal with `kovletd dev approve <user_code>`. Or start the server with `kovletd --dev --dev-auto-approve`.

## Next

- [Share live data between two AI-built apps](/docs/multi-app-sync): connect a second app to the same Data Space.
- [Quickstart: web and React](/docs/quickstart-web): finish the app the agent started.
