# MCP server

> Connect an MCP client to your workspace: records, access, spec and changeset tools.

Source: https://docs.ligament.ai/developers/mcp/

Your workspace runs a Model Context Protocol (MCP) server. Point an AI client such as Claude Code or Cursor at it and the agent can query records, explain access decisions, read your app definitions and propose changes for a person to review. What the agent can do is decided by the API key you give it, so a key with `spec:propose` lets an agent suggest changes but never apply them.

For step-by-step client setup, see [Connect an agent with MCP](https://docs.ligament.ai/build-with-ai/mcp-setup/index.md). This page describes the server itself.

## Endpoint and transport

```plaintext
https://app.ligament.ai/api/mcp
```

The server speaks MCP’s streamable HTTP transport: JSON-RPC 2.0 over `POST`, one request (or a JSON array of requests) per call, answered with plain JSON. It doesn’t push messages to the client, so no event stream is needed. Authenticate with an API key:

```plaintext
Authorization: Bearer <your key>
Content-Type: application/json
```

The server reports protocol version `2025-03-26` and the server name `ligament`.

## What each scope allows

`tools/list` returns only the tools the key’s scopes allow, and `tools/call` refuses the rest. A key needs at least one of `records:read`, `spec:read`, `spec:propose`, `spec:apply`, `members:write` or `endpoints:invoke` to connect at all.

| Scope | Tools |
| --- | --- |
| `records:read` (or `records:read:<entity>`) | `records_query`, `records_get`, `records_history`, `records_changes`; `access_whoami`, `access_explain`, `access_effective` |
| `records:write` (or `records:write:<entity>`) | `records_change` |
| `spec:read` | `spec_catalog`, `spec_list`, `spec_get`, `spec_schema`, `spec_validate`, `spec_plan`, `spec_history`; `changeset_list`, `changeset_get`, `changeset_plan`; `access_plan`; and the spec resources |
| `spec:propose` | `changeset_create`, `changeset_put_items`, `changeset_discard` |
| `spec:apply` | `spec_apply`, `changeset_apply` |
| `members:write` (admin scope) | `invites_list`, `invites_resend` (the key’s creator must be an owner or admin; see [Inviting people](https://docs.ligament.ai/guides/workspaces/inviting-people/index.md#with-mcp)) |
| `endpoints:invoke` | One tool per connector operation and script your workspace exposes (`connector__<key>__<operation>`, `script__<key>`) |

`*` includes all of these except `members:write`, which a key only has when it names it (see [API keys](https://docs.ligament.ai/developers/api-keys/index.md)). For an agent, create a key with just the scopes it needs. A key with `spec:read`, `spec:propose` and `records:read` lists 21 tools; a key with only `records:read` lists 7.

Tools act as the key’s creator with the key’s role, capped at the creator’s current role, the same as REST calls with that key. The spec and changeset tools, `access_plan` and the spec resources also need the creator to have the Build capability, as the matching REST routes do: a member’s key without it gets `capability_required`. One exception, also as in REST: an [app admin](https://docs.ligament.ai/guides/access/app-admins/index.md)’s key may call `access_plan` for their own app’s permission sets, roles and restrictions. Inputs and results for every tool are in the [MCP tools reference](https://docs.ligament.ai/reference/mcp-tools/index.md).

## Initialize

```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"}}}
```

Notifications such as `notifications/initialized` have no `id` and get an empty `202 Accepted`.

## List tools

```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"}'
```

With a read-only key (`records:read`) the answer lists seven tools. Each has a description and a JSON Schema for its input (one shown here):

```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "tools": [
      { "name": "access_whoami", … },
      { "name": "access_explain", … },
      { "name": "access_effective", … },
      {
        "name": "records_query",
        "description": "List records of an entity: filters ([{field, op, value|values}], ops eq ne contains empty not_empty in lt lte gt gte), match all|any, sort (\"-salary,name\"), q (search), limit (≤ 200), offset. …",
        "inputSchema": {
          "type": "object",
          "required": ["entity"],
          "properties": {
            "entity": { "type": "string", "description": "Entity key, e.g. person" },
            "filters": { "type": "array", "items": { "type": "object" } },
            "match": { "type": "string", "enum": ["all", "any"] },
            "sort": { "type": "string" },
            "q": { "type": "string" },
            "limit": { "type": "number" },
            "offset": { "type": "number" },
            "asOf": { "type": "string", … },
            "knownAt": { "type": "string", … }
          }
        }
      },
      { "name": "records_get", … },
      { "name": "records_history", … },
      { "name": "records_changes", … }
    ]
  }
}
```

## Call a tool

Critical incidents, two at a time:

```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":4,"method":"tools/call","params":{"name":"records_query","arguments":{"entity":"incident","filters":[{"field":"priority","op":"eq","value":"critical"}],"limit":2}}}'
```

The result is MCP text content holding JSON, the same shape as the [REST list](https://docs.ligament.ai/developers/pagination/index.md) (shortened here):

```json
{
  "jsonrpc": "2.0",
  "id": 4,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\"rows\":[{\"title\":\"Payments API returning 500s\",\"number\":\"INC0000035\",\"priority\":\"critical\",\"state\":\"in_progress\",…},{\"title\":\"Laptop battery swelling (#33)\",\"number\":\"INC0000034\",…}],\"total\":13,\"nextCursor\":\"…\",\"nextOffset\":2}"
      }
    ]
  }
}
```

In filters, `@me` means the key’s creator, so `{"field":"assigneeId","op":"eq","value":"@me"}` finds the records assigned to them.

`access_whoami` shows who the key acts as:

```json
{"userId":"vtvYBRvkNm4bYx6I0D9xqXS1lxzj7rBJ","role":"admin","admin":true,"keyId":"cmx1wize20131feutkwlgmkw1","scopes":["records:read"],"evaluator":"v2","accessVersion":427,"canExplainOthers":true}
```

### Proposing a change

With `spec:propose`, an agent creates a changeset that waits for a person to review. Nothing is applied:

```json
{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"changeset_create","arguments":{"title":"Service desk home: add a My open incidents list","note":"Proposed from Claude Code. Adds a list block filtered to the signed-in agent."}}}
```

The result (shortened) records who proposed it, through which key, and links to the review page:

```json
{
  "id": "cmx6arke600je6x6ss0eskqy8",
  "title": "Service desk home: add a My open incidents list",
  "status": "open",
  "createdBy": { "kind": "key", "label": "Ada Admin via API key Claude Code (proposals only) (…4n9P)", … },
  "items": [],
  "url": "https://app.ligament.ai/build/changes/cmx6arke600je6x6ss0eskqy8"
}
```

A person then opens the changeset in **Build › Changes** and applies or discards it. The agent’s loop is `spec_get` → edit the doc → `spec_plan` → `changeset_create` or `changeset_put_items`. See [Let agents propose changes](https://docs.ligament.ai/guides/building-apps/agents-propose/index.md) and [Changesets](https://docs.ligament.ai/guides/building-apps/changesets/index.md).

Even a key with `spec:apply` can’t apply every change by itself: when the workspace requires a person to apply changes made with a key (access rules, by default), `spec_apply` and `changeset_apply` return `proposed: true, applied: false` with the changeset’s `url`, and the change waits for review.

## Resources

With `spec:read`, and a key whose creator has the Build capability, `resources/list` serves the spec catalog and one JSON Schema per artefact type, and `resources/templates/list` returns the template `ligament://spec/schema/{type}`:

| URI | Content |
| --- | --- |
| `ligament://spec/catalog` | Artefact types, entities and fields, roles, components and blocks (same as `spec_catalog`) |
| `ligament://spec/schema/<type>` | The JSON Schema of one artefact type, for example `page` |

Read one with `resources/read` and `{"uri": "…"}`.

Without the Build capability both lists are empty, and `resources/read` answers a JSON-RPC error:

```json
{"jsonrpc":"2.0","id":3,"error":{"code":-32001,"message":"Only workspace admins, or roles with the Build capability, can use Build","data":{"uri":"ligament://spec/catalog","code":"capability_required","required":["build:use"],"message":"Only workspace admins, or roles with the Build capability, can use Build"}}}
```

## Errors

Problems with the request itself are JSON-RPC errors:

| Situation | HTTP | Response |
| --- | --- | --- |
| No `Authorization` header | 401 | `{"jsonrpc":"2.0","id":null,"error":{"code":-32001,"message":"Missing Authorization header"}}` |
| Invalid or revoked key | 401 | `error.code` `-32001`, `"Invalid or revoked API key"` |
| Key without any MCP scope | 403 | `error.code` `-32001`, with the usual `insufficient_scope` body in `error.data`. It names `endpoints:invoke`, but `records:read`, `members:write` or a spec scope also let the key connect |
| Body isn’t JSON | 400 | `{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"parse error"}}` |
| Unknown method | 200 | `{"jsonrpc":"2.0","id":7,"error":{"code":-32601,"message":"method not found: prompts/list"}}` |

When a tool refuses a call, for example because the key lacks the tool’s scope or the creator can’t access the record, the request still succeeds and the tool result has `isError: true`. The text is JSON with `message`, `code` and the details:

```json
{"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"{\"message\":\"API key lacks scope \\\"records:write:incident\\\" (needed for records_change)\",\"code\":\"insufficient_scope\",\"required\":[\"records:write:incident\"]}"}],"isError":true}}
```

An agent can read that and tell you which key it needs.

## Your workspace’s own tools

With `endpoints:invoke`, `tools/list` also includes the connectors and scripts your workspace has chosen to expose: one tool per connector operation (`connector__<connector>__<operation>`) and one per script (`script__<key>`). They run as the key’s creator, at most with member rights. Only items marked as exposed appear, so nothing is published to agents by default.
