> **Building with AI coding agents?** Install the authstack plugin with one command. This equips your agent with accurate Scalekit implementation patterns.
>
> **Recommended** (the `-y` flags skip prompts, so the command runs without an interactive terminal):
> ```bash
> npx -y @scalekit-inc/cli setup -y
> ```
>
> Global:
> ```bash
> npm install -g @scalekit-inc/cli
> scalekit setup -y
> ```
>
> Supports Claude Code, Cursor, GitHub Copilot, Codex + skills for other Agent Skills-compatible agents in `~/.agents/skills`.
> Skills: integrate-agentkit, implement-saaskit, add-mcp-oauth, implement-sso, implement-scim.
> [Full setup guide](https://docs.scalekit.com/dev-kit/build-with-ai/)

---

# How Virtual MCP servers work

A Virtual MCP server exposes the tools you choose, for one user at a time, to any MCP client. How servers, session tokens and tool calls fit together.
A **Virtual MCP server** is a URL that exposes tools you choose, from one or more connections, to any MCP client. You create one server per agent role, such as a support assistant, and all your users share it. Before each run, you mint a **session token** for one user. The agent connects to the server URL with that token and can call only the tools you chose, as that user.

Use a Virtual MCP server when your agent already speaks MCP. If you build the agent loop yourself, you can call tools from your code instead: see [Use built-in tools](/agentkit/tools/scalekit-optimized-tools/).

Every AgentKit connection also has its own MCP server, with all of that connection's tools and nothing to create. [Use a connection's MCP server](/agentkit/mcp/connection-mcp-servers/) compares the two. Session tokens work the same way on both.

## Why use one

- **The agent sees only the tools it needs.** A Gmail connection has dozens of tools. A summarizer needs one. The server exposes only the tools you list, so the agent can't call the rest.
- **Smaller prompts.** Every tool on an MCP server goes into the model's context. Fewer tools means fewer tokens on every call.
- **One definition, isolated users.** All users share the server's URL. Each run's session token is bound to one user and that user's connected accounts, so one user's run can't act with another user's credentials.
- **Read-only runs from the same server.** Mint a [read-only token](/agentkit/mcp/read-only-tokens/) and the agent gets only the tools that don't change anything, without a second server.

## How it works

| When | You | What you get |
| --- | --- | --- |
| Once per agent role | [Create a Virtual MCP server](/agentkit/mcp/configure-mcp-server/) with the connections and tools the agent needs | A server ID and a fixed `mcp_server_url` |
| Before each run | [Check the user's connected accounts](/agentkit/reference/virtual-mcp-servers/check-connected-accounts-for-a-server/) are `ACTIVE`, then [mint a session token](/agentkit/mcp/session-tokens/) | A bearer token for one user and one server |
| During the run | Connect any MCP client to the URL with `Authorization: Bearer <session token>` | The server's tools, called as that user |

```d2 title="Create a Virtual MCP server once per agent role, mint a session token for each user's run, and let the MCP client call tools through Scalekit as that user"
direction: right

App: "Your app"
Client: "MCP client\n(your agent)"

Scalekit: {
  label: "Scalekit"
  Server: "Virtual MCP server\n(the tools you chose)"
  Account: "The user's\nconnected account"
}

Apps: "The user's apps\n(Gmail, Slack, ...)"

App -> Scalekit.Server: "1. Create once per agent role"
App -> Scalekit.Server: "2. Mint a session token per run"
App -> Client: "3. Server URL + token"
Client -> Scalekit.Server: "4. tools/list, tools/call"
Scalekit.Server -> Scalekit.Account: "5. That user's credentials"
Scalekit.Account -> Apps: "6. API call"
```

In the API and SDKs, a Virtual MCP server is called an **MCP configuration**, for example `create_config` in Python and `createConfig` in Node.js. The [Virtual MCP servers API reference](/agentkit/reference/virtual-mcp-servers/) lists every operation.

## Session tokens

A session token authorizes one user on one server:

- It lasts one hour unless you set `expiry`, which must be between 60 seconds and 24 hours.
- It can't be refreshed or extended. Mint a new one instead. Minting a new token doesn't revoke earlier ones.
- It only works on the server it was minted for. Any other server URL returns `401`.
- It can be full or read-only. A [read-only token](/agentkit/mcp/read-only-tokens/) sees and calls only the server's read-only tools.
- Check the user's connected accounts before the run. A tool call fails until the account for its connection is `ACTIVE`.

[Mint session tokens](/agentkit/mcp/session-tokens/) covers when to mint for one-off, scheduled, concurrent and long-running agents.

## What the agent sees

`tools/list` returns the tools you chose for the server. Tools from a connection the user hasn't authorized don't work until they do. `tools/list` also includes a `connect_account` tool. When the user still needs to connect an app, the agent calls it to get an authorization link, and shows the link to the user.

A tool call returns the same output as [`execute_tool`](/agentkit/tools/scalekit-optimized-tools/#read-the-result): the app's response under `data`. If the app reports an error in a successful (`2xx`) response, that error is in `data`. If the app answers with an error status, the tool call returns an error result (`isError: true`) whose message starts with `tool execution failed`.

## Data flow

1. The MCP client sends a request to the server URL with the session token.
2. Scalekit checks the token against the server and the user, and finds the user's connected account for the tool's connection.
3. Scalekit calls the app's API with that account's credentials and returns the result to the client.

Your agent never receives the user's OAuth token or API key. Responses pass through to the MCP client and aren't stored. See [what Scalekit stores](/agentkit/security/#what-scalekit-stores).

## Next

  - [Create a Virtual MCP server](/agentkit/mcp/configure-mcp-server/): Choose the tools and get the server URL.
  - [Mint session tokens](/agentkit/mcp/session-tokens/): Authorize a user's run and connect an MCP client.
  - [Use a connection's MCP server](/agentkit/mcp/connection-mcp-servers/): Every tool of one connection, with no server to create.


---

## More Scalekit documentation

| Resource | What it contains | When to use it |
|----------|-----------------|----------------|
| [/llms.txt](/llms.txt) | Structured index with routing hints per product area | Start here — find which documentation set covers your topic before loading full content |
| [/llms-full.txt](/llms-full.txt) | Complete documentation for all Scalekit products in one file | Use when you need exhaustive context across multiple products or when the topic spans several areas |
| [sitemap-0.xml](https://docs.scalekit.com/sitemap-0.xml) | Full URL list of every documentation page | Use to discover specific page URLs you can fetch for targeted, page-level answers |
