> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tablepro.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Pairing

> One-click flow that issues a scoped MCP token to an extension through a PKCE-style code exchange

Four steps: generate a verifier, open a deep link, catch the one-time code, trade it for a token over
localhost. TablePro releases the token only to the caller that can produce the verifier, so an app
that intercepts the redirect holds a code it cannot spend.

Nothing about this is Raycast-specific. Any client that can receive a callback, through its own URL
scheme or a loopback HTTP listener, can pair.

## Sequence

```mermaid theme={null}
sequenceDiagram
    participant E as Extension
    participant T as TablePro app
    participant U as User
    participant M as MCP server (HTTP)

    E->>E: verifier = randomBytes(32).base64url
    E->>E: challenge = base64url(SHA-256(verifier))
    E->>T: open tablepro://integrations/pair<br/>?client=…&challenge=…&redirect=…&response_mode=query&state=…
    T->>M: start server (refused while MCP is off)
    T->>U: Approval sheet (client, destination, scopes, connections, expiry)
    U->>T: Approve
    T->>T: mint token, hold pending exchange<br/>{ code, plaintext, challenge }, 5 min
    T->>E: open redirect URL<br/>?code=…&state=…
    E->>M: POST /v1/integrations/exchange<br/>{ code, code_verifier: verifier }
    M->>M: SHA-256(verifier) == challenge ?
    M->>E: 200 { token: "tp_…" }
    E->>E: store token in the Keychain
```

The name in the heading is whatever `client` asked to be called, so read the line under it: it names
the address the code is delivered to. Approve only when that address belongs to the app you started
the pairing from.

![Approval sheet headed Allow Raycast to access TablePro, with the delivery address, a permissions picker, a connection list and an expiry picker](https://mintcdn.com/ngquct/FRKr39BjDrtfaK4D/images/mcp-pairing-approval-sheet.png?fit=max\&auto=format\&n=FRKr39BjDrtfaK4D\&q=85\&s=323c6237905ce6a8592d166eb1a85742)

Scope, connections and expiry are all editable before Approve

## The whole client, in one file

```ts theme={null}
import { randomBytes, createHash } from "node:crypto";

const b64url = (b: Buffer) =>
  b.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");

// Step 1. Keep the verifier and the state in memory until the exchange. Never log the verifier.
const verifier = b64url(randomBytes(32));
const challenge = b64url(createHash("sha256").update(verifier).digest());
const state = b64url(randomBytes(16));

// Step 2. Open the deep link. The parameters are on the URL scheme page.
const params = new URLSearchParams({
  client: "My Editor on macbook-pro",
  challenge,
  redirect: "http://127.0.0.1:7391/callback",
  response_mode: "query",
  state,
  scopes: "readWrite",
});
await openUrl(`tablepro://integrations/pair?${params}`); // however your host opens a URL

// Step 3. Your callback receives ?code=<uuid>&state=<state>, ?error=access_denied when the user says no,
// or ?error=server_error when TablePro could not issue the token after the user approved.
// 23508 is the default port. Make it a setting: if the port is taken, the server binds another one,
// and the Status row in Settings > MCP shows the port in use.
export async function exchange(callback: URL, port = 23508): Promise<string> {
  const query = callback.searchParams;
  if (query.get("state") !== state) throw new Error("pairing state mismatch");
  const code = query.get("code");
  if (!code) throw new Error(`pairing refused: ${query.get("error")}`);

  const res = await fetch(`http://127.0.0.1:${port}/v1/integrations/exchange`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ code, code_verifier: verifier }),
  });
  if (!res.ok) throw new Error(`pairing failed: ${res.status}`);

  const { token, scope } = await res.json(); // scope: what the user granted, see Scopes
  return token; // Step 4. Straight into the Keychain, never a plain file.
}
```

Three constraints decide whether TablePro accepts the request at all:

* The **verifier** is 43 to 128 characters from `A-Z a-z 0-9 - . _ ~`. 32 random bytes in base64url
  is 43.
* The **challenge** is its base64url SHA-256, so exactly 43 base64url characters.
* The **redirect** is a loopback `http` or `https` URL (`127.0.0.1`, `localhost`, `::1`), or a
  private-use scheme an installed app has registered. Anything else is refused with *"The redirect
  address is not a local callback, so pairing was refused."* That covers a redirect carrying
  credentials, `tablepro://` and the database URL schemes TablePro opens, a scheme a web browser
  handles (such as `google-chrome:`), and network schemes whose handler fetches from the host they
  name, such as `smb://`, `ssh://` and `webcal://`.

