The Sanity MCP Server enables AI-powered content operations for Sanity by implementing the Model Context Protocol. This server connects your Sanity projects with AI tools like Claude, Cursor, and VS Code, allowing AI models to understand your content structure and perform operations through natural language instructions.
Before using the MCP server, you need to:
Deploy your Sanity Studio with schema manifest
# Option A: If you have the CLI installed globally
npm install -g sanity
cd /path/to/studio
sanity schema deploy
# Option B: Update your Studio
cd /path/to/studio
npm update sanity
npx sanity schema deploy
For CI environments without Sanity login:
SANITY_AUTH_TOKEN=<token> sanity schema deploy
Gather your API credentials
Add the following configuration to your application's MCP settings:
{
"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"
}
}
}
}
The configuration location depends on your application (Claude Desktop, Cursor, VS Code, etc.).
Activate your preferred Node.js version:
# Using nvm
nvm use 20 # or your preferred version
# Using mise
mise use node@20
# Using fnm
fnm use 20
Create the necessary symlinks:
On macOS/Linux:
sudo ln -sf "$(which node)" /usr/local/bin/node && sudo ln -sf "$(which npx)" /usr/local/bin/npx
On Windows (PowerShell as Administrator):
New-Item -ItemType SymbolicLink -Path "C:\Program Files\nodejs\node.exe" -Target (Get-Command node).Source -Force
New-Item -ItemType SymbolicLink -Path "C:\Program Files\nodejs\npx.cmd" -Target (Get-Command npx).Source -Force
Verify the setup:
# Should show your chosen Node version
/usr/local/bin/node --version # macOS/Linux
"C:\Program Files\nodejs\node.exe" --version # Windows
Variable | Description | Required |
---|---|---|
SANITY_API_TOKEN |
Your Sanity API token | ✅ |
SANITY_PROJECT_ID |
Your Sanity project ID | ✅ |
SANITY_DATASET |
The dataset to use | ✅ |
MCP_USER_ROLE |
Determines tool access level (developer or editor) | ✅ |
SANITY_API_HOST |
API host (defaults to https://api.sanity.io) | ❌ |
MAX_TOOL_TOKEN_OUTPUT |
Maximum token output for tool responses (defaults to 50000) | ❌ |
Generate a Robot Token:
Required Permissions:
viewer
roleeditor
or developer
roleadministrator
role may be neededTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "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"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"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"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"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"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect