# Connect an agent with MCP

> Set up Claude Code, Claude Desktop, Cursor and other MCP clients against your workspace.

Source: https://docs.ligament.ai/build-with-ai/mcp-setup/

Connect an AI client to your workspace’s [MCP server](https://docs.ligament.ai/developers/mcp/index.md) and the agent can query records, read your app spec and propose changesets from inside the chat or editor. You need an API key and a few lines of client configuration.

All clients need the same two things:

| Setting | Value |
| --- | --- |
| URL | `https://app.ligament.ai/api/mcp` |
| Header | `Authorization: Bearer <your key>` |

The server uses the streamable HTTP transport and authenticates with the header only.

## 1\. Create a key for the agent

In **Settings › API keys**, create a key named after the agent and the machine, for example “Claude Code on Priya’s laptop”. Choose the scopes for what the agent should do:

| The agent should | Scopes |
| --- | --- |
| Answer questions about records | `records:read` |
| Also explain access (“why can’t Tomás see this case?”) | `records:read` (the access tools come with it) |
| Read your apps and propose changes for review | `spec:read`, `spec:propose`, `records:read` |
| Apply changes itself | add `spec:apply`. Only for agents you’d trust with the creator’s build permissions |
| Call your workspace’s exposed connectors and scripts | `endpoints:invoke` |

Avoid **Full access** (`*`) for agents: it includes `spec:apply` and every write scope.

Keep the key in an environment variable rather than in a config file you might commit:

```sh
export LIGAMENT_API_KEY=<your key>
```

## 2\. Check the key works

Before configuring a client, check that the server answers with your key:

```sh
curl -s "https://app.ligament.ai/api/mcp" \
  -H "Authorization: Bearer $LIGAMENT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}'
```

```json
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-03-26","capabilities":{"tools":{},"resources":{}},"serverInfo":{"name":"ligament","version":"1.0.0"}}}
```

Then list the tools the key can use:

```sh
curl -s "https://app.ligament.ai/api/mcp" \
  -H "Authorization: Bearer $LIGAMENT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
```

A key with `spec:read`, `spec:propose` and `records:read` lists 21 tools: `spec_catalog`, `spec_list`, `spec_get`, `spec_schema`, `spec_validate`, `spec_plan`, `spec_history`, `changeset_list`, `changeset_get`, `changeset_create`, `changeset_put_items`, `changeset_plan`, `changeset_discard`, `access_whoami`, `access_explain`, `access_effective`, `access_plan`, `records_query`, `records_get`, `records_history` and `records_changes`. A `401` means the key is wrong or revoked; a `403` means it has none of the scopes the server needs.

## 3\. Add the server to your client

### Claude Code

```sh
claude mcp add --transport http ligament https://app.ligament.ai/api/mcp \
  --header "Authorization: Bearer $LIGAMENT_API_KEY"
```

This stores the key’s value in your Claude Code settings. To share the setup with your team without sharing a key, add the server to the project’s `.mcp.json` instead and let each person’s environment supply the key:

```json
{
  "mcpServers": {
    "ligament": {
      "type": "http",
      "url": "https://app.ligament.ai/api/mcp",
      "headers": { "Authorization": "Bearer ${LIGAMENT_API_KEY}" }
    }
  }
}
```

In Claude Code, `/mcp` shows whether the server is connected and how many tools it has.

### Claude Desktop

Claude Desktop starts local MCP servers from `claude_desktop_config.json`. To reach a remote server that authenticates with a header, run it through the `mcp-remote` bridge (needs Node.js):

```json
{
  "mcpServers": {
    "ligament": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://app.ligament.ai/api/mcp", "--header", "Authorization:${AUTH_HEADER}"],
      "env": { "AUTH_HEADER": "Bearer <your key>" }
    }
  }
}
```

The header goes through an environment variable because the value contains a space. Restart Claude Desktop after editing the file.

### Cursor

Add the server to `.cursor/mcp.json` in your project (or `~/.cursor/mcp.json` for every project):

```json
{
  "mcpServers": {
    "ligament": {
      "url": "https://app.ligament.ai/api/mcp",
      "headers": { "Authorization": "Bearer ${env:LIGAMENT_API_KEY}" }
    }
  }
}
```

The server then appears under Cursor’s MCP settings with its tools.

### Other clients

Any client that supports MCP over streamable HTTP with custom headers works: give it the URL and the `Authorization` header from the table at the top of this page. For clients that only run local (stdio) servers, use the `mcp-remote` bridge as in the Claude Desktop example.

## 4\. Try it

Ask the agent something that needs the tools, for example:

> Which critical incidents are still in progress? Use the ligament tools.

The agent should call `records_query` with a `priority` filter. Then give it the [starting prompt](https://docs.ligament.ai/build-with-ai/agent-prompt/index.md) before asking for changes, and put the [AGENTS.md template](https://docs.ligament.ai/build-with-ai/agents-md/index.md) in any repository where agents work on your apps.

To disconnect an agent, revoke its key in **Settings › API keys**. Its next call gets `401`.
