# Connecting an AI agent to an unLocked CRM account

An AI agent works in a user's unLocked CRM account through the unLocked CRM MCP server, with access the user grants. This page says how an agent gets that access. Everything here comes from the server's own metadata; where this page and the metadata differ, the metadata is right.

- MCP server: `https://mcp.unlockedcrm.ai` (streamable HTTP)
- MCP manifest: https://unlockedcrm.ai/.well-known/mcp.json
- Server card: https://unlockedcrm.ai/.well-known/mcp/server-card.json
- API documentation: https://unlockedcrm.ai/api.md

## OAuth 2.0 (delegated access)

The MCP server is its own authorization server.

| | |
|---|---|
| Issuer | `https://mcp.unlockedcrm.ai` |
| Authorization endpoint | `https://mcp.unlockedcrm.ai/oauth?action=authorize` |
| Token endpoint | `https://mcp.unlockedcrm.ai/oauth?action=token` |
| Revocation endpoint | `https://mcp.unlockedcrm.ai/oauth?action=revoke` |
| Client registration endpoint | `https://mcp.unlockedcrm.ai/oauth?action=register` |
| Grant types | `authorization_code`, `refresh_token` |
| PKCE code challenge method | `S256` |
| Client authentication at the token endpoint | `client_secret_post`, `client_secret_basic`, `private_key_jwt`, `none` |

Metadata, as the server publishes it:

- Authorization server (RFC 8414): https://mcp.unlockedcrm.ai/.well-known/oauth-authorization-server
- Protected resource (RFC 9728): https://mcp.unlockedcrm.ai/.well-known/oauth-protected-resource

Copies of both are kept on this site at https://unlockedcrm.ai/.well-known/oauth-authorization-server and https://unlockedcrm.ai/.well-known/oauth-protected-resource.

### Steps

1. **Register the client.** Either register it at the client registration endpoint (dynamic client registration), or use a client ID metadata document: the server's metadata sets `client_id_metadata_document_supported` to `true`.
2. **Send the user to the authorization endpoint** with the authorization code flow and a PKCE `S256` code challenge, asking for the scopes the agent needs.
3. **Exchange the code** at the token endpoint. A refresh token can be exchanged for a new access token later.
4. **Call the MCP server** with the access token in the `Authorization: Bearer` header.
5. **Revoke the token** at the revocation endpoint when the agent no longer needs access.

### Scopes

Scopes are named `read:<resource>` and `write:<resource>`, for example `read:leads`, `write:leads`, `read:clients` and `read:policies`. The full list is `scopes_supported` in the metadata above. Ask only for the scopes the task needs.

## API key

Instead of OAuth, a scoped API key can be used. The user creates it in unLocked CRM under Settings, then API Keys, choosing its permissions per resource; it is shown once. Send it in the `x-api-key` header, to the MCP server and to the Public API alike (see https://unlockedcrm.ai/api.md). The MCP server's own answer to an unauthenticated request says it accepts `x-api-key` or `Authorization: Bearer <token>`; send an API key in `x-api-key`, as the developer portal's example does, and keep `Authorization: Bearer` for OAuth access tokens.

## Connecting a coding agent (Claude Code, Cursor)

The developer portal's MCP example connects any MCP client with an API key:

```bash
npx -y mcp-remote https://mcp.unlockedcrm.ai --header x-api-key:YOUR_API_KEY
```

A client that speaks streamable HTTP itself takes the same address and header. For Claude Code, a project `.mcp.json`:

```json
{
  "mcpServers": {
    "unlocked-crm": {
      "type": "http",
      "url": "https://mcp.unlockedcrm.ai",
      "headers": { "x-api-key": "${UNLOCKED_API_KEY}" }
    }
  }
}
```

For Cursor, `.cursor/mcp.json` with the same `url` and `"headers": { "x-api-key": "${env:UNLOCKED_API_KEY}" }`. Keep the key in an environment variable, never in the file or a prompt. The tools the server offers are listed to the client once it is connected.

## New accounts

New unLocked CRM accounts sign up at https://app.unlockedcrm.ai/signup.
