# Sanity MCP

> Sanity provides full control over your headless CMS content by letting any AI agent perform operations through natural conversation. This MCP lets you query documents using custom GROQ queries, create new drafts, update existing fields, and even manage entire datasets without ever opening the Sanity Studio interface. You can list all project members or browse media assets—it turns complex backend administration into simple chat commands.

## Overview
- **Category:** developer-tools
- **Price:** Free
- **Tags:** structured-content, groq, content-api, data-modeling, real-time-sync

## Description

Your AI agent now acts as a dedicated content operations assistant for your Sanity project. Instead of navigating multiple dashboards to find a document ID or remembering precise query syntax, you just tell your client what you need done.

It handles everything from drafting new blog posts and updating product details to running complex data checks across different datasets. Need to know which users have access? Or maybe you're staging content and need to create a clean dataset for development testing? Your agent manages it all, keeping track of your entire content lifecycle in one place.

Connecting this MCP through the Vinkius catalog gives any compatible AI client instant, conversational access to your entire content graph. You manage data with plain language commands; the system handles the complex API calls.

## Tools

### create_dataset
Creates an empty, isolated content collection for testing purposes (e.g., 'staging').

### create_document
Generates and saves a brand new document with specified type fields.

### delete_document
Permanently removes an existing content item from the database; this action cannot be undone.

### get_document
Retrieves all field data for a single, specific document using its unique ID.

### list_datasets
Displays all the isolated content environments currently configured in your project.

### list_documents
Lists every available document of a specific type within the current dataset, including metadata.

### list_image_assets
Retrieves metadata for all images and media files stored in your content library.

### list_users
Lists every user account that has access to the project, useful for security audits.

### query_documents
Runs highly customized GROQ queries across your content to find data based on complex logic (e.g., 'all posts published last month').

### search_documents
Performs a broader search of documents, optionally filtering by type and setting a maximum result count.

### update_document
Modifies specific fields (like title or status) on an existing document without affecting other content.

## Prompt Examples

**Prompt:** 
```
List all published blog posts in my Sanity project.
```

**Response:** 
```
I found 15 documents of type 'post'. The most recent include: 'Getting Started with Sanity' (published 2 days ago), 'GROQ Query Tips' (published last week), and 'Content Modeling Best Practices' (published 2 weeks ago).
```

**Prompt:** 
```
Create a new draft post titled 'API Integration Guide' with status 'draft'.
```

**Response:** 
```
Done! I've created a new document of type 'post' with title 'API Integration Guide' and status 'draft'. The document ID is drafts.abc123def456. It's ready for editing in Sanity Studio.
```

**Prompt:** 
```
Run a GROQ query to find all products with price greater than 100.
```

**Response:** 
```
Found 8 products with price > 100. The most expensive is 'Enterprise Plan' at $499/month, followed by 'Pro Plan' at $199/month. Results include product name, price and slug for each.
```

## Capabilities

### Run custom content queries
Ask the agent to search and retrieve documents by specific criteria using advanced GROQ query syntax.

### Create, update, and delete records
Add new documents or modify existing fields (like changing a status from draft to published) with single commands.

### Manage content collections
Browse all available document types within your project scope.

### Administer data environments
List existing datasets or create new ones, isolating content for different stages like staging or development.

### Handle media assets and users
Browse your image library and audit who has access to the project's backend tools.

## Use Cases

### Finding all articles needing a content review
A Content Editor needs to find every product post that was written last week but hasn't been assigned an image yet. They ask their agent to run a query, and the MCP executes `query_documents` using filters for 'product' type and date criteria, returning only the IDs of articles needing review.

### Setting up a clean environment for QA
A Developer is working on a new feature and needs to test content against production data. They first ask their agent to `list_datasets` to verify 'production' exists, then command it to `create_dataset` named 'qa-test', ensuring zero risk to live content.

### Mass updating product details
A Marketing Manager needs to change the status of 15 old blog posts from draft to published. Rather than opening 15 documents, they instruct their agent to `update_document` for a list of IDs and set the 'status' field to 'published'.

### Retrieving specific document details by ID
An Editor gets an email with only a content item ID. Instead of guessing where it lives, they ask their agent to `get_document` using the provided ID and instantly retrieve all associated fields for review.

## Benefits

- You eliminate the need to manually run complex queries. Instead of writing intricate GROQ code every time you need data, simply ask your agent to query documents using `query_documents` and get instant results.
- Content publishing becomes conversational. You can draft content or change a document's status from 'draft' to 'published' by asking the agent to run an `update_document` command, skipping clicks entirely.
- Data isolation is effortless. If you need to test changes without affecting live data, use the MCP to list and create dedicated datasets via `list_datasets` and `create_dataset`.
- Auditing access used to mean clicking through user roles. Now, you simply ask your agent to run `list_users`, getting a clean roster of who has access instantly.
- Media management is direct. Instead of navigating the asset library manually, you can list images and their metadata by running `list_image_assets` directly from your chat window.

## How It Works

The bottom line is that your AI client treats complex content management like a simple conversation with an expert assistant.

1. Subscribe to this MCP, then provide your Sanity Project ID, Dataset name, and API Token.
2. Connect your preferred AI client (like Cursor or Claude) to the Vinkius catalog. This gives your agent access credentials.
3. Tell your agent what you need—for example, 'List all drafts of product documents'—and it executes the necessary commands.

## Frequently Asked Questions

**How do I run custom searches with Sanity using the Sanity MCP?**
You use the `query_documents` tool. You simply ask your agent what data you need, and it translates that into a powerful GROQ query to pull exactly what you're looking for.

**Can I create content drafts with Sanity using this MCP?**
Yes, you use the `create_document` tool. You can specify the document type and fill in basic content fields (like a title) to generate a new draft ready for editing.

**Is it safe to delete documents using the Sanity MCP?**
The `delete_document` action is irreversible. Always confirm with your agent that you have the correct document ID and are sure you want to permanently remove the content before confirming.

**What if I need to test changes in a sandbox environment?**
You should use `list_datasets` first, then run `create_dataset` to make an isolated copy. This ensures any testing or mistakes won't affect your live production content.

**How do I check who has access to my Sanity project?**
Simply ask the agent to execute the `list_users` tool. It will retrieve a list of all registered team members and their current permissions within the project.