# MCP server

Connect Claude, ChatGPT, Cursor, VS Code or any MCP client to opendesk with a sign-in or an API key, and the tools it offers.

opendesk is an [MCP](https://modelcontextprotocol.io) server. Connect an AI client such as Claude, ChatGPT, Cursor or VS Code and it can search and read tickets, reply, add notes, update and create tickets, attach files, create and update contacts and companies, search the knowledge base, draft articles and read reports. Anything else the API offers, it can reach through the [API bridge](#the-api-bridge).

There are two ways to connect:

- **Sign in with OAuth.** Clients with connectors (the Claude apps, ChatGPT) only need the server URL. You sign in to opendesk, choose a workspace and approve. The client acts as you, with your role.
- **An API key.** Clients that send a header (Claude Code, Cursor, VS Code, scripts) use a key with the scopes you choose.

**Settings → AI clients** in opendesk shows the server URL, copyable setup for each client, the tools offered and the clients you have connected.

| Where | Endpoint |
| --- | --- |
| opendesk Cloud | `https://api.opendesk.sh/mcp` |
| Self-hosted | `https://<your-domain>/mcp` |

The server speaks MCP over Streamable HTTP. Each request stands alone, so there is no session to keep alive.

## Connect with OAuth

Add opendesk as a custom connector with the URL `https://api.opendesk.sh/mcp` (self-hosted: `https://<your-domain>/mcp`). No key, no bridge.

- **Claude** (claude.ai and the desktop app): **Settings → Connectors → Add custom connector**, paste the URL, then **Connect**.
- **ChatGPT**: add a connector (developer mode) with the same URL and OAuth authentication.

The client opens opendesk in your browser. Sign in if you are not, pick the workspace, check what the app asks for and approve. You return to the client, connected.

What it can do:

- The app gets the access you approve, never more than your role allows: viewers read only; agents and up can also reply, update tickets and contacts, and draft articles. If your role changes, the connection follows at once.
- It never gets settings writes, and it can't reach your account (password, sessions, two-factor).
- Everything it does shows up in opendesk as done by you.

Disconnect it any time in **Settings → AI clients**. Admins see every member's connections and can disconnect any of them. Removing a member from the workspace, or changing or resetting your password, disconnects their clients too.

For client developers: opendesk follows the MCP authorization spec. `401` responses from `/mcp` carry `WWW-Authenticate: Bearer resource_metadata="https://api.opendesk.sh/.well-known/oauth-protected-resource/mcp"`. The authorization server metadata is at `/.well-known/oauth-authorization-server` and supports dynamic client registration (`/oauth/register`; redirect URIs must be `https`, or `http` on `127.0.0.1`, `localhost` or `[::1]`), the authorization code flow with PKCE (`S256` only), the `resource` parameter, refresh token rotation and revocation (`/oauth/revoke`). Access tokens last an hour; refresh tokens rotate on every use, and a refresh token used twice ends the connection.

## Create an API key

1. In opendesk, open **Settings → API keys** (admins only).
2. Create a key and give it only the scopes you want the AI client to have. The client sees only the tools those scopes allow (see [Tools](#tools)).
3. Copy the secret (`od_live_...`). It is shown once.

Every tool runs through the public API as that key, so it gets exactly the key's scopes, the same validation, and the same events, activity entries and audit log entries as any other API call. Changes show up in opendesk as made by the API.

Treat the key like a password. Do not commit it to a repository; prefer a prompt or an environment variable, as in the examples below. Delete the key in **Settings → API keys** to cut off access at once.

## Connect a client

The examples use the Cloud endpoint. On a self-hosted install, replace `https://api.opendesk.sh/mcp` with `https://<your-domain>/mcp`.

### Claude Code

```sh
claude mcp add --transport http opendesk https://api.opendesk.sh/mcp \
  --header "Authorization: Bearer od_live_..."
```

Add `--scope project` to share the server with your team through `.mcp.json`. In that case keep the key out of the file and reference an environment variable instead:

```json
{
  "mcpServers": {
    "opendesk": {
      "type": "http",
      "url": "https://api.opendesk.sh/mcp",
      "headers": { "Authorization": "Bearer ${OPENDESK_API_KEY}" }
    }
  }
}
```

### Claude Desktop

The simplest way is a connector with OAuth (see [Connect with OAuth](#connect-with-oauth)). To use an API key instead, connect through the `mcp-remote` bridge (it needs Node.js). Open **Settings → Developer → Edit config** and add:

```json
{
  "mcpServers": {
    "opendesk": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://api.opendesk.sh/mcp", "--header", "Authorization:${OPENDESK_AUTH}"],
      "env": { "OPENDESK_AUTH": "Bearer od_live_..." }
    }
  }
}
```

Restart Claude Desktop. The opendesk tools appear in the tools menu.

### Cursor

Add the server to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project):

```json
{
  "mcpServers": {
    "opendesk": {
      "url": "https://api.opendesk.sh/mcp",
      "headers": { "Authorization": "Bearer od_live_..." }
    }
  }
}
```

Then check **Cursor Settings → MCP** that opendesk is enabled and lists its tools.

### VS Code

Add `.vscode/mcp.json` to your workspace. VS Code asks for the key the first time and stores it securely:

```json
{
  "inputs": [
    { "type": "promptString", "id": "opendesk-key", "description": "opendesk API key", "password": true }
  ],
  "servers": {
    "opendesk": {
      "type": "http",
      "url": "https://api.opendesk.sh/mcp",
      "headers": { "Authorization": "Bearer ${input:opendesk-key}" }
    }
  }
}
```

Start the server from the file or with **MCP: List Servers**, then use the tools in Copilot chat's agent mode.

### Other clients

Any MCP client that supports Streamable HTTP works: with OAuth when it supports the MCP authorization spec, otherwise with `Authorization: Bearer <API key>` on every request.

## Tools

A tool is offered only when the key, or the OAuth connection together with your role, has its scopes.

| Tool | Scope | What it does | Changes data |
| --- | --- | --- | --- |
| `search_tickets` | `tickets:read` | Finds tickets by text, status, priority, severity, assignee, team, label, channel, contact or creation date. At most 50 per call. | No |
| `get_ticket` | `tickets:read` | Reads a ticket with its thread as plain text, internal notes included. | No |
| `list_custom_fields` | `tickets:read` | Lists the custom fields: key, name, type, options and whether a ticket needs the field set to be solved. Filter by `entity` (`ticket`, `contact` or `company`); archived fields only with `include_archived`. | No |
| `reply_to_ticket` | `tickets:write` | Sends a public reply (markdown), optionally with files. The customer receives it. Can set the status after sending. With `direction: "inbound"` it logs what the customer said elsewhere, such as on a call, as their own message instead, and sends nothing. | Yes |
| `draft_reply` | `tickets:write` | Stages a reply (markdown) on the ticket without sending it. Every teammate who opens the ticket finds it in their composer, to edit and send as their own reply. Staging again replaces it; a reply going out clears it. | Yes |
| `add_note` | `tickets:write` | Adds an internal note the customer never sees, optionally with files. | Yes |
| `update_ticket` | `tickets:write` | Changes status, priority, severity, assignee, team, labels or custom fields. | Yes |
| `create_ticket` | `tickets:write` | Creates a ticket for a contact email, optionally with custom field values and files. With a mailbox, the first reply is emailed to the contact. With `direction: "inbound"` the first message is logged as the contact's own request, for one that came in by phone or in person, and nothing is sent. | Yes |
| `upload_attachment` | `tickets:write` | Uploads a file from an https URL (up to 25 MB) or as base64 (up to 6 MB) and returns its `attachment_id`, for `attachment_ids` on the three tools above. | Yes |
| `search_contacts` | `contacts:read` | Finds contacts by name, email, phone or field value, or by company, label or `external_id`. | No |
| `get_contact` | `contacts:read` | Reads a contact by id, email or `external_id`, with their latest tickets when the key also has `tickets:read`. | No |
| `create_contact` | `contacts:write` | Creates a contact with email, name, phone, company, `external_id`, labels, notes and custom fields. | Yes |
| `update_contact` | `contacts:write` | Changes only what you pass. Labels are added and removed by name, fields are merged. | Yes |
| `search_companies` | `contacts:read` | Finds companies by name, domain or field value, or by label or `external_id`. | No |
| `get_company` | `contacts:read` | Reads a company by id, `external_id`, domain or name, with its people. | No |
| `create_company` | `contacts:write` | Creates a company with name, domain, `external_id`, labels, notes and custom fields. | Yes |
| `update_company` | `contacts:write` | Changes only what you pass, as `update_contact`. | Yes |
| `search_knowledge` | `kb:read` | Searches knowledge base articles and knowledge sources; the top matches come with their full text. | No |
| `create_kb_draft` | `kb:write` | Creates an unpublished draft article for the team to review. | Yes |
| `search_wiki` | `wiki:read` | Searches the team's internal wiki; each match comes with where it sits and a passage. | No |
| `get_wiki_page` | `wiki:read` | Reads a wiki page as plain text, with its subpages and its version. | No |
| `create_wiki_page` | `wiki:write` | Adds a wiki page (markdown), at the top level or under another page. | Yes |
| `update_wiki_page` | `wiki:write` | Renames a wiki page or replaces its text (markdown). With the version it read, a teammate's newer edit is never overwritten. | Yes |
| `get_report` | `settings:read` and `tickets:read` | Reads the overview report for a date range. | No |
| `find_api` | any | Finds API routes by keywords or area. | No |
| `describe_api` | any | Describes one route: parameters, body and response. | No |
| `api_read` | any | Calls a `GET` route. | No |
| `api_write` | any write scope | Calls a `POST`, `PUT`, `PATCH` or `DELETE` route. | Yes |

Tickets are referenced by number (`#123`) or id. Assigning by email or moving to a team by name looks the teammate or team up, which needs `settings:read`; with user and team ids it does not.

`create_ticket` and `update_ticket` take custom field values in `fields`, an object keyed by the field keys `list_custom_fields` returns, for example `{"customer": "Acme", "plan": "pro"}`. A select takes an option id, a multi-select a list of them, a date `YYYY-MM-DD` and a user field a user id. On update only the keys you pass change, and `null` clears a field. Values are checked as in the API ([Labels and custom fields](/api/resources/labels-fields/)): an unknown key or a value that does not fit the field is refused.

### Syncing contacts and companies

Give each contact and company the id your own system uses as its `external_id`. The tools find a record by it wherever they take one (`contact`, `company`), and `search_contacts` and `search_companies` filter on it exactly. A `company` can also be its id, domain or exact name; `"none"` removes a contact from their company.

Creating a contact whose email or `external_id` another contact already has, or a company whose domain or `external_id` is taken, fails with `already_exists` and returns that record as `existing`, so the client can update it. Pass `if_exists: "update"` to update it in the same call. Updates never drop labels or field values you did not name. Deleting, merging and blocking contacts stay in the app (or the API bridge, with the same permissions).

### The API bridge

The tools above cover the everyday work. For anything else the API can do, such as saved replies, views, automations, SLA policies or merging tickets, the client can use the bridge: `find_api` searches the API's routes, `describe_api` shows one route's parameters and body, and `api_read` and `api_write` call it. Each call runs as the key or the connected person, with the same permissions, checks and history as the API itself.

Some routes are never reachable through the bridge: signing in and your own account, API keys, webhooks, AI client connections, billing, the instance admin, and any route that takes a password, token or other secret. Secrets in responses are withheld. Files go through `upload_attachment`.

Tools carry MCP annotations, so clients can tell read-only tools from ones that change data and ask you before running them. Results are compact JSON text.

A suggested starting point: `tickets:read`, `contacts:read` and `kb:read` for an assistant that only reads, plus `tickets:write` when you want it to reply and update tickets, and `contacts:write` to keep contacts and companies in sync.

## Limits and security

- Requests without a valid key or token get `401` with `WWW-Authenticate: Bearer` and the `resource_metadata` URL.
- Requests from a browser must come from an origin in `CORS_ORIGINS`; others get `403`. Desktop and command line clients send no origin and are not affected.
- Each key, and each OAuth connection, can make 300 requests a minute to `/mcp`. Over that, the server answers `429`; wait and retry.
- Request bodies, keys, codes and tokens are never logged. Codes and refresh tokens are stored hashed.

## Self-hosting

There is nothing to switch on. The MCP endpoint is part of the `opendesk` service, and the bundled Caddy configuration already sends `/mcp` to it, so it is live at `https://<your-domain>/mcp` as soon as your install is, OAuth included. If you run your own reverse proxy, route `/mcp`, `/oauth/*` and `/.well-known/oauth-*` to the `opendesk` service, like the API.
