Building an MCP Server for Sanity CMS​​​​‌‍​‍​‍‌‍‌​‍‌‍‍‌‌‍‌‌‍‍‌‌‍‍​‍​‍​‍‍​‍​‍‌​‌‍​‌‌‍‍‌‍‍‌‌‌​‌‍‌​‍‍‌‍‍‌‌‍​‍​‍​‍​​‍​‍‌‍‍​‌​‍‌‍‌‌‌‍‌‍​‍​‍​‍‍​‍​‍‌‍‍​‌‌​‌‌​‌​​​‍‍​‍​‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‍​​​​​​​​​‍‌‍‍‌‌‍‍‌‌​‌‍‌‌‌‍‍‌‌​​‍‌‍‌‌‌‍‌​‌‍‍‌‌‌​​‍‌‍‌‌‍‌‍‌​‌‍‌‌​‌‌​​‌​‍‌‍‌‌‌​‌‍‌‌‌‍‍‌‌​‌‍​‌‌‌​‌‍‍‌‌‍‌‍‍​‍‌‍‍‌‌‍‌​​‌‌‍‌‌‍​‌‌‌‌‍‌​‌‍​‌​‌‌​‌​​‌​‌‌‍‌‍​​‌‌​‌‍​‌‍‌‌‍‌​​‌‌‌‍‌‌‍‍‌‌‌​‌‍​‌‌‌‌‍‌​‍​​‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‍‌‍​‌‍‌‍‌​‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‌​‌‍‍‌‌‌​‌‍​‌‍‌‌​‌‍​‍‌‍​‌‌​‌‍‌‌‌‌‌‌‌​‍‌‍​​‌‌‍‍​‌‌​‌‌​‌​​​‍‌‌​​‌​​‌​‍‌‌​​‍‌​‌‍​‍‌‌​​‍‌​‌‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‌‌​​‌​​‌​​​​​​​​​‍‌‍‌‍‍‌‌‍‌​​‌‌‍‌‌‍​‌‌‌‌‍‌​‌‍​‌​‌‌​‌​​‌​‌‌‍‌‍​​‌‌​‌‍​‌‍‌‌‍‌​​‌‌‌‍‌‌‍‍‌‌‌​‌‍​‌‌‌‌‍‌​‍​​‍‌‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‍‌‍​‌‍‌‍‌​‍‌‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‌​‌‍‍‌‌‌​‌‍​‌‍‌‌​‍‌‍‌​​‌‍‌‌‌​‍‌​‌​​‌‍‌‌‌‍​‌‌​‌‍‍‌‌‌‍‌‍‌‌​‌‌​​‌‌‌‌‍​‍‌‍​‌‍‍‌‌​‌‍‍​‌‍‌‌‌‍‌​​‍​‍‌‌

