Sanity Context

Configure a Context MCP endpoint

Create a Context MCP endpoint in the Context app, scope what it serves, and connect an agent to it.

An MCP endpoint defines what an agent can access and the instructions it receives. Configuration lives in the Context app rather than in your agent code, so it's visible to your team, editable by non-developers, and shared across environments. This guide creates one and connects an agent to it.

Prefer to use AI?

Prerequisites

An organization API token with Context Viewer permissions, created in Manage under API > Tokens at the organization level, not the project level, and, if the endpoint has a dataset source, a Studio (v5.1.0 or later) deployed for that project and dataset with npx sanity@latest deploy. See Sanity Context for the full list.

Create the MCP endpoint

In the Context app in the Dashboard, create an MCP endpoint and fill in its fields. Choose the name carefully: the endpoint URL uses it, and you can't change it after you create the endpoint. For what each field does, see MCP endpoint configuration fields. The Context app shows the endpoint URL once you save.

Scope what the agent can read

A GROQ filter limits which documents the agent's queries select from a dataset source. It accepts a filter expression only: the part inside the [ ... ] of a full query, which evaluates to true or false for one document at a time.

Three things that don't belong in a filter:

  • Projection syntax such as { name, price }. It is accepted, but matches no documents. Move projections to the agent's queries instead.
  • Ordering or slicing such as order(...) or [0...10].
  • A full query, meaning anything that starts with *[...]. Filters nested inside an expression are fine.

An invalid filter is rejected with a 422 and the parser error in the response body.

A filter that matches nothing looks like a broken connection

Connect an agent to the endpoint

Use the endpoint URL from the Context app to connect an MCP client. This example uses the Vercel AI SDK:

import {createMCPClient} from '@ai-sdk/mcp'

const mcpClient = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://api.sanity.io/v2026-11-03/context/organizations/YOUR_ORGANIZATION_ID/mcp/YOUR_ENDPOINT_NAME',
    headers: {
      Authorization: `Bearer ${process.env.SANITY_ORGANIZATION_TOKEN}`,
    },
  },
})

Replace YOUR_ORGANIZATION_ID with your organization id and YOUR_ENDPOINT_NAME with the endpoint's name, which is chosen when you create the MCP endpoint and cannot be changed afterwards. SANITY_ORGANIZATION_TOKEN is an organization API token with Context Viewer permissions. If you don't have one, create it in Manage. Keep it server-side, since it carries organization-level permissions.

Verify the connection by listing the available tools:

const tools = await mcpClient.tools()
console.log(tools)

For an endpoint with a dataset source, the list includes initial_context and groq_query. If a tool is missing, check the endpoint's sources: each tool is served only for the source type it belongs to. For the full tool list per source type, see Context MCP tools.

For framework-specific setup, see the connect guides for Claude Agent SDK, Google ADK, LangChain, Mastra, OpenAI Agents SDK, Vercel AI SDK, and Vercel eve.

Next steps

Was this page helpful?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme