Developer guides

Best practices for AI-powered Sanity development

Set up the Sanity Agent Toolkit and MCP server to help AI assistants generate high-quality Sanity code that follows established best practices.

Because Sanity is an unabashedly all-code tool, you can use AI to rapidly configure a new Sanity Studio or integrate Sanity Client into your application faster than low-code alternatives requiring hundreds of in-browser clicks.

AI tools can dramatically accelerate Sanity development, but without proper guidance, they often produce generic code that fails to leverage Sanity's full capabilities. This guide teaches you how to instruct AI to generate Sanity code that follows established best practices while maintaining the speed advantages of AI assistance.

While most models understand all the APIs Sanity makes available, they are unlikely to follow opinionated best practices, which we have published over the years in guides and courses on Sanity Learn.

This guide will help you:

  • Set up AI tools to generate high-quality Sanity code.
  • Avoid common pitfalls of AI-generated configurations.
  • Implement best practices from Sanity Learn into your AI workflow.
  • Create better experiences for your content teams.

Sanity Agent Toolkit

The Sanity Agent Toolkit is a collection of resources to help AI agents build better with Sanity. It includes:

  • 20+ context rules covering schema design, GROQ, Visual Editing, SEO, localization, migrations, and framework integrations.
  • Claude Code plugin with slash commands and interactive skills for common workflows.
  • Knowledge router (AGENTS.md) that directs AI to the right guidance based on task keywords.

Configure the MCP server

The recommended approach is to connect your editor(s) to the Sanity MCP server, which gives AI agents direct access to your Sanity projects and always up-to-date best practice rules.

This detects and configures the MCP server for Cursor, Claude Code, and VS Code automatically. See the MCP server documentation for manual configuration options and troubleshooting.

For editors without MCP support, or if you prefer local rules, see the manual installation instructions in the Agent Toolkit repository.

Leveraging documentation content

The Sanity documentation has several ways you can use AI to get the job done:

  • For quick, specific reference: Use the Copy article button on all articles that puts the markdown version of the content on your clipboard. You can also add .md at the end of any article URL to get the markdown version.
  • For comprehensive context: You can point LLMs to /docs/llms.txt and /docs/llms-full.txt to access all the links and the full corpus as markdown formatted content.
  • For interactive queries: Use the MCP server's search_docs and read_docs tools.
  • For CLI-based work: You can even tell LLMs to use sanity docs search and sanity docs read to find docs articles.

Leveraging Sanity Learn content

All course and lesson material on Sanity Learn is also available in the LLM-friendly llms.txt standard. You can read how we made this on our blog.

There are two different sizes you can import into your IDE:

  • /llms.txt is an abbreviated index of all the content with links.
  • /llms-full.txt is the complete content (sometimes optimized to fit within the context window limits).

Cursor

  • Within Cursor chat, type "@Docs," select "Add new doc" and then paste in https://www.sanity.io/learn/llms.txt (or the filename of your choice above).
  • You can also add https://www.sanity.io/docs/ to the Cursor Settings → Features → Docs configuration.

Was this page helpful?