Building an MCP Server for Sanity CMS​​​​‌‍​‍​‍‌‍‌​‍‌‍‍‌‌‍‌‌‍‍‌‌‍‍​‍​‍​‍‍​‍​‍‌​‌‍​‌‌‍‍‌‍‍‌‌‌​‌‍‌​‍‍‌‍‍‌‌‍​‍​‍​‍​​‍​‍‌‍‍​‌​‍‌‍‌‌‌‍‌‍​‍​‍​‍‍​‍​‍‌‍‍​‌‌​‌‌​‌​​​‍‍​‍​‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‍​​​​​​​​​‍‌‍‍‌‌‍‍‌‌​‌‍‌‌‌‍‍‌‌​​‍‌‍‌‌‌‍‌​‌‍‍‌‌‌​​‍‌‍‌‌‍‌‍‌​‌‍‌‌​‌‌​​‌​‍‌‍‌‌‌​‌‍‌‌‌‍‍‌‌​‌‍​‌‌‌​‌‍‍‌‌‍‌‍‍​‍‌‍‍‌‌‍‌​​‌‌‍‌‌‍​‌‌‌‌‍‌​‌‍​‌​‌‌​‌​​‌​‌‌‍‌‍​​‌‌​‌‍​‌‍‌‌‍‌​​‌‌‌‍‌‌‍‍‌‌‌​‌‍​‌‌‌‌‍‌​‍​​‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‍‌‍​‌‍‌‍‌​‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‌​‌‍‍‌‌‌​‌‍​‌‍‌‌​‌‍​‍‌‍​‌‌​‌‍‌‌‌‌‌‌‌​‍‌‍​​‌‌‍‍​‌‌​‌‌​‌​​​‍‌‌​​‌​​‌​‍‌‌​​‍‌​‌‍​‍‌‌​​‍‌​‌‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‌‌​​‌​​‌​​​​​​​​​‍‌‍‌‍‍‌‌‍‌​​‌‌‍‌‌‍​‌‌‌‌‍‌​‌‍​‌​‌‌​‌​​‌​‌‌‍‌‍​​‌‌​‌‍​‌‍‌‌‍‌​​‌‌‌‍‌‌‍‍‌‌‌​‌‍​‌‌‌‌‍‌​‍​​‍‌‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‍‌‍​‌‍‌‍‌​‍‌‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‌​‌‍‍‌‌‌​‌‍​‌‍‌‌​‍‌‍‌​​‌‍‌‌‌​‍‌​‌​​‌‍‌‌‌‍​‌‌​‌‍‍‌‌‌‍‌‍‌‌​‌‌​​‌‌‌‌‍​‍‌‍​‌‍‍‌‌​‌‍‍​‌‍‌‌‌‍‌​​‍​‍‌‌
Toms Veidemanis​​​​‌‍​‍​‍‌‍‌​‍‌‍‍‌‌‍‌‌‍‍‌‌‍‍​‍​‍​‍‍​‍​‍‌​‌‍​‌‌‍‍‌‍‍‌‌‌​‌‍‌​‍‍‌‍‍‌‌‍​‍​‍​‍​​‍​‍‌‍‍​‌​‍‌‍‌‌‌‍‌‍​‍​‍​‍‍​‍​‍‌‍‍​‌‌​‌‌​‌​​​‍‍​‍​‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‍​​​​​​​​​‍‌‍‍‌‌‍‍‌‌​‌‍‌‌‌‍‍‌‌​​‍‌‍‌‌‌‍‌​‌‍‍‌‌‌​​‍‌‍‌‌‍‌‍‌​‌‍‌‌​‌‌​​‌​‍‌‍‌‌‌​‌‍‌‌‌‍‍‌‌​‌‍​‌‌‌​‌‍‍‌‌‍‌‍‍​‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‌‍​‍‌‍​‌‌​‌‍‌‌‌‌‌‌‌​‍‌‍​​‌‌‍‍​‌‌​‌‌​‌​​​‍‌‌​​‌​​‌​‍‌‌​​‍‌​‌‍​‍‌‌​​‍‌​‌‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‌‌​​‌​​‌​​​​​​​​​‍‌‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‍‌‍‌​​‌‍‌‌‌​‍‌​‌​​‌‍‌‌‌‍​‌‌​‌‍‍‌‌‌‍‌‍‌‌​‌‌​​‌‌‌‌‍​‍‌‍​‌‍‍‌‌​‌‍‍​‌‍‌‌‌‍‌​​‍​‍‌‌·Jan 26, 2026

Building an MCP Server for Sanity CMS

I recently built a Model Context Protocol (MCP) server that enables AI assistants like Claude to directly manage content in Sanity CMS. Here's what I learned and how you can build one too.

What is MCP?

Model Context Protocol is Anthropic's open standard for connecting AI assistants to external tools and data sources. It allows Claude to interact with databases, APIs, and content management systems in a structured, safe way.

Why Build This?

Managing content through a CMS dashboard is fine for occasional updates, but when you're working with an AI assistant on content creation, the back-and-forth becomes tedious. With an MCP server, Claude can:

- Create and publish blog posts directly - Manage categories and tags - Upload images and media - Update existing content

The Architecture

The server is built with TypeScript and uses:

@modelcontextprotocol/sdk - The official MCP SDK

@sanity/client - Sanity's JavaScript client with write capabilities

Zod - For input validation and type safety

Key Features

Full CRUD Operations

Every content type has complete create, read, update, and delete operations. The tools are designed to be intuitive for AI assistants while maintaining data integrity.

Portable Text Conversion

One challenge was converting markdown content to Sanity's Portable Text format. The server includes a utility that transforms markdown headers, paragraphs, and blockquotes into proper Portable Text blocks.

Media Upload

The server supports uploading images both from base64 data and from URLs, making it easy to attach cover images to posts.

