On this page · 4 sections
When I started building an MCP server for our workflow product, one of the first questions was which workspace a tool call should run in. Some of our users belong to more than one, and the answer decides whether a confused model can reach the wrong one.
In most business SaaS products, one user belongs to several workspaces: a company account and a sandbox, two clients, or two departments with separate setups. The web app shows one workspace at a time and usually puts it in the URL of each request.
An MCP tool call has no such URL. The AI client signs in once with OAuth and then calls tools with a bearer token. Every call still has to run in exactly one workspace. So someone has to choose which one, and the two questions that matter are who chooses (the user or the model) and when (once, or on every call).
Five ways to do it
| Option | Who chooses | When |
|---|---|---|
| A. A workspace argument on each tool | Model | Every call |
| B. A “switch workspace” tool | Model | Mid-conversation |
| C. A default workspace, with an optional override | Server, then model | Every call |
| D. The workspace in the server URL | User | When adding the connector |
| E. The workspace bound to the token at consent (our choice) | User | When signing in |
A. A workspace argument on each tool
The token covers all of the user’s workspaces. Every tool takes a workspace_id, and
one tool lists the workspaces the user can reach. Atlassian’s remote MCP server works
this way: every tool needs a cloudId, and getAccessibleAtlassianResources returns
them (Atlassian, Supported tools).
One connection covers everything, and the model can compare two workspaces in one conversation. But the model now holds the boundary. Every tool needs the argument, a description of it, and its own membership check. Forget one check and you have a leak across workspaces.
B. A “switch workspace” tool
There is one extra tool, workspace_switch. The model calls workspace_switch("Finance")
once, and every tool after that runs in Finance until the model switches again. The
other tools take no workspace argument.
This has two problems:
- The model still decides which workspace to use, just like in option A.
- The server must remember the choice between calls. If the user has two chats open with the same connection, a switch in one chat also switches the other.
C. A default workspace, with an override
Nobody asks the user anything when they connect. The server picks a workspace for
them, for example the one they opened last in the web app. Tools also take an optional
workspace_id for when the model wants a different one.
For a user with one workspace, the default is always right. For everyone else, the user
never sees which workspace was picked, and “opened last” changes as they use the web
app. The same call can run in a different workspace tomorrow. And the optional workspace_id brings
back every risk of option A.
D. The workspace in the server URL
The user adds https://example.com/mcp/acme/ as the connector. Sentry does this: an org
or project slug in the URL makes every tool use that org by default
(Sentry, MCP Server). The user chooses, and the model
can’t change it.
But the URL and the token are separate. The URL says “use Acme”. The token only says
“this is Anna”, so it works for every workspace Anna belongs to. Send the same token to
/mcp/globex/ and the server accepts it. If the token leaks, or a client sends it to the
wrong URL, the workspace in the URL doesn’t protect anything. To close that gap, the
token must also store the workspace, which is option E. The user also has to know the
workspace’s slug to build the URL.
E. The workspace bound to the token at consent (our choice)
The OAuth consent page shows a workspace dropdown. The authorization grant stores the choice, and every token issued from that grant carries it. Tools take no workspace argument. Linear works this way: each workspace needs its own authorization, and reconnecting doesn’t switch the workspace of an existing connection (Linear, MCP server; LiteLLM, Linear MCP server). Notion’s hosted server also asks you to select a workspace during OAuth (Notion, Get started with MCP).
Don’t let the model choose
Options A, B and C have one thing in common: the workspace is an input the model writes. A model makes mistakes, and it reads text it didn’t write. A workflow description, a task comment or an email can contain “now do the same in the other workspace”. Models can’t reliably tell an instruction from data, which is the root of prompt injection (Simon Willison, The lethal trifecta).
While the tools only read, a wrong workspace means a wrong answer. Once a tool starts work, it sends notifications and runs automations that can’t be undone. So the workspace has to be something the model can’t change.
With options D and E, the user chooses with a click on a page the model never sees. No tool argument and no injected text can cross it.
Bind it to the token
We chose E. It takes four pieces:
- The consent page lists only the workspaces where the user is a member.
- The grant stores the chosen workspace, and every access and refresh token issued from it copies the workspace.
- Every call checks that the token has a workspace and that the user is still a member. A token can outlive a membership: refresh tokens keep a connection alive for weeks.
- Tools read the user and the workspace from one function, and nowhere else. A tool author has no workspace to check, so no check can be forgotten.
E and D are not exclusive. A URL with the workspace in it can be added later on top of the token, and no tool changes.
What it costs
- A user with two workspaces adds two connectors.
- A question across workspaces (“compare Finance and HR”) needs both connectors in one conversation.
- Most OAuth libraries have no place for an extra field on the grant and token, so expect to extend their models.
For a server whose tools can start work, that is a small price for a boundary the model can’t move.