Sanity MCP Server
An implementation of the Model Context Protocol (MCP) server for Sanity.io.
Overview
This server implements the MCP protocol using stdio transport, making it suitable for direct integration with LLM assistants that support the MCP protocol. The server provides tools for interacting with Sanity's content management system.
Technical Details
- Built with TypeScript for type safety and better developer experience
- Uses Vitest for testing, with better ES Modules support
- Implements controllers for various Sanity.io features:
actions.ts
: Document publishing and unpublishing operations
embeddings.ts
: Embeddings and semantic search
groq.ts
: GROQ queries and real-time updates
mutate.ts
: Document mutations and modifications
releases.ts
: Content release management
schema.ts
: Schema type information
tools.ts
: Tool definitions for MCP
Available Tools
The server provides the following tools:
Installation
npm install
Building and Running
This project is built with TypeScript. To compile the TypeScript files to JavaScript:
npm run build
Important : Before running the server, make sure to set up your environment variables as described in the Environment Variables section below. The server requires Sanity API credentials to function properly.
Development Mode
Start the development server with automatic recompilation and restart on changes:
npm run dev
This uses tsc -w
to watch TypeScript files and recompile them when they change, plus node --watch
to restart the server when the compiled JavaScript changes.
Production Mode
For production or regular usage:
npm run build
npm start
Usage
Using as a direct command line tool
npm start
Or after building:
node dist/index.js
Integration with AI assistants
The server can be integrated with AI assistants that support the MCP protocol. It uses stdio transport (standard input/output) to communicate.
To see an example of how to integrate with the MCP client, check out the usage-example.ts
file.
Claude AI Configuration Example
For Anthropic's Claude AI, you can configure it to use this MCP server by adding the following to your Claude configuration:
{
"tools": [
{
"name": "sanity-mcp",
"type": "mcp",
"path": "/path/to/sanity-mcp-server/dist/index.js",
"env": {
"SANITY_TOKEN": "your_sanity_api_token",
"SANITY_PROJECT_ID": "your_sanity_project_id",
"SANITY_DATASET": "your_sanity_dataset",
"SANITY_API_VERSION": "2025-03-15"
}
}
]
}
Environment Variables
To configure the server, you need to set up environment variables:
Copy the .env.sample
file to create your own .env
file:
cp .env.sample .env
Edit the .env
file and fill in your Sanity credentials:
SANITY_TOKEN=your_sanity_api_token
SANITY_PROJECT_ID=your_sanity_project_id
SANITY_DATASET=your_sanity_dataset
SANITY_API_VERSION=2024-05-23 # Must be 2024-05-23 or later to support releases
PORT=3000 # Server port
You can get these values from your Sanity project settings:
* `SANITY_TOKEN`: Create an API token in the Sanity management console with appropriate permissions
* `SANITY_PROJECT_ID`: Your Sanity project ID (found in project settings)
* `SANITY_DATASET`: The dataset name you want to work with (typically "production")
Development
Project Structure
The project is organized as follows:
src/
: Source code
controllers/
: Controller modules for different Sanity features
types/
: TypeScript type definitions
utils/
: Utility functions
config/
: Configuration files
config/
: Configuration files for development tools
.eslintrc.json
: ESLint configuration
.eslintignore
: Files to ignore in ESLint
tsconfig.test.json
: TypeScript configuration for tests
scripts/
: Development and build scripts
test/
: Test files
unit/
: Unit tests
integration/
: Integration tests
schemas/
: Sanity schema files (not tracked in version control)
License
MIT