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

# Build your own client

> How the Widgetic MCP server behaves around a call, for people who write their own client: the tool contract, questions before a build, progress, files, errors and several agents on one account

Most people use the server through an assistant that already handles everything on this page. Read it when you write the client yourself: an assistant, a script that calls the server with an API key, a test. It covers what a client sees around a tool call. The [tools reference](https://docs.widgetic.com/docs/agents/tools.md) covers the tools, and [Connect your assistant](https://docs.widgetic.com/docs/agents/connect.md) the setup.

## The protocol in short

* **One endpoint.** `POST https://mcp.widgetic.com/`, JSON-RPC 2.0. Every request carries its own credential, `Content-Type: application/json` and an `Accept` that lists both `application/json` and `text/event-stream`.
* **One JSON document per answer.** The server is stateless: there is no session to open, no stream to hold and nothing to listen on. A `GET` that asks for `text/event-stream` gets `405` with `Allow: POST, OPTIONS`. A call that takes time answers at once, and you follow it with later calls: see [While a build runs](#while-a-build-runs).
* **Revisions.** The server speaks revision `2025-11-25` of MCP and the ones before it. A request that names revision `2026-07-28`, in the `MCP-Protocol-Version` header or in `_meta["io.modelcontextprotocol/protocolVersion"]`, is answered the way that revision says: no `initialize`, a `resultType` on every result, a `server/discover` call that lists what the server accepts, and a `tools/list` that says how long to keep the list (`ttlMs`, one minute, `cacheScope: "private"`). A request that names anything else is answered as it always was.

## Check the tools without a key

The version of the tool contract and the names of the tools are published at an address that needs no credential:

```bash theme={"theme":"css-variables"}
curl -s https://mcp.widgetic.com/.well-known/widgetic-mcp-contract
```

```json theme={"theme":"css-variables"}
{
  "schemaVersion": 1,
  "server": "widgetic",
  "contractVersion": "1.26.0",
  "toolCount": 56,
  "tools": ["get_profile", "get_account_usage", "create_widget", "..."]
}
```

| Field | What it holds |
| - | - |
| `schemaVersion` | The shape of this document. It changes only when a program that reads it would have to change too |
| `server` | The name the server gives itself, the `serverInfo.name` of `server/discover` and `initialize` |
| `contractVersion` | The version of the tool contract as a whole, the `serverInfo.version` of those two calls. It goes up when the tools change: one is added, or the words or the inputs of one change |
| `toolCount` | How many tools there are, so that a program that cut the list short can tell |
| `tools` | The names `tools/list` gives, in the contract's order |

Use it before a release, or in a test, to check that the tools your client was written for are the ones the server serves: compare `contractVersion` and `tools` with what the client expects, and read `tools/list` again when they differ. The document has no descriptions, no input schemas and nothing that depends on who asks, so it is the same for everyone. It answers `GET` and `HEAD`, and it sends no CORS headers: read it from a server or a script, not from a web page.

## Questions before a build

When a request to `create_widget` is very open ("a widget for my bakery"), the server does not start a build and spend a credit on a guess. It asks a few short questions first, and builds once they are answered. `revise_widget` does the same for a change request that does not say what should change. A question starts nothing and costs no credit.

**What it asks**

* **For a new widget:** what kind of widget it should be (a quiz or poll, a countdown, an image gallery or carousel, an FAQ or list, a timeline, a chart or calculator, or the person's own words), what it should look like (clean and light, dark and bold, playful and colorful, matching their brand colors, or their own words) and, optionally, anything it must say or show. A question the call already answers is left out.
* **For a change:** what should change (colors and style, layout, texts and content, behavior and animation, sizes and spacing; several can be chosen) and, optionally, a description of the change.
* **Nothing else, and never a secret.** What the person types is cut to the room its field has.

**When it asks**

Only for a request that is very open. A request with files or media library items attached builds at once, and so does one with a longer description. When the server is not sure that a request is too open, or cannot decide, it builds as asked: a question can prevent a wasted build and never blocks a real one. A retry of a build that already started is never asked again.

`suggest_widgets` asks questions of its own, up to three and once, when a goal is too open to suggest widgets from: its `status` is `needs_details`, the questions come in the answer, and you call the tool again with the answers in `details`. `create_widget_batch` and `replicate_widget` never ask.

**How the questions reach your client**

> [tab] In words (every client)
>
> The call comes back as a tool error that says nothing was started and no credits were used, and lists the questions. Put them to the person, then call the same tool again with the whole request and the answers added to it. The server keeps nothing between the two calls, so the second call carries everything.

> [tab] As a form (revision 2026-07-28)
>
> A client on revision `2026-07-28` that says it can show a form gets `resultType: "input_required"` with the questions in `inputRequests`, in place of the tool error. It says so with `elicitation` in the capabilities it sends in `_meta["io.modelcontextprotocol/clientCapabilities"]`: an empty object, or one with `form`. A client that declares nothing, or only that it can open links, is never sent a form and gets the tool error described in the other tab.
>
> Show the form, then call the tool again, as a new request, with the answers in `params.inputResponses`. What the person did decides what follows:
>
> | The person | What happens |
> | - | - |
> | Answers | The widget is built with the answers in it |
> | Skips | The widget is built from what was said |
> | Closes the form | Nothing is built and nothing is charged |

An answer becomes an argument of the call before anything checks it, so the content checks and the length limits read it exactly as they read the description.

## While a build runs

`create_widget` and `revise_widget` start the work and answer at once. They, `get_widget`, `show_widget` and `cancel_widget_creation` all return the same state object, so one reader serves all five. This is what `get_widget` returns a minute into a build:

```json theme={"theme":"css-variables"}
{
  "widget_id": "7c0f3a5e-2b8d-4a47-9c1e-5d6f0a1b2c3d",
  "title": "Product launch countdown",
  "phase": "generating",
  "progress": 42,
  "status_text": "Building your widget.",
  "note": null,
  "preview_url": null,
  "composition_id": null,
  "published_version": null,
  "serving_status": "not_published",
  "revision": "9f3a1c7e5b2d4a6c"
}
```

| Field | What it holds |
| - | - |
| `phase` | `queued`, `generating`, `ready`, `failed` or `cancelled` |
| `progress` | 0 to 99 while a build runs. 100 only once `phase` is `ready`, so a progress bar never says "done" early. 0 for a build that failed or was cancelled |
| `status_text` | One sentence that is safe to show as it is |
| `note` | An explanation, when something needs one: why a build failed, that a finished build was kept as a draft, why embeds are paused. Show it as written. `null` otherwise |
| `preview_url` | The live preview of the current draft. `null` until a draft exists |
| `composition_id` | What `update_widget_customization` and `get_embed_code` take. `null` until the widget is published |
| `published_version`, `serving_status` | The version embeds show, and whether they are `serving`, `paused` or `not_published` |
| `revision` | A token for the state the widget is in now: see [Several agents on one account](#several-agents-on-one-account) |

**Poll `get_widget`** every 5 to 10 seconds until `phase` is `ready`, `failed` or `cancelled`. It uses no credits, and a build usually takes a few minutes. There is no push, and no progress inside a single call: the figure moves in coarse steps and there is no time estimate. Polling faster does not make the build quicker, and each call counts against the tool's budget for the minute.

**What the server keeps true**

* The state is read from stored records, not from the memory of one server, so any server can answer and a restart loses nothing.
* A build that stops reporting for 5 minutes is reported as `failed` with a note, not as `generating` for ever. A widget with no draft and no build record is `queued` for its first 2 minutes and `failed` after that.
* A failed or cancelled revision never erases the draft the person already has: the widget stays `ready`, with a note.
* Credits come back when a build fails.

**What a build in progress blocks**

While a widget is `queued` or `generating`, `revise_widget`, `publish_widget` and `delete_widget` are refused for it, each with a sentence that says nothing was started, published or deleted. `cancel_widget_creation` marks the build as cancelled, but it cannot stop work the generator has already begun, so a draft can still appear afterwards. For 2 minutes after a stop, `delete_widget` is refused as well, because the stopped build may still be writing to the widget; the refusal says to try again in a few seconds.

**Batches, translations and the rest**

`create_widget_batch` answers at once with one entry for each widget and returns no state object: follow each widget with `get_widget`, as above. `create_translation` and `add_translation_languages` are the one place where a single call waits for work. They wait for under a minute, then answer with what they have (`finished` is `false` while some languages are still being made), and you follow them with `get_translation` until its `state` is `ready`. A translation that has not finished is not a failure and the work goes on without you.

## Saving files

`save_to_media_library` runs inside the call and returns a result for every file, so there is no live percentage to follow.

* **What it takes.** Up to 10 HTTPS links in `file_urls`, and up to 10 attached `files`, filed in the folder you name (`Assets` when you name none). A link has to answer directly: redirects are not followed. A file can be up to 250 MB, an SVG up to 2 MB, a JSON or Excel file up to 10 MB.
* **What it returns.** `saved` lists each file with its `media_id`, `name`, `kind`, `folder` and `thumbnail_url`. `failed` lists the `position` of each file that could not be saved and the `reason`, in words: the type is not supported, the file is too big, the link did not answer, or the storage allowance is full. One bad file does not stop the others.
* **Room.** Saved files count against the storage allowance. `get_account_usage` reports `storage_used_mb` and `storage_limit_mb` before you save many.

`create_widget` and `revise_widget` take up to 5 `files` of their own and up to 5 `media_ids` of images already in the media library. The `files` argument holds what ChatGPT hands over for an attachment (a temporary `download_url` and a `file_id`), and the server fetches those only from the file hosts of OpenAI and ChatGPT. Any other client saves the image with `save_to_media_library` first and passes the `media_id` it gets back. A file that cannot be used refuses the whole call before any credit moves, and the answer names it and says why.

## Errors

A failure is one of two things, and a client should treat them differently. An HTTP error says the request did not reach a tool at all. A tool error says the tool ran and refused. The event methods of [MCP events](https://docs.widgetic.com/docs/webhooks/mcp-events.md#errors) refuse a third way, with HTTP `200` and a JSON-RPC `error` that has its own codes.

### At the door

The server checks the request in this order: the credential and the plan that goes with it, then `Accept`, `Content-Type`, the size of the body and the JSON in it. An answer about the credential, the plan or the rate has a body of the form `{ "error": "...", "error_description": "..." }`. An answer about the request itself (`400`, `406`, `413`, `415`) is a JSON-RPC error: `{ "jsonrpc": "2.0", "id": null, "error": { "code": ..., "message": "..." } }`.

| Status | What it means | What to do |
| - | - | - |
| `401` | No credential, or one that is not a Bearer credential (`error` is `unauthorized`), or an access token that is expired or malformed, or an API key that is invalid or revoked (`error` is `invalid_token`). `WWW-Authenticate` names where the sign-in details are published, in `resource_metadata` | Renew the access token with its refresh token, or sign in again; for a key, check it |
| `403` | The credential is fine and may not use the server: the workspace is in its free trial or its plan has no API access (the message says so), the key was made with a limit (the message says the endpoint needs a key made with full access), or the key names no account that can own widgets. See [Authentication](https://docs.widgetic.com/docs/agents/authentication.md) | Choose a plan for the workspace, make a key with full access, or connect with OAuth |
| `403` with `error` `access_denied` | Widgetic is switched off for the app you connect from, for the moment. The message reads "Widgetic is not available in this app right now." | Use another client, or try again later |
| `400` | The body is not valid JSON (`-32700`) | Send valid JSON |
| `405` | The server answers `POST` only. The body is `{ "error": "method_not_allowed" }` and `Allow` lists `POST, OPTIONS` | Send requests with `POST` |
| `406` | `Accept` does not list both `application/json` and `text/event-stream` | Send both |
| `413` | The request body is over 1 MiB | Send less |
| `415` | `Content-Type` is not `application/json` | Send `application/json` |
| `429` | Too many requests from your network address, or for your account, in a short time. The `RateLimit-*` headers say where you stand | Wait for the time in `Retry-After` |
| `503` | Widgetic could not check the credential just now. `Retry-After` says when to try again | Try again after that time |

Any other address on the host answers `404` with `{ "error": "not_found" }`. A browser that opens the bare host is sent to the [overview of these docs](https://docs.widgetic.com/docs/agents/overview.md).

### Inside a tool

A tool error comes back with HTTP status `200`. The result has `isError` set to `true` and one text item, a sentence written for the person to read as it is. It has no `structuredContent`.

```json theme={"theme":"css-variables"}
{
  "jsonrpc": "2.0",
  "id": 7,
  "result": {
    "isError": true,
    "content": [
      {
        "type": "text",
        "text": "The build of this widget was stopped but is still shutting down, so it cannot be deleted for a moment. Try again in a few seconds. Nothing was deleted."
      }
    ]
  }
}
```

Show the sentence to the person. Decide what to do from `isError` and from the tool you called, and do not match on the words: they are written for people and can be improved from one release to the next. Every refusal says whether anything was changed. A refusal that starts nothing says that no credits were used.

| The sentence is about | What it means | What to do |
| - | - | - |
| A permission the tool needs | The connection was approved without it. The result also carries a `WWW-Authenticate` challenge in `_meta["mcp/www_authenticate"]`, with `error="insufficient_scope"` and the missing permission in `scope`. That is how ChatGPT knows to show its connect screen again | Connect again and approve every permission |
| The workspace's plan | The workspace has no plan, or one that does not include what the tool does. The sentence is the plan's own: see [When the workspace has no plan](https://docs.widgetic.com/docs/agents/authentication.md#when-the-workspace-has-no-plan) | Choose a plan, or ask the workspace's owner |
| Too many calls | The tool has its own budget for the minute, and the sentence says how many calls were used. Starting a build has a smaller budget than reading | Wait a moment, and slow down |
| A widget that changed | The `expected_revision` you passed is not the current one. Nothing was changed and no credits were used | Read the widget again, then decide: see [Several agents on one account](#several-agents-on-one-account) |
| A build in progress, or one that was just stopped | The tool cannot act on the widget yet. Nothing was started, published or deleted | Wait for the build to finish, or try again in a few seconds |
| Questions before a build | The request is too open and your client cannot show a form: see [Questions before a build](#questions-before-a-build). Nothing was started and no credits were used | Ask the questions, then call again with the answers |
| A file or a text document | It cannot be used, and the sentence says why. The whole call is refused before any credit moves | Fix what it names, or leave it out |

## Several agents on one account

Any number of clients can be connected to the same workspace at once: ChatGPT, two Cursor windows, Claude Code in a terminal, a script with an API key. Each connection is separate and has its own grant, which the person can revoke without touching the others. They all work as the same account in the same workspace, so they see the same widgets, the same media library, the same Brand Kit, the same workflows, A/B tests and translations, and they spend the same credits.

There is no push between agents. One is not told when another changes something: it sees the change the next time it reads. The one notice that exists is [MCP events](https://docs.widgetic.com/docs/webhooks/mcp-events.md), and it tells a subscribed app that a visitor sent an entry into a widget, not that another agent changed it. Reading entries (`list_widget_data`, `get_widget_data`) changes nothing, so several agents can do it at once.

### What is protected

A tool that changes a widget takes the `revision` the widget had when the agent read it, as `expected_revision`: `revise_widget`, `publish_widget`, `unpublish_widget`, `rename_widget`, `delete_widget`, `update_widget_customization`, `save_embed_settings`, `apply_embed_code` and `add_content_from_files`. `save_workflow` and `publish_workflow` do the same with a workflow's `revision`. When the token is no longer the current one, the tool does nothing, uses no credits and says the widget has changed, so the agent reads it again instead of writing over somebody else's change. Pass it whenever you read first. The details are in [Changing a widget that may have changed](https://docs.widgetic.com/docs/agents/tools.md#changing-a-widget-that-may-have-changed).

A revision is a short opaque token, 16 hexadecimal characters. It moves when the widget is renamed, built, published, unpublished or set live, and not for a thumbnail or any change nobody would call a change of the widget. Copy it as it is.

### What is not protected

> [!WARNING]
>
> Two agents that ask for the same thing both get it, and both are charged. Look at `list_widgets` before you try again after a call that may or may not have gone through.

* **Starting a build.** `create_widget` has a repeat guard, but a narrow one: the same title (capital letters ignored) from the same account within two minutes returns the widget already started, and charges nothing. Another title, or the same one two minutes later, starts another widget. The same holds for each entry of `create_widget_batch`, and it refuses a second batch within the same minute.
* **Copies and new things.** `duplicate_composition` adds a copy at every call, up to 10 for a widget. `save_workflow` and `save_ab_test` without an id make another one at every call, and so does a retry after a timeout: check `list_workflows` or `list_ab_tests` first.
* **The Brand Kit.** `update_brand_kit` has no revision. The later write wins, and `colors` replaces the whole palette, so an agent that read the palette before another one changed it, and sends it back, undoes the other's colors. Read it again with `get_brand_kit` before you write. The answer carries what each changed part was before, so nothing is lost for good.
* **The media library.** `manage_media_library` renames and moves files without a lock, so the later of two renames of a file wins. `delete_media_file` is final for everyone.
* **Final for everyone.** `delete_widget`, a stop with `set_ab_test_state` and `cancel_widget_batch` cannot be undone, and an agent that is still waiting for what they ended finds it deleted, stopped or cancelled. The exact title or name the person confirmed protects against the wrong target, not against another agent that is still working on the right one. Pass `expected_revision` to `delete_widget` to refuse the delete when the widget has changed since you read it.
* **Offline for everyone.** `unpublish_widget` takes a widget offline for every agent, until any agent publishes it again, or a revision that was not asked to stay a draft does.

## Checklist for a client

* Send `Content-Type: application/json` and an `Accept` that lists both `application/json` and `text/event-stream`.
* Treat an HTTP error and a tool error (`isError`) differently, and show the sentence of a tool error as it is.
* Handle the questions before a build: as words in every client, as a form in a client on revision `2026-07-28` that declares one.
* Poll `get_widget` every 5 to 10 seconds, and stop at `ready`, `failed` or `cancelled`. Show `status_text` and `note` as written.
* Pass `expected_revision` whenever you read before you write.
* After a call that starts something has failed without a clear answer, call `list_widgets` before you call it again.


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