Sanity MCP server
Enable AI assistants 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.
Installation
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:
- An MCP-compatible client, such as Claude Code, Cursor, VS Code, Lovable, or v0.
- A Sanity account.
Quick install via Sanity CLI
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.
Claude Code
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
Cursor
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:
- Open the Command Palette and run View: Open MCP Settings.
- Select + New MCP Server in the settings pane. This will open your
mcp.jsonfile. - Add the following configuration:
{
"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.
VS Code
- Open Visual Studio Code.
- In the Command Palette (
Cmd+Shift+P/Ctrl+Shift+P), run: MCP: Open User Configuration. - Update the
mcp.jsonfile 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.
OpenCode
You can add Sanity as a remote MCP server in your OpenCode configuration.
- Open your OpenCode config file.
- Add the following configuration to the
mcpsection:
{
"$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
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:
- In the v0 prompt input field, click Prompt Tools (bottom left).
- Select MCPs, then click Add New.
- Select Sanity.
- Click Authorize.
- Follow the prompt to authenticate with your Sanity account via OAuth.
Lovable
You can add Sanity as a "Personal connector" in Lovable.
- In Lovable, go to Settings > Connectors > Personal connectors.
- Click New MCP server.
- Enter
Sanityas the name andhttps://mcp.sanity.ioas the Server URL. - Click Add & authorize.
- Follow the prompt to authenticate with your Sanity account via OAuth.
For more details on managing connectors, see the Lovable MCP documentation.
Replit
You can add Sanity as a custom MCP server in Replit Agent.
- Go to the Integrations Page, then scroll down to MCP Servers for Replit Agent.
- Click Add MCP server.
- Enter
Sanityas the name andhttps://mcp.sanity.ioas the Server URL. - Click Test & Save.
- Follow the prompt to authenticate with your Sanity account via OAuth.
Once saved, you can ask Replit Agent to use Sanity by mentioning it in your chat. For more details, see the Replit MCP documentation.
Other clients
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"
]
}
}
}Authorization
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.
Run commands (or tools)
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:
- Help me migrate this project to Sanity.
- Run a GROQ query for all articles written by Mark.
- Add localization to my article document type.
- Help me migrate existing content to a new schema shape.
- List all releases in this dataset.
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.
Available tools
The following is a list of available tools and their uses:
get_context
Get project-specific context for a Sanity project and dataset, including available schemas, releases, and embeddings.
get_schema
Get the full schema of the current Sanity workspace
list_workspace_schemas
Get a list of all available workspace schema names
deploy_schema
Directly deploy schema types to the cloud.
create_documents_from_json
Create one or more draft documents by directly providing JSON content. Creates drafts (drafts.* prefix) unless releaseId is specified for version creation.
create_documents_from_markdown
Create one or more draft documents from Markdown content. Creates drafts (drafts.* prefix) unless releaseId is specified for version creation.
create_version
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.
patch_document_from_json
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_document_from_markdown
Patch a specific field in a document using Markdown content
query_documents
Query documents from Sanity using GROQ query language
generate_image
Trigger async AI image generation for a document field.
transform_image
Trigger async AI transformation of an existing image.
get_document
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_documents
Publish one or more draft documents to make them live
unpublish_documents
Unpublish one or more published documents (moves them back to drafts)
version_replace_document
Replace the contents of a document version with contents from another document
discard_drafts
Discard one or more draft documents (deletes drafts while keeping published documents intact). Can also discard release versions if releaseId is provided.
version_unpublish_document
Mark a document to be unpublished when the release is run
list_organizations
Lists all organizations the user has access to in Sanity
list_projects
Lists all Sanity projects associated with your account
get_project_studios
Retrieves all studio applications linked to a specific Sanity project
create_project
Creates a new Sanity project and initializes it with a dataset and API tokens
add_cors_origin
Adds CORS origin(s) to allow client-side requests to a Sanity project
list_datasets
Lists all datasets in your Sanity project
create_dataset
Creates a new dataset with specified name and access settings
update_dataset
Modifies a dataset's name or access control settings
list_releases
List content releases in Sanity, optionally filtered by state (active, scheduled, etc)
create_release
Create a new content release in Sanity with an automatically generated ID
edit_release
Update metadata for an existing content release
schedule_release
Schedule a content release to be published at a specific time
publish_release
Publish a release immediately
archive_release
Archive a release that is no longer active
unarchive_release
Restore an archived release
unschedule_release
Remove a previously set schedule from a release
delete_release
Delete a release
list_embeddings_indices
List all available embeddings indices for a dataset
semantic_search
Perform a semantic search on an embeddings index
migration_guide
Retrieve guides for migrating schemas and content from other CMS platforms.
search_docs
Search Sanity docs
read_docs
Fetch a specific documentation article.
list_sanity_rules
List available best-practice development rules.
get_sanity_rules
Load specific best-practice development rules.
Troubleshooting
Authentication issues
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:
- VS Code: Run
Authentication: Remove Dynamic Authentication Providersfrom the Command Palette, select the Sanity provider, and restart the server. - Cursor: Run
Cursor: Clear All MCP Tokensfrom the Command Palette to reset your session.
Tool availability
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.
Support
Join us in the Sanity community to ask questions and discuss our MCP server with other developers in the #mcp-server channel.
Was this page helpful?