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

# Use Upsolve in Your Own Agent

> Give your own AI agent or MCP server your Upsolve workspace as a sub-agent: it asks the workspace's analytics agent questions as each of your users, with the embed tokens you already use.

If you're building your own AI agent, you can give it your Upsolve workspace as a tool. Your agent passes the data questions to the workspace's analytics agent, and gets back the answer, the chart data and the SQL behind it. Each call runs as one of your users, with the same embed token your [workspace embed](https://docs.upsolve.ai/embedding.md) already uses, so it sees only that user's data.

| | Embed the workspace | Embed in your agent (this page) |
| - | - | - |
| **What users get** | Upsolve's chat, favorites and canvases in your app | Your own agent, which asks Upsolve for answers |
| **How** | An `<iframe>` | Your workspace's MCP endpoint, called from your backend |
| **Sign-in** | Your backend gets an embed token for each user | The same embed token, sent as a bearer token |
| **Whose data** | Each user's own | Each user's own |

Your agent can only reach the end-user tools: ask the workspace's agent questions and work with that user's own conversations, favorites and canvases. It can't reach any tools for building or changing a workspace.

## Before you start

1. **A workspace with a production version.** The endpoint only answers from the version promoted to production. See [Environments](https://docs.upsolve.ai/ai-agent-builder/environments.md).
2. **Embed tokens for your users.** Your backend gets them from [`POST /v1/api/projects/embed-token`](https://docs.upsolve.ai/api-reference/endpoint/create-embed-token), the same way it does for the [workspace embed](https://docs.upsolve.ai/embedding.md).

## Connect

Each workspace has its own MCP endpoint, a standard [Model Context Protocol](https://modelcontextprotocol.io) server over Streamable HTTP. Copy its URL from **Workspace settings → MCP Branding**:

| | |
| - | - |
| **URL** | `https://mcp.upsolve.ai/w/<WORKSPACE_ID>` |
| **Auth** | `Authorization: Bearer <embed token>` |

The workspace is in the URL, so no tool asks your agent for an organization, project or workspace ID: the endpoint fills them in from the URL and the token.

Any MCP client that can send its own `Authorization` header can connect. There's no OAuth sign-in: the embed token is the sign-in. The token must be for a user of the workspace's project, or the endpoint refuses it.

### Example: Pydantic AI

This uses [Pydantic AI](https://ai.pydantic.dev) 2.x. Each agent run gets that user's embed token through `deps`, so one agent serves all your users:

```python theme={null}
from dataclasses import dataclass

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset

WORKSPACE_MCP_URL = "https://mcp.upsolve.ai/w/<your workspace id>"


@dataclass
class Deps:
    upsolve_token: str  # this user's embed token, from POST /v1/api/projects/embed-token


ALLOWED = {
    "workspaces_chat_data",
    "workspaces_query",
    "workspaces_me_threads_list",
    "workspaces_me_threads_get",
}

upsolve = MCPToolset(
    WORKSPACE_MCP_URL,
    auth=lambda ctx: ctx.deps.upsolve_token,  # sent as "Authorization: Bearer <token>"
).filtered(lambda ctx, tool: tool.name in ALLOWED)

agent = Agent(
    "<your model>",
    deps_type=Deps,
    toolsets=[upsolve],
    instructions=(
        "For any question about the user's data, call workspaces_chat_data with "
        'messages=[{"role": "user", "content": "<the question>"}]. '
        "For a follow-up question, pass the thread_id the previous answer returned."
    ),
)

result = await agent.run(
    "How many orders did we get last month?",
    deps=Deps(upsolve_token=embed_token_for_this_user),
)
```

The filter keeps your agent's tool list short. Without it, your agent sees every end-user tool, which is fine too.

## Your brand, not Upsolve's

Set your name, icon and loading animation in [MCP Branding](https://docs.upsolve.ai/ai-agent-builder/deploy-agents/mcp-branding.md). Everything your agent and your users see then uses them instead of Upsolve's: the server's name when a client connects, the tool descriptions and instructions your agent's model reads, error messages, and the chart widget in Claude and ChatGPT. Without branding, the endpoint calls itself **Analytics**.

When the agent builds a canvas for one of your users, the link it gives them opens your app, at the canvas link you set there. Your page then opens the canvas in your embed: see [Open a canvas from a link](https://docs.upsolve.ai/embedding.md#open-a-canvas-from-a-link).

## Which tools to use

| Tool | Use it for |
| - | - |
| `workspaces_chat_data` | **Any data question.** It asks the workspace's analytics agent, using all the context, skills and tests you set up, and returns its answer. Pass the returned `thread_id` on follow-ups and the agent remembers the conversation. |
| `workspaces_query` | A quick number, with no chart. Faster than a full agent turn. |
| `workspaces_me_threads_list`, `workspaces_me_threads_get` | Pick up this user's earlier conversations. |
| `workspaces_me_favorites_*`, `workspaces_me_canvases_*` | Optional: save charts and build canvases in this user's account. They show up in your [workspace embed](https://docs.upsolve.ai/embedding.md) too. |

Use `workspaces_chat_data`, not `workspaces_chat`. They run the same turn, but `workspaces_chat` is built for clients like Claude that draw charts in the conversation. `workspaces_chat_data` returns plain content your agent can read.

A `workspaces_chat_data` result has:

* **An access note** that says whether row-level security narrowed the answer.
* **The answer**, in markdown.
* **The charts**: each chart's config, its rows and the SQL that produced them.
* **The `thread_id`**, for follow-ups.

## Several workspaces

Each workspace has its own URL, so an agent that works with several connects to each one, or uses Upsolve's end-user server, `https://mcp.upsolve.ai/user`, instead. That server takes the same embed tokens, but every tool needs the organization, project and workspace IDs, and its `me_list`, `me_projects_list` and `me_workspaces_list` tools let your agent find them. It isn't branded.

## Tokens

* **One token per user.** Each call runs as the user the token was made for, under their [data governance](https://docs.upsolve.ai/ai-agent-builder/data-governance.md) rules. Never share one user's token with another.
* **Tokens expire.** You choose how long a token lasts when you create it (`5m` to `7d`). When it has expired, a tool fails with an error that says the embed token has expired, and you need a new token for the next run.
* **Keep it in your backend.** Pass the token to your MCP client, as in the example, never to the model in its prompt.
* **Use embed tokens.** Use tokens from `POST /v1/api/projects/embed-token`. The endpoint refuses Upsolve API keys and legacy tenant tokens.

## Troubleshooting

> [accordion] Connecting fails: “This endpoint takes an embed token”
>
> The bearer isn't an embed token. Send a token from
> `POST /v1/api/projects/embed-token`, not an Upsolve API key.

> [accordion] Connecting fails: “This embed token cannot open this workspace”
>
> The token was made for another project, or for a user who belongs to
> another workspace. Check the workspace ID in the URL, and the project (and
> `workspaceId`, if you send one) you create the token for.

> [accordion] Your MCP client tries to sign in with OAuth
>
> The request reached the server without a token. Check that your client
> sends `Authorization: Bearer <embed token>` on every request, as a header,
> and not through its OAuth settings.

> [accordion] A tool says the embed token has expired
>
> The token has expired or isn't valid. Get a new one from
> `POST /v1/api/projects/embed-token` and connect with it.

> [accordion] The agent says the workspace has no published version
>
> The endpoint only answers from the production version. Save a version of
> the workspace and promote it.

> [accordion] Answers show data the user shouldn't see
>
> The answer is narrowed by the properties you sent when you created the token.
> Check the access note in the result, and the token's properties against
> your [data governance](https://docs.upsolve.ai/ai-agent-builder/data-governance.md) rules.

## Next steps

> [card] [MCP Branding](https://docs.upsolve.ai/ai-agent-builder/deploy-agents/mcp-branding.md)
>
> Your name, icon, loading animation and canvas links.

> [card] [Embed Upsolve in your product](https://docs.upsolve.ai/embedding.md)
>
> Get embed tokens for your users.


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