Build with AI

Sanity MCP server

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. Agents can 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:

Official Sanity connectors

Sanity ships official connectors for Claude and ChatGPT. These are the fastest way to connect: install from the directory, authenticate with your Sanity account, and the hosted MCP server and our official agent skills are configured and kept up to date for you.

The Sanity connector in the Claude directory connects Claude to your Sanity content across Claude on the web, desktop, mobile and Claude Code CLI.

The Sanity plugin for ChatGPT connects Sanity to ChatGPT on the web, desktop, mobile and Codex CLI.

Quick install via Sanity CLI

You can add the Sanity MCP server to all of your developer tools at once 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.

Unlike the connectors above, this installs only the MCP server. Bundled agent toolkit extras like skills aren't included.

Manual installation

The Sanity MCP server works with any MCP-compatible agent. The following are setup instructions for common MCP clients.

Claude

How you connect depends on where you use Claude.

Claude on the web and desktop

  • Open the Sanity connector listing, or go to Settings > Connectors in Claude and browse the directory for Sanity.
  • Click Connect and follow the prompt to authenticate with your Sanity account via OAuth.

Claude Code CLI

If you do not use the Claude Desktop app, install the Sanity plugin, which bundles the MCP server with agent skills and slash commands for working with Sanity:

If you'd rather register just the MCP server without the plugin, add it manually with the Claude Code CLI. The next time you run Claude Code, authenticate with OAuth when prompted.

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.

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:

  • Fetch the deployed schema for a workspace. Resolves the best available source automatically — MCP-managed first, then Studio-deployed, then a legacy `system.schema` document.

  • List the deployed schemas for a project and dataset.

  • Directly deploy schema types to the cloud.

  • Deploy a managed Sanity Studio bound to an MCP-managed schema. Creates a hosted Studio whose URL follows the current environment — `sanity.studio` on production, `studio.sanity.work` on staging — and returns the concrete `studioUrl` in the response.

    Requires an existing MCP-managed schema at the same `(projectId, dataset, workspaceName)` address — call `deploy_schema` first if none exists. Re-run after subsequent `deploy_schema` calls so the deployed Studio picks up the latest schema.

  • Create one or more draft documents by directly providing structured 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.

  • Update or edit one or more existing documents by applying precise modifications using @sanity/client patch() operations. Patches for each document are applied as a single transaction (all succeed or all fail). Edits are saved to the draft or release version; published content is never modified directly.

  • 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)

  • Discard one or more draft documents (deletes drafts while keeping published documents intact)

  • Discard one or more document versions from a release

  • 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

  • Returns information about the currently authenticated Sanity user. Useful for verifying authentication and troubleshooting access issues.

  • 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

  • Create a new release for grouping content changes. Releases are containers that hold versioned documents for coordinated publishing.

  • List releases in a dataset. By default returns active and scheduled releases. Use the state filter to find published or archived releases.

  • List all available embeddings indices for a dataset

  • Perform a semantic search on an embeddings index

  • Search Sanity docs

  • Fetch a specific documentation article.

  • List available best-practice development rules.

  • Load specific best-practice development rules.

  • Submit feedback about Sanity when you encounter issues while working with a Sanity codebase or project.
    Use this when:
    - A Sanity MCP tool returned an unexpected error or confusing result
    - You needed a Sanity capability that doesn't exist or is hard to use
    - Sanity docs, MCP tool descriptions, or examples were unclear or incorrect
    - Common Sanity surfaces such as @sanity/client, the HTTP API, schemas, Studio, or deployment were confusing or blocked progress
    - You had to use a workaround for something in Sanity that should be simpler

    Provide a specific, detailed message about what you were trying to do,
    what happened, and what you expected instead.

AI credit usage

Most MCP tools are standard API calls and don't consume AI credits. The following tools invoke Sanity's AI inference endpoints and consume AI credits:

  • generate_image
  • transform_image
  • create_version – only when the instruction parameter is provided

You can disable these tools in your MCP client if you want to avoid credit usage.

Learn more about pricing and quotas in How AI credits work.

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:

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 Providers from the Command Palette, select the Sanity provider, and restart the server.
  • Cursor: Run Cursor: Clear All MCP Tokens from 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?