The Sanity MCP Server implements the Model Context Protocol to connect your Sanity projects with AI tools, enabling natural language interactions with your content. It allows AI models to understand your content structure and perform operations through conversational 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
Get 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 location for this configuration depends on your application:
Application | Configuration Location |
---|---|
Claude Desktop | Claude Desktop configuration file |
Cursor | Workspace or global settings |
VS Code | Workspace or user settings (depends on extension) |
Custom Apps | Refer to your app's MCP integration docs |
First, 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
Then, 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
The server uses the following environment variables:
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
role is sufficienteditor
or developer
role recommendedadministrator
role may be neededThe server supports two user roles:
Once you've set up the Sanity MCP server, you'll have access to various tools for different operations:
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.