Migrate from the Context Studio plugin to the new Context app
Move an agent from the Context Studio plugin to the Context app: create an endpoint and an organization API token, swap the URL, and update Insights.
Sanity Context now runs at the organization level: MCP endpoints are created in the Context app instead of a sanity.agentContext document in your dataset, and they support knowledge bases. The Context Studio plugin was removed in @sanity/context 3.0.0. To keep editing legacy Context documents in Studio, stay on @sanity/context@^2. Otherwise, remove the plugin from your Studio config. Your existing MCP URLs keep working but receive no further updates. Your knowledge bases and Insights conversation history are already in the Context app; endpoint configurations are the one thing you recreate.
This guide explains how to move an agent from a dataset-addressed MCP URL to an endpoint in the Context app.
Prerequisites:
- A Sanity organization with access to the Context app
- An Administrator or Developer role in the organization
- To attach a dataset as a source: the Administrator or Developer role (or a custom role that can create datasets) on that dataset's project, plus unrestricted read access to the dataset
Create an MCP endpoint
- Open the Context app and select New MCP endpoint.
- Name the endpoint and attach the sources your agent needs: Knowledge Bases, or the dataset your old configuration served. Attaching a dataset requires the Administrator or Developer role (or a custom role that can create datasets) on its project, plus unrestricted read access to the dataset; attaching it is what authorizes the endpoint to serve that dataset's content.
- Save. The endpoint's URL appears on its detail page. This is a new organization-addressed URL, not your old dataset-addressed one.
Existing MCP configurations were not migrated. Every endpoint must be created anew in the Context app. The old URL keeps serving until you point your agent at the new one.
Create an organization API token
Project tokens don't work on Context MCP endpoints. You need an organization API token with Context access, and one token covers every MCP endpoint in your organization.
- In Manage, select API › Tokens in your organization's sidebar.
- Select Add API token, name it, and under Organization permissions check Context.
- Choose Viewer if the token only reads over MCP. If the same token records Insights or manages Knowledge Bases, choose Editor.
- Store the token where your agent reads its secrets.
A token without Context access is rejected when the agent connects, with an error naming the missing grant.
Update your agent
Replace the MCP URL and token in your agent's configuration with the endpoint URL and the new token. This is the cutover: the old URL keeps serving until you switch, and restoring it rolls you back.
Update the Insights integration
If your agent records conversations to Insights, update the integration in the same deploy. The old integration writes to your dataset through an API that is no longer served, and fails silently.
Conversations are now recorded with sanityInsightsIntegration from @sanity/context/ai-sdk. To group conversations by endpoint in Insights, pass the endpoint name in metadata.mcpEndpoints. Use the same <name> as at the end of the endpoint URL:
import {streamText} from 'ai'
import {createMCPClient} from '@ai-sdk/mcp'
import {createClient} from '@sanity/client'
import {sanityInsightsIntegration} from '@sanity/context/ai-sdk'
const MCP_URL =
'https://api.sanity.io/v2026-11-03/context/organizations/<organizationId>/mcp/<name>'
const mcp = await createMCPClient({
transport: {
type: 'http',
url: MCP_URL,
// Needs read access; keep server-side
headers: {Authorization: `Bearer ${process.env.SANITY_ORGANIZATION_TOKEN}`},
},
})
const client = createClient({
apiVersion: '2026-08-25',
token: process.env.SANITY_ORGANIZATION_TOKEN,
context: {organizationId: '<organizationId>'},
useCdn: false,
useProjectHostname: false,
})
const result = streamText({
model,
messages,
tools: await mcp.tools(), // The agent's toolset, straight from the MCP
// On AI SDK v6, use `experimental_telemetry: {isEnabled: true, integrations: [...]}` instead
telemetry: {
integrations: [
sanityInsightsIntegration({
client,
threadId, // Your chat's thread id, unique within the org
// The well-known mcpEndpoints key tags the conversation with an MCP endpoint name
metadata: {mcpEndpoints: '<name>'},
}),
],
},
})If your agent doesn't use the AI SDK, save conversations directly with client.context.request on the PUT /organizations/{organizationId}/conversations/{threadId} route (@sanity/client 8.15 or later). Your existing conversation history is already in the Context app; new conversations continue the same Insights view.
Clean up
After the cutover, remove the sanity.agentContext document and the Context Studio plugin from your Studio config. Nothing reads them anymore.
Next steps
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?