Was this page helpful?
Enable AI agents to interact with your Sanity workspace through the Model Context Protocol (MCP).
The Sanity Model Context Protocol (MCP) server enables AI assistants like Claude Code and Cursor to interact directly with your Sanity projects.
With the MCP server, agents can go beyond code generation and perform advanced content management operations in your Sanity projects—execute GROQ queries, manage releases, and patch documents with full awareness of your schema, eliminating the need to manually supply context.
The Sanity MCP server is hosted on Sanity's own infrastructure on https://mcp.sanity.io. It follows Anthropic's official MCP specification and works with any MCP-compatible client. It supports authentication through both OAuth (default) and token-based authentication.
Prerequisites:
The easiest way to get started is using the Sanity CLI. It detects the most common AI-powered editors (Cursor, VS Code, Claude Code) and automatically configures the MCP server for you.
npx sanity@latest mcp configure
pnpm dlx sanity@latest mcp configure
yarn dlx sanity@latest mcp configure
bunx sanity@latest mcp configure
This command uses your logged-in CLI user for authentication, so you don't need to manually authenticate or manage API tokens.
Run the following command in your terminal to add the Sanity MCP server. The next time you run Claude Code, it will have access to the MCP and you can authenticate with OAuth.
claude mcp add Sanity -t http https://mcp.sanity.io --scope user
Use the link below to directly install the Sanity MCP server in Cursor. Once installed, you'll be prompted to authorize access.
You can confirm the server is running by opening the Command Palette (Cmd+Shift+P / Ctrl+Shift+P) and running View: Open MCP Settings.
Alternatively, you can manually update your configuration:
mcp.json file.{
"mcpServers": {
"Sanity": {
"type": "http",
"url": "https://mcp.sanity.io"
}
}
}Once you save the file, Cursor detects the new server and prompts you to authenticate via OAuth to complete the connection.
Cmd+Shift+P / Ctrl+Shift+P), run: MCP: Open User Configuration.mcp.json file with the following configuration and save the file:{
"servers": {
"Sanity": {
"type": "http",
"url": "https://mcp.sanity.io"
}
}
}Once you save the file, VS Code detects the new server and prompts you to authenticate via OAuth to complete the connection.
You can add Sanity as a remote MCP server in your OpenCode configuration.
mcp section:{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sanity": {
"type": "remote",
"url": "https://mcp.sanity.io",
"oauth": {}
}
}
}Save the file and authenticate with Sanity by running: opencode mcp auth sanity
Once authenticated, you can use Sanity tools in your prompts by mentioning sanity. For more details, see the OpenCode MCP documentation.
v0 is an AI agent from Vercel that helps anyone create real code and full-stack apps. Ship features, refine designs, update copy, and create live prototypes – all with a prompt. Here’s how you add the Sanity MCP:
You can add Sanity as a "Personal connector" in Lovable.
Sanity as the name and https://mcp.sanity.io as the Server URL.For more details on managing connectors, see the Lovable MCP documentation.
You can add Sanity as a custom MCP server in Replit Agent.
Sanity as the name and https://mcp.sanity.io as the Server URL.Once saved, you can ask Replit Agent to use Sanity by mentioning it in your chat. For more details, see the Replit MCP documentation.
If your client does not support remote MCP servers, you may be able to use a proxy such as mcp-remote.
{
"mcpServers": {
"Sanity": {
"command": "npx",
"args": [
"mcp-remote",
"https://mcp.sanity.io",
"--transport",
"http-only"
]
}
}
}The Sanity MCP server uses OAuth by default to perform operations on your behalf. You may instead provide an API token by setting the Authorization header in your MCP config. When configured with the header, the server will not use OAuth. Tool calls will use the API token in accordance with its role and scoped to its permissions.
{
"mcpServers": {
"Sanity": {
"url": "https://mcp.sanity.io",
"headers": {
"Authorization": "Bearer sk..."
}
}
}
}You can create API tokens from sanity.io/manage or with the sanity CLI's tokens command. You can also provide a personal token, which will share your role and permissions, as well as link you to any changes in the revision history.
Once configured and started, authenticate with your Sanity credentials if prompted. You can then use natural language to work with Sanity development tasks, such as:
mcp.sanity.io provides both editorial and development-focused tools for content operations, schema exploration, GROQ query execution, project management tasks such as creating and managing resources like datasets and API keys, and migration assistance. These tools allow your AI assistant to interact with your Sanity data directly.
The following is a list of available tools and their uses:
Get the full schema of the current Sanity workspace
Get a list of all available workspace schema names
Directly deploy schema types to the cloud.
Create one or more draft documents by directly providing JSON content. Creates drafts (drafts.* prefix) unless releaseId is specified for version creation.
Create one or more draft documents from Markdown content. Creates drafts (drafts.* prefix) unless releaseId is specified for version creation.
Create a version document (versions.{releaseId}.* prefix) for a specific release. Versions are separate from drafts and published documents, and are used for scheduled release workflows.
Apply precise modifications to document fields. When targeting a published document, this creates or updates a draft with the changes (published document remains unchanged). When targeting a draft or version, updates it in place.
Patch a specific field in a document using Markdown content
Query documents from Sanity using GROQ query language
Trigger async AI image generation for a document field.
Trigger async AI transformation of an existing image.
Fetch a single document by its exact ID. This is a direct ID lookup only - it does not search, filter, or query. Use when you have a specific document ID and need its full content.
Publish one or more draft documents to make them live
Unpublish one or more published documents (moves them back to drafts)
Replace the contents of a document version with contents from another document
Discard one or more draft documents (deletes drafts while keeping published documents intact). Can also discard release versions if releaseId is provided.
Mark a document to be unpublished when the release is run
Lists all organizations the user has access to in Sanity
Lists all Sanity projects associated with your account
Retrieves all studio applications linked to a specific Sanity project
Creates a new Sanity project and initializes it with a dataset and API tokens
Adds CORS origin(s) to allow client-side requests to a Sanity project
Lists all datasets in your Sanity project
Creates a new dataset with specified name and access settings
Modifies a dataset's name or access control settings
List content releases in Sanity, optionally filtered by state (active, scheduled, etc)
Create a new content release in Sanity with an automatically generated ID
Update metadata for an existing content release
Schedule a content release to be published at a specific time
Publish a release immediately
Archive a release that is no longer active
Restore an archived release
Remove a previously set schedule from a release
Delete a release
List all available embeddings indices for a dataset
Perform a semantic search on an embeddings index
Retrieve guides for migrating schemas and content from other CMS platforms.
Search Sanity docs
Fetch a specific documentation article.
List available best-practice development rules.
Load specific best-practice development rules.
If you encounter authentication errors (e.g., 401 Unauthorized), the solution depends on how you installed the server:
Installed via CLI (using token auth)
If you installed the MCP via the Sanity CLI, your authentication relies on a generated token that may have expired or been revoked. To fix this, simply run the configuration command again and re-select your code editor with space:
npx sanity@latest mcp configure
pnpm dlx sanity@latest mcp configure
yarn dlx sanity@latest mcp configure
bunx sanity@latest mcp configure
This will generate a fresh auth token and update your editor's configuration file automatically.
Manually configured (using OAuth)
If you configured the server manually, you are likely using OAuth. Sessions typically expire after 7 days. Your client should prompt you to re-authenticate, but if it gets stuck:
Authentication: Remove Dynamic Authentication Providers from the Command Palette, select the Sanity provider, and restart the server.Cursor: Clear All MCP Tokens from the Command Palette to reset your session.If specific tools (like query_documents) are missing or failing, verify that your account has the correct permissions for the project and dataset you are trying to access. The set of available tools may also vary as we release updates to the MCP server.
Join us in the Sanity community to ask questions and discuss our MCP server with other developers in the #mcp-server channel.
npx sanity@latest mcp configurepnpm dlx sanity@latest mcp configureyarn dlx sanity@latest mcp configurebunx sanity@latest mcp configurenpx sanity@latest mcp configurepnpm dlx sanity@latest mcp configureyarn dlx sanity@latest mcp configurebunx sanity@latest mcp configureclaude mcp add Sanity -t http https://mcp.sanity.io --scope user{
"mcpServers": {
"Sanity": {
"type": "http",
"url": "https://mcp.sanity.io"
}
}
}{
"servers": {
"Sanity": {
"type": "http",
"url": "https://mcp.sanity.io"
}
}
}{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sanity": {
"type": "remote",
"url": "https://mcp.sanity.io",
"oauth": {}
}
}
}{
"mcpServers": {
"Sanity": {
"command": "npx",
"args": [
"mcp-remote",
"https://mcp.sanity.io",
"--transport",
"http-only"
]
}
}
}{
"mcpServers": {
"Sanity": {
"url": "https://mcp.sanity.io",
"headers": {
"Authorization": "Bearer sk..."
}
}
}
}npx sanity@latest mcp configurepnpm dlx sanity@latest mcp configureyarn dlx sanity@latest mcp configurebunx sanity@latest mcp configurenpx sanity@latest mcp configurepnpm dlx sanity@latest mcp configureyarn dlx sanity@latest mcp configurebunx sanity@latest mcp configure