@sanity-labs/agent-context-inspector
v0.0.6
Published
A dev tool for inspecting and testing Sanity Agent Contexts. It runs a small server and web UI where you can chat with your agent, see tool calls and token usage, and tweak system prompts and runtime options.
Keywords
Readme
@sanity-labs/agent-context-inspector
A dev tool for inspecting and testing Sanity Agent Contexts. It runs a small server and web UI where you can chat with your agent, see tool calls and token usage, and tweak system prompts and runtime options.
Getting started
There are three ways to configure the inspector.
Option A: Browser UI (zero config)
Just run the dev server:
npx @sanity-labs/agent-context-inspector@latest devA setup form will appear in the browser where you enter your project ID, dataset, Sanity API token, and Anthropic API key. Settings are saved in your browser's local storage for subsequent visits.
Option B: CLI flags
Pass credentials directly on the command line:
npx @sanity-labs/agent-context-inspector@latest dev \
--project-id :projectId \
--dataset :dataset \
--slug my-agent \ # optional — targets a specific Agent Context document
--token sk-... \
--anthropic-api-key sk-ant-...Alternatively, pass a full MCP server URL with --url:
npx @sanity-labs/agent-context-inspector@latest dev \
--url https://api.sanity.io/v2026-03-03/agent-context/:projectId/:dataset/my-agent \
--token sk-... \
--anthropic-api-key sk-ant-...Option C: Config file
For teams or multi-context setups, install the package and create a context-inspector.config.ts:
npm install -D @sanity-labs/agent-context-inspectorimport {defineConfig} from '@sanity-labs/agent-context-inspector'
export default defineConfig({
contexts: [
{
name: 'my-agent',
title: 'My Agent',
url: 'https://api.sanity.io/v2026-03-03/agent-context/:projectId/:dataset',
tokenEnv: 'MY_AGENT_TOKEN',
systemPrompt: 'You are a helpful assistant.',
},
// Add more contexts here...
],
})Add your keys to .env. The tokenEnv field in your config is the env var name the server reads the Sanity API token from:
ANTHROPIC_API_KEY=sk-ant-...
MY_AGENT_TOKEN=sk-...Then start the dev server:
npx context-inspector devPrerequisites
All options require a Sanity API token (read access) and an Anthropic API key:
- Sanity tokens can be created with
sanity tokens add "My agent token"or at sanity.io/manage. See the Sanity CLI tokens reference for more details. - Anthropic API keys can be created at console.anthropic.com.
Precedence
When multiple sources are present: CLI flags > config file > browser UI.
Commands
The examples below use
npx context-inspectorwhich requires the package to be installed locally. If you haven't installed it, usenpx @sanity-labs/agent-context-inspectorinstead.
dev
Start the development server with hot reloading:
npx context-inspector dev [options]Opens at http://localhost:3100 by default.
build
Build for production deployment (requires a config file):
npx context-inspector buildOutputs a self-contained server to .output/.
preview
Preview the production build locally:
npx context-inspector preview [--port 3100]CLI flags
All flags are optional. When --project-id, --dataset, and --token are provided together, the inspector connects without needing a config file.
| Flag | Description | Default |
| --------------------------- | ----------------------------------------------- | --------------- |
| --port <port> | Port to listen on | 3100 |
| --project-id <id> | Sanity project ID | |
| --dataset <name> | Sanity dataset name | |
| --slug <slug> | Agent Context document slug | |
| --token <token> | Sanity API read token | |
| --anthropic-api-key <key> | Anthropic API key | |
| --url <url> | Full MCP server URL (overrides project/dataset) | |
| --api-version <version> | Sanity API version | v2026-03-03 |
| --api-host <host> | Sanity API host | api.sanity.io |
| --name <name> | Context display name | |
Config file reference
Each context entry accepts:
| Field | Required | Description |
| -------------- | -------- | ------------------------------------------------------------------- |
| name | yes | URL-safe identifier |
| title | yes | Display name in the UI |
| url | yes | MCP server URL |
| tokenEnv | yes | Env var name holding the Sanity API token (e.g. 'MY_AGENT_TOKEN') |
| systemPrompt | no | Default system prompt |
| instructions | no | Default MCP instructions override |
| groqFilter | no | Default GROQ filter override |
Optional fields can also be edited live in the sidebar during a session.
