# Sanity MCP

> Sanity MCP gives your AI agent total control over your Content Lake. Execute powerful queries against structured data, manage document records, and handle media assets without ever leaving your chat window. Stop context switching between your CMS interface and an API client; your agent now acts as a native power-user for all Sanity content.

## Overview
- **Category:** developer-tools
- **Price:** Free
- **Tags:** groq-queries, structured-content, document-management, schema-modeling, content-lake, api-driven

## Description

This MCP connects any compatible AI client directly to your entire Sanity Content Lake. You can manage every aspect of your structured data—from creating brand new records to running deep queries across thousands of documents.

Want to find all posts written by a specific author who mention 'AI'? Your agent handles that with one command, executing complex graph-relational object queries (GROQ) that pull exactly the content you need. Need to update 50 product descriptions simultaneously? You can patch multiple fields on existing documents or even run raw mutations for tricky transactions.

It’s more than just reading data; your agent becomes a full CMS power-user, capable of listing every schema type in your project and managing all uploaded media assets. If you're looking for the best way to connect structured content sources to AI workflows, Vinkius hosts this MCP, giving you one connection point to manage complex document structures.

This means developers can prototype migrations instantly, editors can perform bulk updates without leaving their chat, and product managers get instant reports on published versus draft content.

## Tools

### list_typed_documents
Lists all available document types within your Sanity project.

### count_entity_nodes
Counts the total number of documents belonging to a specific type.

### list_unique_schema_types
Retrieves a full list of every unique document structure defined in your dataset.

### create_cms_document
Builds and saves a brand new content document by specifying its type and attributes.

### get_document_details
Pulls all the specific data fields for one single document using its unique ID.

### list_media_assets
Displays a list of every image and file asset that has been uploaded to your project.

### patch_cms_document
Updates specific fields on an existing document without affecting any other data points.

### run_groq_query
Executes powerful, complex graph-relational object queries to fetch precise content subsets.

### run_raw_mutation
Runs advanced, raw mutations for highly complex, multi-document data transactions.

### wipe_cms_document
Permanently deletes a document from the CMS; this action is irreversible.

## Prompt Examples

**Prompt:** 
```
List all unique schema types in my dataset.
```

**Response:** 
```
I checked your schema types. Your dataset contains the following 5 types: `post`, `author`, `category`, `product`, and `siteSettings`. Would you like to know how many documents exist for a specific type?
```

**Prompt:** 
```
Write a GROQ query to find the 3 most recently updated authors.
```

**Response:** 
```
I executed the GROQ query `*[_type == 'author'] | order(_updatedAt desc)[0...3]`. The most recently updated authors are: 1. Sarah Chen, 2. Marcus Rivera, 3. Alex Nguyen. Should I retrieve their full biographical details?
```

**Prompt:** 
```
Update the post with ID 'drafts.1234' and set its published state to true.
```

**Response:** 
```
I've successfully patched document 'drafts.1234'. The field `isPublished` is now set to `true`. The change is immediately live in your Content Lake.
```

## Capabilities

### Querying structured data
Fetch specific pieces of content by running powerful queries against your document schema.

### Creating and updating records
Build new documents or modify existing fields on any type of record in the CMS.

### Managing media files
Browse, list, and handle all images and file assets uploaded to your project.

### Auditing content structure
List every unique document type available in the dataset or count how many records exist for a given type.

### Running raw mutations
Execute complex, multi-document transactions that require advanced API calls.

## Use Cases

### Finding all outdated content
A Product Manager needs to find every product listing that hasn't been updated in six months. They prompt their agent, and it executes a run_groq_query targeting the 'product' type and filtering by the last update date. The result is a clean list of IDs ready for review.

### Mass publishing content
A Content Editor has 20 articles that are finished but still marked as drafts. They ask the agent to patch_cms_document for all 20 records, setting the 'isPublished' field to true in one go, bypassing manual UI clicks.

### Auditing content structure changes
A Developer needs to know if a new schema type was added since yesterday. They ask the agent to list_unique_schema_types and compare that output against their local records, instantly verifying the CMS structure.

### Creating related articles automatically
A user wants to create a new case study document based on an old one. They ask the agent to get_document_details for the original post's data and then use those fields to run a create_cms_document, saving the structured copy.

## Benefits

- You eliminate context switching. Instead of jumping between the CMS UI and an API playground to test queries, you just ask your agent what you need in plain English. The agent handles the complex GROQ execution for you.
- Content updates get faster. Use tools like patch_cms_document to update specific fields on existing records—like changing a status or updating a date—without having to recreate the entire document payload every time.
- Schema discovery is instant. Never wonder what content types exist again; just ask your agent to list unique schema types, and it gives you an immediate inventory of everything in your Content Lake.
- Media management simplifies. You can browse all images and file assets using list_media_assets right from the chat, treating media files like data points rather than just visual clutter.
- Data integrity is maintained. For complex tasks that involve multiple documents (like creating a new post and simultaneously updating its author's profile), you use run_raw_mutation to keep everything consistent.

## How It Works

The bottom line is that once connected, your agent treats your CMS like a built-in database, letting you talk to its data instead of writing API calls.

1. Subscribe to this MCP and input your Sanity Project ID, Dataset name, and API Token.
2. Your AI agent automatically connects the credentials and makes all document types available for querying and modification.
3. Tell your AI client what you need—for example, 'List all unique content types' or 'Update post 123 to say it is published.' — and watch the actions happen.

## Frequently Asked Questions

**How does Sanity MCP handle complex queries?**
It handles them by allowing your agent to execute GROQ (Graph-Relational Object Queries). This means you can ask questions that require linking data across multiple different content types, not just simple field searches.

**Can Sanity MCP delete content permanently?**
Yes. It provides the wipe_cms_document tool to permanently remove records from your CMS. Be warned: this action is irreversible and should only be used when you are absolutely sure.

**Does the Sanity MCP help with media assets?**
Absolutely. You can list all image and file assets using the list_media_assets tool, letting your agent manage or reference these files directly within your content workflows.

**Is this better than just using the Sanity API directly?**
It's much easier. You don't need to write boilerplate API calls; you just talk naturally to your agent, and it translates those instructions into the correct tool commands for you.

**What if I want to create a new document with specific attributes?**
You use the create_cms_document tool. You specify the desired schema type and provide all the necessary data points in a simple, structured format that the agent handles.