Connect an AI assistant
Before you begin
- Role
- Viewer or higher.
- You need
- An MCP client, such as Claude, Claude Code or Codex
MockHub has an MCP server, so an AI assistant can list your projects, create and edit mocks, read the requests your mocks received and turn them into new mocks. This page connects one in about five minutes.
| Setting | Value |
|---|---|
| Server address | https://api.mockhub.io/_mcp, or a toolset URL |
| Connection type | Streamable HTTP (called “HTTP” in Claude Code) |
| Sign-in | Through the browser, or a MockHub token sent as Authorization: Bearer <token> |
| Reach | One workspace, chosen when you sign in or create the token |
Settings → AI assistants in MockHub builds the URL and shows the steps for your assistant.
Choose how it signs in
Section titled “Choose how it signs in”| Assistant | Signs in | URL to use |
|---|---|---|
| Claude (claude.ai, Claude Desktop) | Through the browser | https://api.mockhub.io/_mcp/all |
| Claude Code | Through the browser or with a token | https://api.mockhub.io/_mcp/all |
| Codex | Through the browser or with a token | https://api.mockhub.io/_mcp/all |
| Cursor and other MCP clients | With a token | https://api.mockhub.io/_mcp |
| CI, scripts, a shared machine | With a machine token | The one the job needs |
Supported assistants lists how each signs in and the URL to give it.
Signing in needs no token: MockHub asks you which workspace the assistant works in and with which role, and the assistant renews its access on its own. A token suits an assistant that cannot sign in, a shared machine and CI.
Choose the URL
Section titled “Choose the URL”The URL chooses which toolsets, groups of tools, the assistant sees:
https://api.mockhub.io/_mcplists the default toolsets: who the assistant is, its projects and these docs, then mocks, request logs, scenarios and the data store.https://api.mockhub.io/_mcp/alllists every tool, contract checks, chaos, webhooks, configuration documents and CI environments among them.https://api.mockhub.io/_mcp/default+contractslists the default toolsets and one more; join names with+.
Claude, Claude Code and Codex load a tool’s definition only when they need it, so /_mcp/all costs them nothing. Cursor and many other clients load every definition up front, where fewer tools keep the assistant fast: start them on /_mcp and add the toolsets you use. A toolset decides what the assistant sees, never what it may do: its role decides that.
Sign in through the browser
Section titled “Sign in through the browser”Claude
Section titled “Claude”For claude.ai and Claude Desktop, which share their connectors:
- In Claude, open Settings → Connectors.
- Select Add custom connector, name it
MockHub, and enterhttps://api.mockhub.io/_mcp/all. - Select Connect. MockHub opens; sign in if it asks.
- Approve the connection.
Claude reads the tool list when it connects. After changing the URL, remove the connector and add it again.
Claude Code
Section titled “Claude Code”-
Add MockHub once, in a terminal:
Terminal window claude mcp add --transport http --scope user mockhub https://api.mockhub.io/_mcp/all--scope usermakes MockHub available in every folder;--scope localadds it to the current folder only. -
In Claude Code, type
/mcp, choose mockhub and select Authenticate. MockHub opens in your browser; sign in if it asks.
The Codex CLI, IDE extension and desktop app share one configuration.
-
Add MockHub once, in a terminal:
Terminal window codex mcp add mockhub --url https://api.mockhub.io/_mcp/all -
MockHub opens in your browser; sign in if it asks. If it does not open, run
codex mcp login mockhub.
Approve the connection
Section titled “Approve the connection”MockHub shows who is asking before you allow anything:
- Who is asking: the assistant’s name. Verified means it is confirmed by the website shown beside it, which publishes the assistant’s details. Unverified means the assistant chose the name itself and nothing confirms it.
- Returns to: where your browser goes after you decide. Claude Code, Claude Desktop and Codex show An app on this computer: allow it only if you started connecting from an app on this computer just now. For an unverified assistant, MockHub shows this as a warning.
- Tools: the toolsets the assistant asked for, such as All tools, with the connection URL beneath.
Then choose:
- The Workspace the assistant works in. It sees only that workspace.
- Its Role: Viewer for an assistant that only looks, Editor to let it create and edit mocks, Admin to let it manage project settings too. It can never be above your own role in that workspace.
- Allow access, or Deny to send the assistant away with nothing.
You can disconnect it at any time under Connected AI assistants in Settings → Profile.
The assistant keeps working without asking you again. A connection that has not been used for 30 days, or that is a year old, asks you to sign in again. A request you do not decide within 10 minutes expires; start again from the assistant.
Connect with a token
Section titled “Connect with a token”1. Create a token
Section titled “1. Create a token”Select the workspace the assistant should work in, then create a personal token under Settings → Tokens, as in Create a personal token. Give it a Name you will recognise later, such as Codex - work laptop, and the Role the assistant needs: Viewer to read your projects, mocks and request logs, Editor to let it create and edit mocks. Copy the token, which starts with mh_sk_; the dialog also shows the commands below with it.
A personal token acts as you, with the lower of your role in the workspace and the token’s role. For an assistant that keeps working when people leave, or one limited to a single project, an Admin can create a machine token instead. Leave Can create, list and delete ephemeral environments off; the MCP server does not use it. See Roles, personal tokens and machine tokens.
2. Store the token in an environment variable
Section titled “2. Store the token in an environment variable”Keep the token in an environment variable, never in a configuration file, so it never ends up in a repository or a screenshot. These steps call it MOCKHUB_MCP_TOKEN.
On macOS or Linux, add this line to your shell profile (~/.zshrc or ~/.bashrc) and open a new terminal:
export MOCKHUB_MCP_TOKEN="mh_sk_paste-your-token-here"On Windows, run this once and open a new terminal:
setx MOCKHUB_MCP_TOKEN "mh_sk_paste-your-token-here"Your assistant reads the variable when it starts, so restart it after setting or changing the token. Never paste the token into a chat with the assistant: it does not need to see it.
3. Add MockHub to your assistant
Section titled “3. Add MockHub to your assistant”Codex with a token
Section titled “Codex with a token”Run this once:
codex mcp add mockhub --url https://api.mockhub.io/_mcp/all --bearer-token-env-var MOCKHUB_MCP_TOKENOr add the server to ~/.codex/config.toml yourself:
[mcp_servers.mockhub]url = "https://api.mockhub.io/_mcp/all"bearer_token_env_var = "MOCKHUB_MCP_TOKEN"With a token variable, Codex connects with the token and does not sign in through the browser.
An app started from the Dock, the Start menu or a launcher may not see variables from your shell profile. If MockHub shows as unauthorized there but works in a terminal, start the app from a terminal where the variable is set.
Claude Code with a token
Section titled “Claude Code with a token”claude mcp add --transport http --scope user mockhub https://api.mockhub.io/_mcp/all \ --header 'Authorization: Bearer ${MOCKHUB_MCP_TOKEN}'Keep the single quotes: they store the text ${MOCKHUB_MCP_TOKEN}, and Claude Code fills in the value each time it starts.
To give everyone working in a repository the same setup, commit a .mcp.json file at its root. It contains no secret, because each person sets their own variable:
{ "mcpServers": { "mockhub": { "type": "http", "url": "https://api.mockhub.io/_mcp/all", "headers": { "Authorization": "Bearer ${MOCKHUB_MCP_TOKEN}" } } }}Claude Code asks each person to approve a server from .mcp.json the first time they use it.
Other clients
Section titled “Other clients”Any MCP client that lets you set an HTTP header works: choose Streamable HTTP, enter https://api.mockhub.io/_mcp, and add the header Authorization: Bearer <your token>. For Cursor, add this to ~/.cursor/mcp.json:
{ "mcpServers": { "mockhub": { "url": "https://api.mockhub.io/_mcp", "headers": { "Authorization": "Bearer ${env:MOCKHUB_MCP_TOKEN}" } } }}Several workspaces
Section titled “Several workspaces”One connection reaches one workspace. Connect MockHub once per workspace, under different names. With sign-in, add the server again and pick the other workspace when MockHub asks:
claude mcp add --transport http --scope user mockhub-acme https://api.mockhub.io/_mcp/allclaude mcp add --transport http --scope user mockhub-personal https://api.mockhub.io/_mcp/allWith tokens, create one in each workspace and give each its own variable:
codex mcp add mockhub-acme --url https://api.mockhub.io/_mcp/all --bearer-token-env-var MOCKHUB_ACME_TOKENcodex mcp add mockhub-personal --url https://api.mockhub.io/_mcp/all --bearer-token-env-var MOCKHUB_PERSONAL_TOKENName the workspace in what you ask (“in mockhub-acme, list the projects”).
Check the connection
Section titled “Check the connection”In Claude Code, type /mcp and look for mockhub marked as connected. In Codex, run codex mcp list or type /mcp. In Claude, the connector shows under Settings → Connectors. Then ask:
Which MockHub workspace am I connected to?
The assistant answers with the workspace and the role it acts with, and the token’s name or the assistant it signed in as.
Result: the assistant works in the workspace you chose, with the role you gave it. An assistant you signed in is listed under Settings → Profile → Connected AI assistants; a token, under Settings → Tokens.
If it does not connect
Section titled “If it does not connect”| What you see | What to do |
|---|---|
| This connection cannot continue in MockHub | The request expired, was already decided, or names an address the assistant did not register. Nothing was shared; start connecting again from the assistant. |
A signed-in assistant asks to sign in again, or shows a 401 |
It was disconnected, you left the workspace, or it was unused for 30 days. Sign in again. A connection is tied to its URL: after changing the URL, sign in again. |
mockhub shows as failed with a token, or a 401 error |
Run echo $MOCKHUB_MCP_TOKEN in the same terminal; it should start with mh_. Check the token has not expired or been revoked under Settings → Tokens, then restart the assistant. |
| mockhub is not listed at all | Run claude mcp list or codex mcp list, and add the server again with --scope user. |
404 naming the toolsets |
A name in the URL is not a toolset; see mcp-toolset-unknown. |
403 mentioning Origin or Host |
Use an address on https://api.mockhub.io/_mcp, from an assistant rather than a web page. |
429 |
The assistant made too many requests in a short time; see MCP tools. Wait a minute and ask for smaller batches. |
Limits
Section titled “Limits”- One connection reaches one workspace; connect again for another.
- Sign-in reaches the MCP server only. A signed-in assistant cannot call the REST API, and the CLI uses a token.
- The tool list follows the URL a signed-in assistant connected with. To add toolsets, connect again with the new URL.