Toms Veidemanis​​​​‌‍​‍​‍‌‍‌​‍‌‍‍‌‌‍‌‌‍‍‌‌‍‍​‍​‍​‍‍​‍​‍‌​‌‍​‌‌‍‍‌‍‍‌‌‌​‌‍‌​‍‍‌‍‍‌‌‍​‍​‍​‍​​‍​‍‌‍‍​‌​‍‌‍‌‌‌‍‌‍​‍​‍​‍‍​‍​‍‌‍‍​‌‌​‌‌​‌​​​‍‍​‍​‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‍​​​​​​​​​‍‌‍‍‌‌‍‍‌‌​‌‍‌‌‌‍‍‌‌​​‍‌‍‌‌‌‍‌​‌‍‍‌‌‌​​‍‌‍‌‌‍‌‍‌​‌‍‌‌​‌‌​​‌​‍‌‍‌‌‌​‌‍‌‌‌‍‍‌‌​‌‍​‌‌‌​‌‍‍‌‌‍‌‍‍​‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‌‍​‍‌‍​‌‌​‌‍‌‌‌‌‌‌‌​‍‌‍​​‌‌‍‍​‌‌​‌‌​‌​​​‍‌‌​​‌​​‌​‍‌‌​​‍‌​‌‍​‍‌‌​​‍‌​‌‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‌‌​​‌​​‌​​​​​​​​​‍‌‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‍‌‍‌​​‌‍‌‌‌​‍‌​‌​​‌‍‌‌‌‍​‌‌​‌‍‍‌‌‌‍‌‍‌‌​‌‌​​‌‌‌‌‍​‍‌‍​‌‍‍‌‌​‌‍‍​‌‍‌‌‌‍‌​​‍​‍‌‌

Toms Veidemanis​​​​‌‍​‍​‍‌‍‌​‍‌‍‍‌‌‍‌‌‍‍‌‌‍‍​‍​‍​‍‍​‍​‍‌​‌‍​‌‌‍‍‌‍‍‌‌‌​‌‍‌​‍‍‌‍‍‌‌‍​‍​‍​‍​​‍​‍‌‍‍​‌​‍‌‍‌‌‌‍‌‍​‍​‍​‍‍​‍​‍‌‍‍​‌‌​‌‌​‌​​​‍‍​‍​‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‍​​​​​​​​​‍‌‍‍‌‌‍‍‌‌​‌‍‌‌‌‍‍‌‌​​‍‌‍‌‌‌‍‌​‌‍‍‌‌‌​​‍‌‍‌‌‍‌‍‌​‌‍‌‌​‌‌​​‌​‍‌‍‌‌‌​‌‍‌‌‌‍‍‌‌​‌‍​‌‌‌​‌‍‍‌‌‍‌‍‍​‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‌‍​‍‌‍​‌‌​‌‍‌‌‌‌‌‌‌​‍‌‍​​‌‌‍‍​‌‌​‌‌​‌​​​‍‌‌​​‌​​‌​‍‌‌​​‍‌​‌‍​‍‌‌​​‍‌​‌‍‌‍​‌‍‌‍​‌‍​‌‌‍​‌‍‍​‌‍‌​‌‌​​‍‌‌​​‌​​‌​​​​​​​​​‍‌‍‌‍‍‌‌‍‌​​‌‌‍​‍‌‍‌‌​‍​​‌‍​‌​‍​​​‍​​‌​‍‌‌‍​‍​​‍​‌‌​‌​‍‌​‌​​​‌‌‍‌‍​​‌​‍‌​‍​‌‍‌‌​‌‍‌‍​​‍‌​‌‍​‌​‌‌‌‍​‍​‌‌‌‍‌‌​‍‌‌‍​‍​‍‌​‍‌​‌‌‌‍‌​​‍‌‍‌‌​‌‍‌‌​​‌‍‌‌​‌‌‍​‌‌‌‌‌‌​‌‍‍​‌‍‌​‍​‍‌‍‌​​‌‍​‌‌‌​‌‍‍​​‌‌‍‍‌‍​‌‌‍‌‌‍‌‌​‍‌‍‌​​‌‍‌‌‌​‍‌​‌​​‌‍‌‌‌‍​‌‌​‌‍‍‌‌‌‍‌‍‌‌​‌‌​​‌‌‌‌‍​‍‌‍​‌‍‍‌‌​‌‍‍​‌‍‌‌‌‍‌​​‍​‍‌‌