The exchange endpoint takes no bearer token: the single-use code plus the verifier is the credential.
The public HTTP routes are `/v1/integrations/exchange` and `/mcp`; both accept `POST` only.
The bundled command also uses a [private revocation route](#revoking-a-token).

## Response modes

`response_mode` decides how the answer reaches `redirect`. Send `query`. Use `context` when your host
passes an extension a single launch parameter named `context`, as Raycast does.

| `response_mode` | Approve | Deny |
| - | - | - |
| `query` | `?code=<uuid>&state=<state>` | `?error=access_denied&error_description=user_denied&state=<state>` |
| `context` | `?context={"code":"<uuid>","state":"<state>"}` | `?context={"error":"access_denied","error_description":"user_denied","state":"<state>"}` |
| absent (deprecated) | `?context={"code":"<uuid>"}` for `raycast://`, `?code=<uuid>` for any other scheme | `error=denied` and `error_description=user_denied`, wrapped the same way |

When the user approves and TablePro then cannot issue the token, the redirect carries
`error=server_error` and `error_description=token_not_issued`, with `state`, in the same shape as a
deny for the request's mode. Treat it as a failure to retry, not as a refusal.

The `context` value is JSON with sorted keys, percent-encoded like any other query value. Any other
`response_mode` drops the link: no sheet opens and nothing reaches `redirect`. Query items already on
`redirect` stay as they were, with these appended after them.

### State

`state` is optional and opaque: up to 1,024 UTF-8 bytes, returned unchanged on approve and on deny,
in every mode. A longer one drops the link the same way. Send a fresh random value with each request
and drop any callback whose `state` does not match the request you started.

### Deprecated: no `response_mode`

A link without `response_mode` still gets the delivery in the last row of the table, and is
deprecated. A later release will read a missing `response_mode` as `query`, so send it explicitly.
[Versioning](https://docs.tablepro.app/developers/versioning.md) has the policy.

## Scopes

`scopes` holds one permission level (`readOnly`, `readWrite` or `fullAccess`) plus, for a launcher,
`connections:display`, separated by spaces or commas. Unknown entries are skipped. When the list
names more than one level, the sheet starts at the lowest.

`connections:display` lets the token call [`list_connections`](https://docs.tablepro.app/developers/mcp-tools#listing-for-display)
with `purpose: "display"`, which adds connections hidden from AI and each connection's user name. Ask
for it only to show the user their connections, never to feed a model. The sheet offers it only while
**Allow apps to list connections hidden from AI** is on under **Access** in **Settings > MCP**, and its checkbox
starts off. Otherwise the token is issued without it.

The exchange response names what was granted:

```json theme={null}
{ "token": "tp_…", "scope": "connections:display resources:read tools:read" }
```

`scope` lists every granted scope, sorted and space separated. Read it instead of assuming the
request went through: the user can lower the permission level or leave the checkbox off.

## What the user approves

The sheet names the client and counts down the five minutes the request is good for, dimming
**Approve** when it runs out. Three controls sit under that: **Permissions** (starting at what
the link asked for, movable in either direction), **Connections** (**All**, or **Selected** with a
searchable checklist and **Select All** and **Select None**), and **Expires** (**Never**, 1, 7, 30, 60
or 90 days, or **Custom** with a date). A link that asks for `connections:display` adds
**List connections hidden from AI**, off until the user ticks it. The link's parameters are a
request, not a grant. **Deny** is the default button: Return and Escape both deny, and **Approve**
takes a click. The sheet does not take focus from another app; TablePro's Dock icon bounces instead.

Approving mints the token, holds the plaintext against a one-time code for 5 minutes, and opens the
redirect. Pairing again creates a separate token. Retire an old token through
[revocation](#revoking-a-token) once the client uses its replacement.

## Revoking a token

Revoke a client's token in **Settings > MCP > Tokens**. For the bundled macOS command,
use [`tablepro unpair`](https://docs.tablepro.app/integrations/terminal#status-and-pairing).

The command sends `POST /v1/integrations/revoke` over the private Unix socket, with a form-encoded
`token` field. The route does not exist on the TCP listener and is outside the
[stability contract](https://docs.tablepro.app/developers/versioning.md#what-is-not-under-the-contract). Do not use it as a
public client API.

A successful response is `200 {}`, including for an unknown or already revoked token. A `503`
means revocation was not saved: the token remains valid. The server refuses the stdio bridge
credential with `400 unsupported_token_type`.

## Security properties

| Property | How |
| - | - |
| The token is never in a URL | It travels over localhost HTTP; the deep link carries only a code. |
| Intercepting the redirect is useless | The code cannot be exchanged without the verifier. |
| A code is single-use | Success, a failed verification, or 5 minutes deletes it. |
| The plaintext token is not persisted | Only a salted SHA-256 hash is saved, in the login keychain. |

## Errors

With **MCP server** off, the pair link stops before the approval sheet with an alert that
names **Settings > MCP**. No redirect is opened, so the extension sees no answer.

Approving can still fail before the client gets a code, such as when the token cannot be saved to the
Keychain. TablePro shows **Pairing Failed** with the reason and opens the redirect with the
[`server_error` answer](#response-modes). Start a new pair request once the cause is fixed. The bundled
`tablepro pair` reports this as a failure and exits 1; see
[Status and pairing](https://docs.tablepro.app/integrations/terminal.md#status-and-pairing).

A failed verification burns the code, so retrying with a guessed verifier is not an option: start a
new pair request.

| Code | Meaning |
| - | - |
| `400` | Malformed body, a missing `code` or `code_verifier`, a field over 1,024 bytes, or a verifier that is not 43 to 128 unreserved characters. |
| `403 Challenge mismatch` | The verifier does not hash to the stored challenge. |
| `404 Pairing code not found` | The code never existed, or was already exchanged. |
| `410 Pairing code expired` | The pending exchange is older than 5 minutes. |
| `429 Too Many Requests` | Five failed exchanges from this address within 5 minutes. Locked out for 15, with `Retry-After` on the response. |

Every failed exchange lands in the activity log under the `auth` category with outcome `denied`.

Clicking **Deny** opens the redirect with the deny response for the request's
[mode](#response-modes).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.