Build with AI

Quick start: connect an agent to Sanity Context

Install the Sanity Context skill, run the guided setup, and verify your agent can read your content.

Sanity Context gives an agent read-only, schema-aware access to your content through a hosted MCP server. This quick start uses the setup skill, which inspects your project and generates the schema, configuration, and code you need. By the end you'll have an MCP endpoint and an agent that can answer questions about your content.

Prefer a manual setup?

Prerequisites

  • Context enabled for your organization. An organization admin can enable it from the Apps page of your organization in Manage.
  • A Sanity project with content.
  • A deployed schema for the project and dataset the endpoint reads, from a Studio on v5.1.0 or later. Run sanity schema deploy, or open your hosted Studio once if you deploy with sanity deploy. An MCP endpoint with a dataset source will not serve without one.
  • An organization API token with Context Viewer permissions, created in Manage under API > Tokens at the organization level, not the project level, and kept server-side. Context Editor also works, but Viewer is the least privilege that will do.
  • A model and API key for the agent you're building.
  • A coding agent such as Claude Code or Cursor, plus Node.js 20.19+ or 22.12+ to run npx.

The setup spans Studio, schema, and application code, so run it with a capable coding model rather than a small one.

Step 1: Install the Sanity Context skills

The --all flag installs three skills: create-agent-with-sanity-context for setup, plus dial-your-context for tuning the Instructions field and shape-your-agent for crafting a system prompt. From your project directory:

Step 2: Run the setup skill

The create-agent-with-sanity-context skill asks about your goal, inspects your project, and walks you through configuration, building an example agent, and optionally adding a frontend UI. Prompt your coding agent:

Step 3: Verify the connection

The example uses the Vercel AI SDK's MCP client. Pin its major. @ai-sdk/mcp shares an internal provider dependency with ai, so their majors have to match. If your agent code uses ai@6, a bare install resolves a newer @ai-sdk/mcp and produces type errors on model and tools that name neither package:

Set SANITY_CONTEXT_MCP_URL to your endpoint URL and SANITY_ORGANIZATION_TOKEN to your organization API token, then list the tools the endpoint serves. You should see initial_context and groq_query among them.

Then ask the agent a question whose answer you already know, and check that it answers from your content rather than guessing.

Empty schema or no results?

Next steps

Was this page helpful?