CLI reference
Context CLI command reference
Reference documentation for the Sanity CLI context command.
npx sanity context --help
pnpm dlx sanity context --help
yarn dlx sanity context --help
bunx sanity context --help
Commands
build
USAGE
$ sanity context build KNOWLEDGEBASEID [--cancel] [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--cancel Cancel the running build instead of starting one
--watch Wait for the job to finish, exiting non-zero if it fails
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Queues a build over the knowledge base's current sources and returns a job ID immediately. If a build is already running, the response returns that build's job ID instead of starting a second build. A draft can't be built: the request returns `409` with code `knowledgeBaseIsDraft`.
EXAMPLES
Start a build and return the job ID
$ sanity context build kb-abc123
Start a build and wait for it to finish (non-zero exit on failure)
$ sanity context build kb-abc123 --watch
Cancel the running build, if any
$ sanity context build kb-abc123 --cancelcreate
USAGE
$ sanity context create [--description <value>] [--draft] [--json] [--organization <id>] [--title <value>]
FLAGS
--description=<value> A short description of what the knowledge base covers. Required unless `draft` is `true`.
--draft Whether to create the knowledge base as a draft. You can add sources to a draft, and they sync right away, but you can't build it, and the list leaves it out unless you set `includeDrafts` to `true`. A draft counts toward your plan's knowledge base limit. To finish it, update it with `draft` set to `false`.
--title=<value> The knowledge base's title. Required unless `draft` is `true`.
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization ID (overrides CLI configuration)
DESCRIPTION
Creates a knowledge base in your organization. To add content to it, add a source. Set `draft` to `true` to create a draft, which needs no title or description until you finish it. If your organization's Context document store can't be used, the request returns `503` with code `contextStoreUnavailable` and you can retry.
EXAMPLES
Create a knowledge base
$ sanity context create
Create a knowledge base, as JSON
$ sanity context create --jsondelete
USAGE
$ sanity context delete KNOWLEDGEBASEID [--yes] [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Deletes the knowledge base and everything it owns: its sources, revisions, stored source files, and its documents in your organization's document store. While a build, refresh, apply, or sync is running, the request returns `409` with code `buildInFlight`. Retry after that work finishes.
EXAMPLES
Delete a knowledge base
$ sanity context delete <knowledgeBaseId>
Delete a knowledge base, as JSON
$ sanity context delete <knowledgeBaseId> --jsondocuments
content
USAGE
$ sanity context documents content KNOWLEDGEBASEID DOCUMENTID [-o <file>] [--chunk <value>] [--format <value>] [--json] [--line-numbers] [--lines <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
DOCUMENTID The document's ID.
FLAGS
-o, --output=<file> Write the content to this file instead of stdout
--chunk=<value> Return only this chunk's lines. Citations name the chunk they quote.
--format=<value> Response format. `json` (default) returns the markdown with its line numbers. `markdown` and `plain` return the markdown alone, ready to pass to a model. `raw` returns the bytes the source gave, before conversion: the uploaded file, the crawled page, the dataset document as JSON.
--line-numbers Number each line as citations number them
--lines=<value> Return only these lines, from 1 and inclusive: `10-20`, or `10` for line 10 to the end. A range past the end returns up to the last line.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns the markdown a document converted to: the text builds read, and the line numbers citations use. Set `chunk` or `lines` to get part of it, and `format` to `markdown` or `plain` to get the text alone instead of JSON. Until the document is converted, the request returns `409` with code `documentNotConverted`. With `format=raw` it returns the document as its source gave it, as an attachment, or `409` with code `documentNotStored` when the document was too large to keep.
EXAMPLES
Print a document's markdown
$ sanity context documents content kb-abc123 document-def456
Print lines 10 to 20, each with its line number
$ sanity context documents content kb-abc123 document-def456 --lines 10-20 --line-numbers
Download the original file
$ sanity context documents content kb-abc123 document-def456 --format raw --output handbook.pdfdelete
USAGE
$ sanity context documents delete KNOWLEDGEBASEID DOCUMENTID [--yes] [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
DOCUMENTID The document's ID.
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Deletes a document from its source. A page that is still on the website comes back on the next sync of its source unless the crawl options exclude it. Entries that cite the document stay the same until the next build or refresh, which removes the citations.
EXAMPLES
Delete a document
$ sanity context documents delete <knowledgeBaseId> <documentId>
Delete a document, as JSON
$ sanity context documents delete <knowledgeBaseId> <documentId> --jsonedit
USAGE
$ sanity context documents edit KNOWLEDGEBASEID DOCUMENTID [--json] --state <value>
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
DOCUMENTID The document's ID.
FLAGS
--state=<value> Set to `active` to keep a `missing` page in the knowledge base. The count of crawls that missed it starts again.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Keeps a `missing` web page in the knowledge base by setting its `state` back to `active`. A document that isn't `missing` returns `409` with code `documentInvalidState`.
EXAMPLES
Keep a missing document
$ sanity context documents edit <knowledgeBaseId> <documentId>
Keep a missing document, as JSON
$ sanity context documents edit <knowledgeBaseId> <documentId> --jsonget
USAGE
$ sanity context documents get KNOWLEDGEBASEID DOCUMENTID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
DOCUMENTID The document's ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns a document with its conversion status and the chunks of its markdown. Entry citations point at a document's chunks.
EXAMPLES
Get a document
$ sanity context documents get <knowledgeBaseId> <documentId>
Get a document, as JSON
$ sanity context documents get <knowledgeBaseId> <documentId> --jsonlist
USAGE
$ sanity context documents list KNOWLEDGEBASEID [--ids <value>] [--json] [--limit <value>] [--source <value>] [--state <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--ids=<value> Comma-separated IDs of the documents to return, up to 200, in any state. Use it to look up the documents entry citations point at.
--limit=<value> The maximum number of items to return.
--source=<value> Return only the documents of this source.
--state=<value> Return only documents in this state. Without it, `deleted` documents are left out.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Lists the documents in a knowledge base: the pages, dataset documents and files its sources yield, which builds read and cite. Results are cursor-paginated, and you can filter them by `source` and `state`.
EXAMPLES
List documents
$ sanity context documents list <knowledgeBaseId>
List documents, as JSON
$ sanity context documents list <knowledgeBaseId> --jsonentries
get
USAGE
$ sanity context entries get KNOWLEDGEBASEID PATH [--json]
ARGUMENTS
KNOWLEDGEBASEID Knowledge base ID
PATH Entry path, as listed by `sanity context entries list`
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Get an entry and its content
EXAMPLES
Print an entry and its content
$ sanity context entries get kb-abc123 billing/refunds
Output the entry, including citations, as JSON
$ sanity context entries get kb-abc123 billing/refunds --jsonlist
USAGE
$ sanity context entries list KNOWLEDGEBASEID [--json]
ARGUMENTS
KNOWLEDGEBASEID Knowledge base ID
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List the entries a knowledge base build produced
EXAMPLES
List all entries for a knowledge base
$ sanity context entries list kb-abc123
Output entries as JSON
$ sanity context entries list kb-abc123 --jsonrebuild
USAGE
$ sanity context entries rebuild KNOWLEDGEBASEID ENTRYPATH [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
ENTRYPATH The entry's slash-delimited path, such as `pricing/plans/free`, URL-encoded.
FLAGS
--watch Wait for the job to finish, exiting non-zero if it fails
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Queues a rewrite of the entry at `entryPath` from its cited sources and the active instructions, and returns a job ID immediately. The response also lists the other entries built from any of the same sources. An instruction applies to every entry built from its sources, so those entries can change too. Returns `422` with code `entryDocumentInvalid` if the entry document was edited into a shape the API cannot read.
EXAMPLES
Rebuild an entry from its sources
$ sanity context entries rebuild <knowledgeBaseId> <entryPath>
Rebuild an entry from its sources, as JSON
$ sanity context entries rebuild <knowledgeBaseId> <entryPath> --jsonget
USAGE
$ sanity context get KNOWLEDGEBASEID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns a knowledge base's metadata and state. `knowledgeBaseId` accepts the public ID (`kb...`) or the UUID, and you don't need to pass an organization. If you can't read the knowledge base, the request returns `404`. To read the built entries, query `sanity.context.entry` documents with GROQ from your organization's document store.
EXAMPLES
Get a knowledge base
$ sanity context get <knowledgeBaseId>
Get a knowledge base, as JSON
$ sanity context get <knowledgeBaseId> --jsoninstructions
create
USAGE
$ sanity context instructions create KNOWLEDGEBASEID [--json] [--rebuild-paths <value>] --scope-document-ids <value> --statement <value> [--verified]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--rebuild-paths=<value> Paths of entries to rebuild under the new instruction right away. The response returns the rebuild job ID in `rebuildJobId`.
--scope-document-ids=<value> IDs of the documents the instruction applies to. Builds apply it when they write entries built from these documents. IDs of documents that no longer exist are dropped. If none exist, the request returns `422` with code `instructionScopeVanished`.
--statement=<value> The instruction in plain language. Builds follow it over what the sources say.
--verified Whether you already checked the instruction for entries that contradict it. When `true`, the background check that files issues for those entries is skipped. It still runs if the rebuild you requested in `rebuildPaths` does not start.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Creates a standing instruction for how entries built from its documents are written. Every instruction applies to specific documents, set in `scopeDocumentIds`. To rebuild entries under the new instruction right away, pass their paths in `rebuildPaths`. The response includes the rebuild job ID, or `null` if the rebuild could not start. The instruction is saved either way. After the instruction is saved, a background check files issues for entries that contradict it. If you already checked the instruction for contradictions, set `verified` to skip the background check. If the requested rebuild does not start, the background check runs even when `verified` is set.
EXAMPLES
Create an instruction
$ sanity context instructions create <knowledgeBaseId>
Create an instruction, as JSON
$ sanity context instructions create <knowledgeBaseId> --jsondelete
USAGE
$ sanity context instructions delete KNOWLEDGEBASEID INSTRUCTIONID [--yes] [--json] [--rebuild]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
INSTRUCTIONID The instruction's ID.
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
--rebuild Set to `true` to rebuild every entry built from the instruction's documents once it is deleted, so pages written under the instruction reflect their documents again. The response returns the rebuild job ID in `rebuildJobId`.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Deletes the instruction. Builds stop applying it from the next run. Entries already written under it keep their text until they are rebuilt; pass `rebuild=true` to rebuild every entry built from its documents right away.
EXAMPLES
Delete an instruction
$ sanity context instructions delete <knowledgeBaseId> <instructionId>
Delete an instruction, as JSON
$ sanity context instructions delete <knowledgeBaseId> <instructionId> --jsonedit
USAGE
$ sanity context instructions edit KNOWLEDGEBASEID INSTRUCTIONID [--json] [--scope-document-ids <value>] [--statement <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
INSTRUCTIONID The instruction's ID.
FLAGS
--scope-document-ids=<value> IDs of the documents the instruction applies to. Replaces the current list. Omit it to keep the current documents. IDs of documents that no longer exist are dropped. If none exist, the request returns `422` with code `instructionScopeVanished`.
--statement=<value> The new instruction text. Omit it to keep the current text.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Updates the instruction's statement or documents. The change applies from the next build. Any update also reactivates an archived instruction and ties it to the current content of its documents.
EXAMPLES
Update an instruction
$ sanity context instructions edit <knowledgeBaseId> <instructionId>
Update an instruction, as JSON
$ sanity context instructions edit <knowledgeBaseId> <instructionId> --jsonissues
apply
USAGE
$ sanity context issues apply KNOWLEDGEBASEID ISSUEIDS [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
ISSUEIDS The IDs of the issues to accept and apply.
FLAGS
--watch Wait for the job to finish, exiting non-zero if it fails
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Accepts the issues in `issueIds`, then queues a job that applies them, rewrites the affected entries, and saves a new revision. Returns a job ID. IDs of issues that no longer exist are skipped. Returns `409` with code `issueNotAutoApplicable`, and accepts none of the issues, if any of them cannot be applied: a `conflict` (resolve it with `POST .../issues/{issueId}/resolve`), or an `update_required` issue whose `scopePath` is `*` or names an entry that no longer exists. Dismiss those instead.
EXAMPLES
Accept and apply issues
$ sanity context issues apply <knowledgeBaseId>
Accept and apply issues, as JSON
$ sanity context issues apply <knowledgeBaseId> --jsondismiss
USAGE
$ sanity context issues dismiss KNOWLEDGEBASEID ISSUEID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
ISSUEID The issue's document ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Marks the issue as rejected. If the issue already left triage, the request returns it unchanged. Returns `422` with code `issueDocumentInvalid` if the issue document was edited into a shape the API cannot verify. Returns `409` with code `issueTransitionConflict` if another change to the issue happened at the same time. You can safely retry a `409`.
EXAMPLES
Dismiss an issue
$ sanity context issues dismiss <knowledgeBaseId> <issueId>
Dismiss an issue, as JSON
$ sanity context issues dismiss <knowledgeBaseId> <issueId> --jsonget
USAGE
$ sanity context issues get KNOWLEDGEBASEID ISSUEID [--json]
ARGUMENTS
KNOWLEDGEBASEID Knowledge base ID
ISSUEID Issue ID
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Get details of an issue
EXAMPLES
Get details of a specific issue
$ sanity context issues get kb-abc123 issue.def456
Output the issue as JSON
$ sanity context issues get kb-abc123 issue.def456 --jsonlist
USAGE
$ sanity context issues list KNOWLEDGEBASEID [--json] [--kind <value>] [--scope <path>] [--severity <value>] [--status <value>]
ARGUMENTS
KNOWLEDGEBASEID Knowledge base ID
FLAGS
--kind=<value> Only list issues of this kind
--scope=<path> Only list issues about this entry path or anything under it (`*` for knowledge-base-wide issues)
--severity=<value> Only list issues of this severity
--status=<value> Only list issues with this status (rejected = dismissed, accepted = resolved or applied)
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List issues found by knowledge base builds
EXAMPLES
List all issues for a knowledge base
$ sanity context issues list kb-abc123
List issues awaiting triage
$ sanity context issues list kb-abc123 --status open
List critical conflicts
$ sanity context issues list kb-abc123 --kind conflict --severity critical
List issues about entries under billing/
$ sanity context issues list kb-abc123 --scope billing
Output issues as JSON
$ sanity context issues list kb-abc123 --jsonreopen
USAGE
$ sanity context issues reopen KNOWLEDGEBASEID ISSUEID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
ISSUEID The issue's document ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns an accepted conflict issue to triage, clears its resolution, and deletes the instruction the resolution created. Reopening an open or dismissed conflict returns it unchanged. Other issue types return `422` with code `issueNotResolvable`.
EXAMPLES
Reopen an accepted conflict
$ sanity context issues reopen <knowledgeBaseId> <issueId>
Reopen an accepted conflict, as JSON
$ sanity context issues reopen <knowledgeBaseId> <issueId> --jsonresolve
USAGE
$ sanity context issues resolve KNOWLEDGEBASEID ISSUEID [--json] [--side <value>] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
ISSUEID The issue's document ID.
FLAGS
--side=<value> Index of the correct side, as listed by `sanity context issues get`
--watch Wait for the job to finish, exiting non-zero if it fails
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Resolves a conflict issue by choosing one of its sides. Set `resolution` to the index of a side in `content.sides`. For a conflict on a single entry, index `0` is the entry's current content, so choosing it keeps the entry as it is. Choosing any other side rewrites the entry, and the returned `jobId` tracks the rewrite. The decision becomes a standing instruction for every future build, and `resolvedBy` records who made it. To change a decision, resolve the accepted conflict again. Other issue types, dismissed conflicts, and out-of-range indexes return `422` with code `issueNotResolvable`.
EXAMPLES
Choose the correct side interactively
$ sanity context issues resolve kb-abc123 issue-def456
Choose side 1 and wait for the entry rewrite
$ sanity context issues resolve kb-abc123 issue-def456 --side 1 --watchjobs
get
USAGE
$ sanity context jobs get KNOWLEDGEBASEID JOBID [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
JOBID The job ID returned by the endpoint that started the work.
FLAGS
--watch Wait for the job to finish, exiting non-zero if it fails
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns the status of a background job, such as a build, sync, or refresh. The endpoint that starts the work returns the job ID.
EXAMPLES
Get a job
$ sanity context jobs get <knowledgeBaseId> <jobId>
Get a job, as JSON
$ sanity context jobs get <knowledgeBaseId> <jobId> --jsonlist
USAGE
$ sanity context list [--include-drafts] [--json] [--limit <value>] [--organization <id>]
FLAGS
--include-drafts Set to `true` to also list the organization's drafts, which have `state` set to `draft`. Drafts count toward the plan's knowledge base limit, and `createdBy` says who started each one.
--limit=<value> The maximum number of items to return.
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization ID (overrides CLI configuration)
DESCRIPTION
Returns the knowledge bases you can access in the organization set by `organizationId`. Drafts are left out unless you set `includeDrafts` to `true`. Results are cursor-paginated, newest first.
EXAMPLES
List knowledge bases
$ sanity context list
List knowledge bases, as JSON
$ sanity context list --jsonmcp
create
USAGE
$ sanity context mcp create NAME [-d <name>] [-p <id>] [--groq-filter <value>] [--instructions <value>] [--knowledge-base <id>] [--organization <id>] [--perspective <value>] [--semantic-search] [--title <value>] [--workspace <value>]
ARGUMENTS
NAME Permanent MCP endpoint name used in its URL, made of lowercase letters, digits and hyphens
FLAGS
-d, --dataset=<name> Dataset the endpoint serves
--groq-filter=<value> GROQ filter that limits which dataset documents the endpoint serves
--instructions=<value> Instructions the endpoint serves to connecting agents
--knowledge-base=<id> Knowledge base the endpoint serves; repeat the flag to serve several
--perspective=<value> Perspective agents query the dataset with
--semantic-search Let agents use semantic search on the dataset (--no-semantic-search to turn it off)
--title=<value> MCP endpoint title
--workspace=<value> Studio workspace whose schema agents use, instead of the first workspace
OVERRIDE FLAGS
-p, --project=<id> Project the dataset belongs to (overrides CLI configuration)
--organization=<id> Organization to create the MCP endpoint in (overrides CLI configuration)
DESCRIPTION
Create a Context MCP endpoint that serves knowledge bases and a dataset to agents
EXAMPLES
Create an MCP endpoint that serves two knowledge bases
$ sanity context mcp create support --title "Support" --knowledge-base kb-abc123 --knowledge-base kb-def456
Create an MCP endpoint that serves the products in a dataset
$ sanity context mcp create catalog --title "Catalog" --project abc123 --dataset production --perspective drafts --groq-filter '_type in ["product"]'delete
USAGE
$ sanity context mcp delete NAME [--yes] [--organization <id>]
ARGUMENTS
NAME MCP endpoint name, as in its URL
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
OVERRIDE FLAGS
--organization=<id> Organization the MCP endpoint belongs to (overrides CLI configuration)
DESCRIPTION
Delete a Context MCP endpoint, which disconnects any agents using it
EXAMPLES
Delete an MCP endpoint after confirmation
$ sanity context mcp delete support
Delete an MCP endpoint without confirmation prompt
$ sanity context mcp delete support --yesget
USAGE
$ sanity context mcp get NAME [--json] [--organization <id>]
ARGUMENTS
NAME MCP endpoint name, as in its URL
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization the MCP endpoint belongs to (overrides CLI configuration)
DESCRIPTION
Get details of a Context MCP endpoint, including its URL
EXAMPLES
Get details of the "support" MCP endpoint
$ sanity context mcp get support
Output an MCP endpoint in a specific organization as JSON
$ sanity context mcp get support --organization org-abc123 --jsoninitial-context
USAGE
$ sanity context mcp initial-context MCPENDPOINT [--heading_offset <value>] [--json] [--link-resolver <value>] [--organization <id>]
ARGUMENTS
MCPENDPOINT The MCP endpoint's name, set when the endpoint was created.
FLAGS
--heading_offset=<value> How many levels to shift markdown headings down, from `0` to `6`. Defaults to `1`, so `#` becomes `##`.
--link-resolver=<value> A JSON array that adds `_url` fields to query results. Each item has `types` (document types), `baseUrl`, and an optional `slugExpression`, a GROQ expression that defaults to `slug.current`. Invalid JSON is ignored.
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization ID (overrides CLI configuration)
DESCRIPTION
Returns the same text as the `initial_context` MCP tool, as plain text you can add to a system prompt. `heading_offset` shifts markdown headings down by that many levels. The default is `1`, so `#` becomes `##`.
EXAMPLES
Get an MCP endpoint's initial context
$ sanity context mcp initial-context <mcpEndpoint>
Get an MCP endpoint's initial context, as JSON
$ sanity context mcp initial-context <mcpEndpoint> --jsonlist
USAGE
$ sanity context mcp list [--json] [--organization <id>]
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization to list MCP endpoints for (overrides CLI configuration)
DESCRIPTION
List Context MCP endpoints in an organization
EXAMPLES
List MCP endpoints, selecting the organization interactively
$ sanity context mcp list
Output the MCP endpoints of a specific organization as JSON
$ sanity context mcp list --organization org-abc123 --jsonstatus
USAGE
$ sanity context mcp status NAME [--json] [--organization <id>]
ARGUMENTS
NAME MCP endpoint name, as in its URL
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization the MCP endpoint belongs to (overrides CLI configuration)
DESCRIPTION
Check whether an agent connecting with your credentials can use a Context MCP endpoint
EXAMPLES
Check the "support" MCP endpoint
$ sanity context mcp status supportupdate
USAGE
$ sanity context mcp update NAME [-d <name>] [-p <id>] [--add-knowledge-base <id>] [--groq-filter <value>] [--instructions <value>] [--no-dataset] [--organization <id>] [--perspective <value>] [--remove-knowledge-base <id>] [--semantic-search] [--title <value>] [--workspace <value>]
ARGUMENTS
NAME MCP endpoint name, as in its URL
FLAGS
-d, --dataset=<name> Dataset the endpoint serves, replacing its current dataset
--add-knowledge-base=<id> Knowledge base to add to the endpoint; repeat the flag to add several
--groq-filter=<value> GROQ filter that limits which dataset documents the endpoint serves ("" removes it)
--instructions=<value> Instructions the endpoint serves to connecting agents ("" removes them)
--no-dataset Stop serving the dataset, which also removes the GROQ filter
--perspective=<value> Perspective agents query the dataset with
--remove-knowledge-base=<id> Knowledge base to remove from the endpoint; repeat the flag to remove several
--semantic-search Let agents use semantic search on the dataset (--no-semantic-search to turn it off)
--title=<value> New MCP endpoint title
--workspace=<value> Studio workspace whose schema agents use ("" goes back to the first workspace)
OVERRIDE FLAGS
-p, --project=<id> Project the dataset belongs to (overrides CLI configuration)
--organization=<id> Organization the MCP endpoint belongs to (overrides CLI configuration)
DESCRIPTION
Update a Context MCP endpoint
Only the settings you pass change. Dataset settings (--workspace, --perspective, --semantic-search) apply to the endpoint's dataset and start from the defaults when --dataset switches to another dataset.
EXAMPLES
Rename an MCP endpoint
$ sanity context mcp update support --title "Customer support"
Serve a different knowledge base
$ sanity context mcp update support --add-knowledge-base kb-def456 --remove-knowledge-base kb-abc123
Switch to another dataset and query its drafts
$ sanity context mcp update catalog --project abc123 --dataset staging --perspective drafts
Stop serving the dataset
$ sanity context mcp update support --no-dataset
Remove the instructions
$ sanity context mcp update support --instructions ""query
USAGE
$ sanity context query QUERY [--json] [--organization <id>] [--params <json>]
ARGUMENTS
QUERY GROQ query to run against the organization's Context documents
FLAGS
--params=<json> Query parameters as a JSON object
GLOBAL FLAGS
--json Format output as json.
OVERRIDE FLAGS
--organization=<id> Organization to query (overrides CLI configuration)
DESCRIPTION
Query an organization's Context documents with GROQ
EXAMPLES
List open issues across all knowledge bases
$ sanity context query '*[_type == "sanity.context.issue" && status == "open"]{_id, knowledgeBaseId}'
List the entry paths of one knowledge base as plain JSON
$ sanity context query '*[_type == "sanity.context.entry" && knowledgeBaseId == $kb].path' --params '{"kb": "kb-abc123"}' --jsonsources
create
USAGE
$ sanity context sources create KNOWLEDGEBASEID [--content-type <value>] [--dry-run] [--exclude-paths <value>] [--file <path>] [--ignore-query-parameters] [--include-paths <value>] [--json] [--max-depth <value>] [--page-limit <value>] [--query <value>] [--sanity-dataset-id <value>] [--sanity-project-id <value>] [--sitemap-only] [--text <path|->] [--title <value>] [--type <value>] [--url <value>] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--content-type=<value> The format of `content`: `text/markdown` (the default) or `text/plain`. Only with `content`. Only for type files.
--dry-run Set to `true` to estimate what a crawl would fetch without adding the source. The response is then `200` with a preview of the pages the site has, grouped by path. Only for type web.
--exclude-paths=<value> Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled. Only for type web.
--file=<path> Local file to upload as a files source: a document, or a zip, tar or gzip archive of them
--ignore-query-parameters Whether to treat URLs that differ only by query string as one page. New crawls set it to `true` unless you set it. Set it to `false` when the query string selects different content, such as pagination. Only for type web.
--include-paths=<value> Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them. Only for type web.
--max-depth=<value> How many levels deep the crawl goes from the root URL. Only for type web.
--page-limit=<value> The maximum number of pages to crawl. The crawl can stop sooner when the knowledge base reaches its source limit. Only for type web.
--query=<value> A GROQ query that selects the documents, with an optional projection. Each sync runs it again. Only for type sanity-dataset.
--sanity-dataset-id=<value> The dataset to read documents from. Only for type sanity-dataset.
--sanity-project-id=<value> The ID of the Sanity project to read documents from. You need full read access to the dataset and, on its project, the Administrator or Developer role or a custom role that can create datasets. Only for type sanity-dataset.
--sitemap-only Whether to crawl only the pages listed in the site's sitemap. Only for type web.
--text=<path|-> Text or markdown to hold as a files source, read from a local file or `-` for stdin
--title=<value> The source's title. Only for type files.
--type=<value> The source type. `web` crawls a website. Inferred from the other flags when left out.
--url=<value> The URL to start crawling from. It must be a public `http` or `https` URL. Only for type web.
--watch Wait for the sync to settle, exiting non-zero unless it completes: when it fails, is cancelled or is held for confirmation
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Adds a source to a knowledge base. Set `type` to choose what it reads:
- `web`: a website, crawled from `url`
- `sanity-dataset`: the documents a GROQ query selects in a Sanity dataset
- `files`: files you upload with `POST .../sources/{sourceId}/uploads`, or text you send in `content`
A website or dataset starts its first sync right away. A `files` source syncs when you upload a file, or right away when you send `content`: one request stores the text, adds the source and starts its sync. For a website, set `dryRun` to `true` to preview the crawl without adding the source.
Adding a website that is already a source returns `409` with code `webSourceRootConflict`, and adding more websites than your limit allows returns `409` with code `webSourceRootLimitExceeded`. When the organization's knowledge bases already hold as many source chunks as its plan allows, returns `403` with code `planLimitReached` and adds nothing. Supports the `Idempotency-Key` header.
EXAMPLES
Crawl a website
$ sanity context sources create kb-abc123 --url https://example.com/docs
Estimate how many pages a crawl of /docs would find, without adding it
$ sanity context sources create kb-abc123 --url https://example.com/docs --dry-run
Read the documents a GROQ query selects from a Sanity dataset
$ sanity context sources create kb-abc123 --query '*[_type == "article"]' --sanity-project-id abc123 --sanity-dataset-id production
Upload a local file and wait for its sync
$ sanity context sources create kb-abc123 --file ./handbook.pdf --watch
Add markdown from stdin
$ cat refunds.md | sanity context sources create kb-abc123 --text - --title "Refund policy"delete
USAGE
$ sanity context sources delete KNOWLEDGEBASEID SOURCEID [--yes] [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
FLAGS
-y, --yes Skip confirmation prompt (unattended mode)
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Removes a source and its documents from the knowledge base, and starts a refresh that removes their citations from entries and deletes the entries left with none. A source no other knowledge base uses stops syncing and is deleted once that refresh has run.
EXAMPLES
Delete a source
$ sanity context sources delete <knowledgeBaseId> <sourceId>
Delete a source, as JSON
$ sanity context sources delete <knowledgeBaseId> <sourceId> --jsonedit
USAGE
$ sanity context sources edit KNOWLEDGEBASEID SOURCEID [--confirm-deletions] [--exclude-paths <value>] [--ignore-query-parameters] [--include-paths <value>] [--json] [--max-depth <value>] [--page-limit <value>] [--query <value>] [--sitemap-only] [--sync-frequency <value>] [--title <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
FLAGS
--confirm-deletions Set to `true` to apply new crawl options that delete many documents. Without it, a change that would delete all of the documents, or five or more that are over a fifth of them, returns `409` with code `sourceDeletionsUnconfirmed`.
--exclude-paths=<value> Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.
--ignore-query-parameters Whether to treat URLs that differ only by query string as one page. New crawls set it to `true` unless you set it. Set it to `false` when the query string selects different content, such as pagination.
--include-paths=<value> Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.
--max-depth=<value> How many levels deep the crawl goes from the root URL.
--page-limit=<value> The maximum number of pages to crawl. The crawl can stop sooner when the knowledge base reaches its source limit.
--query=<value> For a `sanity-dataset` source, the GROQ query, replacing the stored one. A sync is queued, and removes the documents the query no longer returns.
--sitemap-only Whether to crawl only the pages listed in the site's sitemap.
--sync-frequency=<value> For a `web` or `sanity-dataset` source, how often it syncs on its own: `weekly` or `monthly`. `null` stops scheduled syncs, and you can still start a sync yourself. Setting a frequency requires a plan that includes scheduled syncs; without one, the request returns `403` with code `featureNotInPlan`. Pass `null` to clear it.
--title=<value> The source's title.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Changes a source's title, a website's crawl options, a dataset's query, or how often a website or dataset syncs on its own. New crawl options delete the documents whose path they leave out. When that would delete all of the source's documents, or five or more that are over a fifth of them, the request returns `409` with code `sourceDeletionsUnconfirmed` until you send it again with `confirmDeletions` set to `true`. New crawl options sent while the source syncs return `409` with code `syncInProgress`; send them again once the sync finishes. A new query queues a sync, which removes the documents the query no longer selects.
Crawl options on a source that isn't a website, a query on one that isn't a dataset, or a sync frequency on a `files` source, return `422` with code `sourceTypeMismatch`. Setting a sync frequency on a plan without scheduled syncs returns `403` with code `featureNotInPlan`; setting it to `null` always works.
EXAMPLES
Update a source
$ sanity context sources edit <knowledgeBaseId> <sourceId>
Update a source, as JSON
$ sanity context sources edit <knowledgeBaseId> <sourceId> --jsonget
USAGE
$ sanity context sources get KNOWLEDGEBASEID SOURCEID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns a source with its settings, document counts and latest sync.
EXAMPLES
Get a source
$ sanity context sources get <knowledgeBaseId> <sourceId>
Get a source, as JSON
$ sanity context sources get <knowledgeBaseId> <sourceId> --jsonlist
USAGE
$ sanity context sources list KNOWLEDGEBASEID [--json] [--limit <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--limit=<value> The maximum number of items to return.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Lists the sources of a knowledge base: the websites, Sanity datasets and files its documents come from, each with its document counts and its latest sync. Results are cursor-paginated.
EXAMPLES
List sources
$ sanity context sources list <knowledgeBaseId>
List sources, as JSON
$ sanity context sources list <knowledgeBaseId> --jsonsync
USAGE
$ sanity context sources sync KNOWLEDGEBASEID SOURCEID [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
FLAGS
--watch Wait for the sync to settle, exiting non-zero unless it completes: when it fails, is cancelled or is held for confirmation
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Starts a sync of the source. A website or dataset is read again: its sync is queued, and starts once any sync of the source that is running ends, including the first one that started when it was added. Asking again while one waits queues nothing more. Follow it with the source's `latestSync`.
For a `files` source, set `uploadId` to the upload whose file the source should hold from now on; without it, the source reads its current file again. Its sync starts at once and returns a job ID to poll; the finished job's `result` names the sync and whether it is `held`. While a sync of a `files` source is running, including the first one, the request returns `409` with code `syncInProgress` and leaves the upload for a later request. An `uploadId` whose file never arrived returns `404` with code `uploadNotFound`, and an `uploadId` on a source that isn't `files` returns `422` with code `sourceTypeMismatch`.
Supports the `Idempotency-Key` header.
EXAMPLES
Sync a source
$ sanity context sources sync <knowledgeBaseId> <sourceId>
Sync a source, as JSON
$ sanity context sources sync <knowledgeBaseId> <sourceId> --jsonsyncs confirm
USAGE
$ sanity context sources syncs confirm KNOWLEDGEBASEID SOURCEID SYNCID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
SYNCID The sync's ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Deletes the documents a `held` sync didn't find, unless a sync has found them since, completes the sync, and starts a refresh of each knowledge base that uses the source, which removes their citations from entries. A sync that isn't `held` returns `409` with code `syncNotHeld`.
EXAMPLES
Confirm a held sync's deletions
$ sanity context sources syncs confirm <knowledgeBaseId> <sourceId> <syncId>
Confirm a held sync's deletions, as JSON
$ sanity context sources syncs confirm <knowledgeBaseId> <sourceId> <syncId> --jsonsyncs discard
USAGE
$ sanity context sources syncs discard KNOWLEDGEBASEID SOURCEID SYNCID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
SYNCID The sync's ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Completes a `held` sync without deleting anything: every document stays as it is. A sync that isn't `held` returns `409` with code `syncNotHeld`.
EXAMPLES
Discard a held sync's deletions
$ sanity context sources syncs discard <knowledgeBaseId> <sourceId> <syncId>
Discard a held sync's deletions, as JSON
$ sanity context sources syncs discard <knowledgeBaseId> <sourceId> <syncId> --jsonsyncs get
USAGE
$ sanity context sources syncs get KNOWLEDGEBASEID SOURCEID SYNCID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
SYNCID The sync's ID.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Returns one sync of a source with its status and counts.
EXAMPLES
Get a sync
$ sanity context sources syncs get <knowledgeBaseId> <sourceId> <syncId>
Get a sync, as JSON
$ sanity context sources syncs get <knowledgeBaseId> <sourceId> <syncId> --jsonsyncs list
USAGE
$ sanity context sources syncs list KNOWLEDGEBASEID SOURCEID [--json] [--limit <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
FLAGS
--limit=<value> The maximum number of items to return.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Lists the syncs of a source, newest first. Results are cursor-paginated.
EXAMPLES
List a source's syncs
$ sanity context sources syncs list <knowledgeBaseId> <sourceId>
List a source's syncs, as JSON
$ sanity context sources syncs list <knowledgeBaseId> <sourceId> --jsonupload
USAGE
$ sanity context sources upload KNOWLEDGEBASEID SOURCEID [--content-type <type>] --file <path> [--json] [--watch]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
SOURCEID The source's ID.
FLAGS
--content-type=<type> MIME type of the file, inferred from the file extension when omitted
--file=<path> Local file to upload: a document, or a zip, tar or gzip archive of them
--watch Wait for the sync to settle, exiting non-zero unless it completes: when it fails, is cancelled or is held for confirmation
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Upload a new file to a files source, replacing the one it holds, and sync it
EXAMPLES
Replace the file a source holds
$ sanity context sources upload kb-abc123 source-def456 --file ./handbook.pdf
Replace the file and wait for its sync to finish
$ sanity context sources upload kb-abc123 source-def456 --file ./handbook.pdf --watchsync
USAGE
$ sanity context sync KNOWLEDGEBASEID [--json]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Queues a sync of every website and dataset source, which starts once any sync of the source that is running ends. `files` sources sync when you upload a file.
EXAMPLES
Sync every source
$ sanity context sync <knowledgeBaseId>
Sync every source, as JSON
$ sanity context sync <knowledgeBaseId> --jsonupdate
USAGE
$ sanity context update KNOWLEDGEBASEID [--description <value>] [--draft] [--json] [--title <value>]
ARGUMENTS
KNOWLEDGEBASEID The knowledge base's ID (`kb...`), its `publicId`. Its UUID `id` is also accepted.
FLAGS
--description=<value> The knowledge base's new description.
--draft Set to `false` to finish a draft, so it can be built and is listed with your other knowledge bases. The knowledge base needs a title, sent here or set before. Ignored when the knowledge base isn't a draft. A finished knowledge base can't become a draft again.
--title=<value> The knowledge base's new title.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Updates the title or the description, or finishes a draft (`draft: false`). Fields equal to their current value are ignored, so sending the current values changes nothing. Finishing a draft with no title returns `422` with code `draftTitleRequired`. How often a website or dataset syncs is set on the source, with `PATCH .../sources/{sourceId}`.
EXAMPLES
Update a knowledge base
$ sanity context update <knowledgeBaseId>
Update a knowledge base, as JSON
$ sanity context update <knowledgeBaseId> --json