# Connect accounts (MCP)

Source: https://ampost.io/docs/mcp/accounts · Full reference: https://ampost.io/llms-full.txt

Each MCP tool is the REST operation of the same name: the same arguments (path parameters and body fields in one object), the same result as `structuredContent`, the same error codes and rate limits. `tools/list` shows only the tools the key's or app's scopes allow; another answers `INSUFFICIENT_SCOPE`. A failed call returns `isError: true` with the REST error body as text.

### Browser-Assisted Account Connection

`POST /api/accounts/connect` creates a ten-minute connection request; `GET /api/accounts/connect/{connectRequestId}` reads its status. Show the complete `connectUrl` to the user once and tell them to open it in a browser. The URL fragment is a one-time secret: never log, analyze, transform or repeat it after that handoff, and never ask the user to paste it back. Provider consent cannot be completed headlessly or inside the LLM conversation. The create response is the only result that contains `connectUrl`.

To reconnect an account (revoked, or active with `health.needsReconnect`), pass its `accountId`; `platform` may be omitted. An active account gets fresh tokens and permissions and stays in its set; a revoked one is reactivated. For a new connection, `expectedUsername` (the `username` accounts_get would show; Facebook: the Page name; case and a leading @ ignored) or `expectedPlatformAccountId` pins the account the user must sign in to. If the user signs in to any other account, the request fails with `ACCOUNT_MISMATCH` and nothing is written.

Poll every 2-5 seconds until the status is `connected` (then `accountId` is the account; a reconnected account keeps its id), `failed` or `expired`. On `failed` or `expired`, `error.message` says why and what the user should do next; relay it, and offer a new link only when it says so. `error.code` is one of `USER_CANCELLED` (the user cancelled or declined consent), `SUPERSEDED` (a newer request for this platform and set replaced this one; poll the newer one. A new request also replaces one the user opened but did not finish, so create one when the user lost or closed the page), `REQUEST_EXPIRED`, `OAUTH_DENIED`, `REQUIRED_PERMISSIONS_MISSING` (the platform did not grant a permission Ampost needs; if the app is not approved for it, retrying won't help), `ACCOUNT_MISMATCH`, `ACCOUNT_ALREADY_CONNECTED`, `PLATFORM_ALREADY_CONNECTED`, `ACCOUNT_LIMIT_REACHED`, `SOCIAL_ACCOUNT_IN_USE` (Free: the social account is connected in another Ampost workspace, or was disconnected from one less than 30 days ago; a paid plan can connect it), `PLATFORM_SET_NOT_FOUND`, `API_KEY_REVOKED` or `CONNECTION_FAILED`. Status results never include `connectUrl`, the fragment token, provider tokens, authorization codes, OAuth state or raw provider errors. Another user gets 404.

Embed account connection in your app: pass `redirectUrl` (absolute `https`, `http` only for localhost, at most 2048 characters, no user name or password) and optionally `state` (at most 512 characters). When the request ends, connected, failed (also a cancel or declined consent) or expired, Ampost's result page tells the browser that went through the flow that it is leaving Ampost for your host and links to `redirectUrl` (a click, not an automatic redirect) with `status` (`connected`, `failed` or `expired`), `connectRequestId`, `platform`, `accountId` (connected) or `error` (the status resource's `error.code`, e.g. `USER_CANCELLED`) and `state` unchanged; your own query parameters stay. No tokens are added. Anyone can forge these parameters, so confirm with `GET /api/accounts/connect/{connectRequestId}` before acting. The URL is stored with the request and shown (its host) on the confirmation page; Ampost never takes a redirect from a callback URL. It works for OAuth platforms, the Telegram and Bluesky form and Facebook Page selection.

There are no separate profiles (platform sets group accounts) or headless authorization: the user always finishes in a browser. Facebook Page selection is hosted by Ampost in the browser; a reconnect or an expected account offers only that Page. Telegram and Bluesky have no consent screen: the `connectUrl` opens an Ampost page where the user enters their bot token and channel (Telegram) or handle and app password (Bluesky). Discord asks the user to pick the server and channel. On Free, X needs a confirmed email first; before that `accounts_connect` fails with `UPGRADE_REQUIRED`. A coming-soon platform (`availability: coming_soon`) fails with 403 `PLATFORM_COMING_SOON` for accounts it is not open to yet, reconnects included.

### MCP Browser-Assisted Account Connection

`accounts_connect` takes `platform` and an optional `platformSetId`, or `accountId` to reconnect, plus the optional `expectedUsername` / `expectedPlatformAccountId` and `redirectUrl` / `state`, with the same service, `connectPlatform` rate limit, ten-minute expiry and errors as REST. Show the returned `connectUrl` to the user, then call `accounts_connect_status` with `connectRequestId` every 2-5 seconds. Never ask the user for an access token, OAuth authorization code, password, bot token, app password, state value, URL fragment or Facebook Page token: Telegram and Bluesky credentials are typed on the Ampost page, not in the conversation.

### Opening Links in the User's Browser (MCP)

On MCP protocol revision 2026-07-28, a client that declares the `elicitation.url` capability does not get `connectUrl` (`accounts_connect`) or `uploadPageUrl` (`media_upload_create`) in the result. Ampost answers the call with a URL-mode elicitation instead: the client shows the user the page address, opens it in the browser after the user agrees, and retries the call. The result then has every other field, and its note says the page was opened. The link never reaches the model or the chat. If the user declines, or the client does not support URL elicitation (every 2025-era client, since this server keeps no sessions), the result has the link as before. REST is unchanged.
