Use a connection's MCP server
Every AgentKit connection has its own MCP server with all of the connection's tools. Find its URL, mint a session token for a user and connect any MCP client.
Every AgentKit connection has its own MCP server. It serves all of that connection’s tools, and there is nothing to create: once the connection exists, so does its server. Mint a session token for a user, and any MCP client can call the connection’s tools as that user.
Choose a connection MCP server or a Virtual MCP server
Section titled “Choose a connection MCP server or a Virtual MCP server”| Connection MCP server | Virtual MCP server | |
|---|---|---|
| Tools | Every tool of one connection | The tools you choose, from one or more connections |
| Setup | None | Create it once per agent role |
| URL | <environment URL>/mcp/v3/connections/<connection name> | The mcp_server_url returned when you create it |
| Session token | Minted for the connection | Minted for the server |
Use a connection MCP server when an agent works with one app and should see what that app offers. Use a Virtual MCP server when an agent needs a few tools from several apps, or you want to keep the tool list short. Both accept read-only tokens.
Before you start
Section titled “Before you start”-
An AgentKit connection, and its name, such as
gmail. The URL uses the name exactly as stored, including case. -
The user’s
identifier: your app’s ID for that user, the same value you passed when they authorized the connection. Choose an identifier explains why it shouldn’t be an email address. -
A client set up as in the Quickstart:
actionsin Python,scalekitin Node.js. For cURL, get an access token and keep it inTOKEN:Terminal window TOKEN=$(curl -sS "$SCALEKIT_ENVIRONMENT_URL/oauth/token" \-d grant_type=client_credentials \-d client_id="$SCALEKIT_CLIENT_ID" \-d client_secret="$SCALEKIT_CLIENT_SECRET" | jq -r .access_token)
-
Get the server URL
Section titled “Get the server URL”In the dashboard, go to AgentKit > Connections, open the connection, and copy MCP Server URL from the Configuration tab. It has this form:
https://<your environment URL>/mcp/v3/connections/gmailYou can also build it from your environment URL and the connection name. The path is case-sensitive, so use the name exactly as it appears in the dashboard.
-
Mint a session token
Section titled “Mint a session token”Mint a token for the user before each run. Set
expirya little above how long the run takes: between 60 seconds and 24 hours, one hour by default.from datetime import timedeltasession = actions.mcp.create_session_token(connection_name="gmail",identifier="user_123",expiry=timedelta(minutes=15),)session_token = session.tokenconst session = await scalekit.actions.mcp.createSessionToken({connectionName: 'gmail',identifier: 'user_123',expirySeconds: 900,});const sessionToken = session.token;Terminal window SESSION_TOKEN=$(curl -sS "$SCALEKIT_ENVIRONMENT_URL/api/v1/mcp/connections/gmail/tokens" \-H "Authorization: Bearer $TOKEN" \-H "Content-Type: application/json" \-d '{"identifier": "user_123", "expiry": "900s"}' |jq -r .token)The token works only on this connection’s server. To limit the agent to tools that don’t change anything, add
access_level="READ_ONLY"(Python) oraccessLevel: 'READ_ONLY'(Node.js): see Limit an agent to read-only tools. -
Connect the MCP client
Section titled “Connect the MCP client”Give your MCP client the server URL and the header
Authorization: Bearer <session token>. Most frameworks take them as the server’s URL and headers. Mint session tokens shows the MCP SDK clients in Python and Node.js, and Connect any MCP client has the HTTP contract for everything else.
Check it worked
Section titled “Check it worked”List the tools with the token:
curl -sS "$SCALEKIT_ENVIRONMENT_URL/mcp/v3/connections/gmail" \ -H "Authorization: Bearer $SESSION_TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | sed -n 's/^data: //p' | jq -r '.result.tools[].name'You see the connection’s tools, such as gmail_fetch_mails, and connect_account. If the user hasn’t authorized the connection yet, the agent calls connect_account to get an authorization link for them, as in Connect a user’s account from the agent.
Common problems
Section titled “Common problems”404 when minting the token
Section titled “404 when minting the token”No active connection has that name in this environment. Check the name in AgentKit > Connections, and that the connection is enabled.
400 when minting the token
Section titled “400 when minting the token”The identifier or expiry is invalid, the connection isn’t an AgentKit connection, or the user has no active account on the connection. In the last case, send the user an authorization link and mint again once the account is ACTIVE.
401 with invalid or expired bearer token
Section titled “401 with invalid or expired bearer token”The token expired, was minted for a different server, or the URL’s connection name differs from the stored name, for example in case. Copy the URL from the dashboard and mint a new token for this connection.
API reference
The endpoints this page's code calls, with every field and the SDK method for each: