Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To build an AI agent grounded in Sanity, connect an MCP-capable application to Sanity Context, choose the content access mode that fits your data, and begin with read-only retrieval. Sanity Context supplies scoped access to content; your application supplies the agent loop and user interface.

How does an AI agent connect to Sanity content?

Sanity stores content in its Content Lake as structured documents. Instead of asking an agent to interpret a page dump, an application can retrieve individual fields—such as a product name, description, or category—as data. Sanity describes those fields as individually addressable, queryable, and reusable across channels. The Content Lake supports GROQ and GraphQL queries. Sanity Content Lake documentation explains the underlying content model.

Sanity Context is a hosted Model Context Protocol (MCP) server. Sanity describes it as providing AI agents “structured, read-only access to your content.” It exposes a schema-aware view of content, but it does not generate the agent’s conversational behavior, run the agent loop, provide your application’s UI, or write to the dataset. Your MCP-compatible harness or application handles those jobs. Sanity Context documentation

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose GROQ or Knowledge Base mode

Pick the mode based on where the agent’s answers should come from and how current or structured that information needs to be.

Mode How it gets information Good fit
GROQ Queries the live dataset and can expose schema and documents allowed by the MCP configuration. Questions about structured records and fields, or content that should reflect the live dataset.
Knowledge Base Serves knowledge indexed ahead of time. Answers drawing on material assembled from datasets, websites, and files.

Sanity’s Context reference describes keyword search ranked with BM25, semantic search over dataset embeddings, and hybrid search with selectable boosting in GROQ mode. Keyword search matches exact tokens; it does not use fuzzy matching or stemming, so a misspelling can return no result. Treat that as a retrieval limitation when you design search prompts or evaluate a failed lookup. Sanity Context MCP reference

What do you need before setup?

For dataset-backed Context use, Sanity’s quick start lists an organization with Context enabled, a Sanity project containing content, and a deployed schema. Its documentation specifies Studio v5.1.0 or later for schema deployment. You also need an MCP-capable harness or application to make the connection and run the agent. Sanity Context quick start

Set up a read-only Context connection

Sanity’s documented quick-start route uses an AI coding agent and the create-agent-with-sanity-context skill to inspect a project and guide setup. The skill is a convenience, not a requirement: Sanity also documents manual configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Enable Sanity Context for your organization, and confirm the project has the content and deployed schema the agent should query.

  2. Follow the quick start’s guided setup or configure an MCP client manually. The quick-start example uses createMCPClient from @ai-sdk/mcp, a Sanity Context MCP URL, and an organization token.

  3. Keep the initial configuration read-only. Set the endpoint and authentication in your application’s MCP client, and restrict access to the content the agent needs.

  4. Ask the agent to retrieve a known document or answer a question whose answer is present in a specific document. Check the returned content against that document before building further behavior on it.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sanity also documents npx sanity@latest mcp configure for setting up its CLI MCP server and provides Agent Toolkit skills and plugins for AI coding workflows. This is a development-assistant setup route; it is distinct from configuring the runtime Sanity Context endpoint your application agent uses. Sanity AI setup documentation

Scope access and permissions deliberately

Read-only access reduces the impact of an incorrect instruction or retrieval. Configure the endpoint and credentials so the agent can see only the content appropriate for its task, then verify that the intended documents are in scope. Sanity’s Context reference describes access in terms of the MCP configuration; permissions should be treated as part of the integration design, not as a prompt-level safeguard.

How can an agent make changes to Sanity content?

Sanity Context is read-only. If the agent must create or edit documents, choose a separate write-capable route and configure its permissions independently of the read-only prototype.

Sanity MCP server

Sanity hosts its MCP server at https://mcp.sanity.io. Sanity says it follows Anthropic’s official MCP specification and supports MCP-compatible clients. Its documented authentication options are OAuth by default or token authentication; available operations follow the authenticated token’s role and permissions. The server’s tools include schema exploration, GROQ queries, project tasks, and content or document changes. Grant only the permissions needed for the agent’s job. Sanity MCP server documentation

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Content Agent API

For a custom content agent, Sanity also documents its Content Agent API and the content-agent npm package, a provider for the Vercel AI SDK. The API supports stateful multi-turn threads through .agent() and stateless calls through .prompt(). Read and write capabilities can be configured separately and scoped with filters. Sanity Content Agent API documentation

Sanity lists these prerequisites for the Content Agent API: a deployed schema, an Editor-level or higher project token, an organization ID, Node.js 18 or later, and a Sanity Studio v5.1.0 or later opened at least once after schema deployment. API calls consume AI credits; Sanity says read-only queries cost less than write operations, but the documentation does not provide a specific credit price.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot retrieval before adding features

If the agent cannot find a known document or returns no useful content, check the connection in this order:

  • Endpoint: Confirm the application is using the intended Context MCP URL and that the client is configured to connect to it.
  • Authentication: Check that the credential type matches the configuration and that the organization or token has the required access.
  • Schema: For dataset-backed use, verify that the schema is deployed; the documented Studio requirement is v5.1.0 or later.
  • Scope: Confirm the requested document and fields are included in the configured read scope.
  • Search terms: In GROQ mode, try the exact spelling of a keyword; keyword matching does not provide fuzzy matching or stemming.

Once a read-only query returns the expected document and you have checked its contents, you have a concrete basis for building the agent’s answer behavior. Add mutations only after selecting a write-capable route and establishing its permission boundary.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.