Sanity MCP
Sanity MCP Server connects Sanity content with AI tools for schema-aware content operations and semantic search. It enables natural language AI management of content releases, queries, and transformations.
How to Install and Use Sanity MCP
Sanity MCP is a tool that connects your Sanity content projects with AI-powered applications like Claude, Cursor, and Visual Studio Code. It helps manage and operate your content using natural language commands. Below, you will find simple, step-by-step instructions to get Sanity MCP up and running on your system with real code examples.
Using the Remote Sanity MCP Server (Recommended)
The easiest way to start using Sanity MCP is with their hosted server. This means you don’t have to set up anything on your own computer.
To connect your MCP client to the remote Sanity MCP server, add this configuration:
{
"mcpServers": {
"Sanity": {
"url": "https://mcp.sanity.io",
"type": "http"
}
}
}
This remote server offers several benefits:
- Streamable HTTP transport for better performance
- OAuth authentication, so you don’t have to manage tokens
- Always up-to-date tools and features
- No need to install Node.js or run any local setup
For more details and examples, visit mcp.sanity.io.
Preparing for Local Installation
If you prefer to run the Sanity MCP server on your own machine (self-hosting), some preparation is needed. Here's what to do before installing:
- Deploy Your Sanity Schema Manifest
The MCP server needs to understand your content structure. Go to your Sanity Studio folder and run:
cd /path/to/studio
npm update sanity
npx sanity schema deploy
If you are running this in a continuous integration (CI) environment without login, add an auth token like this:
SANITY_AUTH_TOKEN=<your-token> sanity schema deploy
Note: Use Sanity CLI version 3.88.1 or newer.
- Get Your API Credentials
You will need:
- Your Sanity Project ID
- The dataset name (like
production) - An API token with proper permissions (see below)
Adding Sanity MCP Server Configuration to Your Application
Once ready, add this configuration to your app’s MCP settings. It tells your app how to start the Sanity MCP server locally using Node.js.
{
"mcpServers": {
"sanity": {
"command": "npx",
"args": ["-y", "@sanity/mcp-server@latest"],
"env": {
"SANITY_PROJECT_ID": "your-project-id",
"SANITY_DATASET": "production",
"SANITY_API_TOKEN": "your-sanity-api-token",
"MCP_USER_ROLE": "developer"
}
}
}
}
Replace "your-project-id" and "your-sanity-api-token" with your actual Sanity project ID and API token.
The exact location where you put this configuration depends on your application; for example:
- Claude Desktop uses its config file,
- Cursor and Visual Studio Code use workspace or user settings,
- Custom apps follow their own integration docs.
Creating an API Token with the Right Permissions
Sanity MCP requires an API token that allows it to read and possibly write data. Here’s how to create one quickly:
Run this terminal command in your Sanity Studio folder:
npx sanity tokens add "MCP Server" --role <role>
Replace <role> with one of:
viewerfor read-only accesseditorordeveloperfor editing and mutation operationsadministratorif you need project-level control
Make sure to keep your token secure and never share it.
Node.js Setup for MCP Server
For the MCP server to run properly, it must access the Node.js and npx commands on your system. If you use a Node version manager like nvm, you may have to create system-wide links.
Example for macOS/Linux:
- Activate your desired Node version:
nvm use 20
- Create symlinks for system-wide access:
sudo ln -sf "$(which node)" /usr/local/bin/node && sudo ln -sf "$(which npx)" /usr/local/bin/npx
- Verify the setup:
/usr/local/bin/node --version
If you’re on Windows, follow the symbolic link instructions in PowerShell as administrator.
With these steps followed, you can start using Sanity MCP either with the remote server or your local setup. For live development, you can also run:
pnpm install
pnpm run dev
to build and test the server.
Remember to always secure your API tokens, and consider using a staging dataset to avoid accidental changes in production. This setup empowers you to interact with your Sanity content by leveraging AI in a simple and efficient way.