KosmoKrator

data

Sanity CLI for AI Agents

Use the Sanity CLI from KosmoKrator to call Sanity tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.

7 functions 4 read 3 write API token auth

Sanity CLI Setup

Sanity can be configured headlessly with `kosmokrator integrations:configure sanity`.

# Install KosmoKrator first if it is not available on PATH.
curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash

# Configure and verify this integration.
kosmokrator integrations:configure sanity --set api_token="$SANITY_API_TOKEN" --set project_id="$SANITY_PROJECT_ID" --enable --read allow --write ask --json
kosmokrator integrations:doctor sanity --json
kosmokrator integrations:status --json

Credentials

Authentication type: API token api_token. Configure credentials once, then use the same stored profile from scripts, coding CLIs, Lua code mode, and the MCP gateway.

KeyEnv varTypeRequiredLabel
api_token SANITY_API_TOKEN Secret secret yes API Token
project_id SANITY_PROJECT_ID Text text yes Project ID
dataset SANITY_DATASET Text text no Dataset

Call Sanity Headlessly

Use the generic call form when another coding CLI or script needs a stable universal interface.

kosmo integrations:call sanity.sanity_query_documents '{
  "query": "example_query",
  "params": "example_params"
}' --json

Use the provider shortcut form for shorter human-facing commands.

kosmo integrations:sanity sanity_query_documents '{
  "query": "example_query",
  "params": "example_params"
}' --json

Agent Discovery Commands

These commands return structured output for coding agents that need to inspect capabilities before choosing a function.

kosmo integrations:docs sanity --json
kosmo integrations:docs sanity.sanity_query_documents --json
kosmo integrations:schema sanity.sanity_query_documents --json
kosmo integrations:search "Sanity" --json
kosmo integrations:list --json

All CLI Functions

Every function below can be called headlessly. The generic form is stable across all integrations; the provider shortcut is shorter but specific to Sanity.

sanity.sanity_query_documents

Read read

Query documents in Sanity using GROQ (Graph-Relational Object Queries). Returns matching documents with their fields.

Parameters
query, params

Generic CLI call

kosmo integrations:call sanity.sanity_query_documents '{"query":"example_query","params":"example_params"}' --json

Provider shortcut

kosmo integrations:sanity sanity_query_documents '{"query":"example_query","params":"example_params"}' --json

sanity.sanity_get_document

Read read

Retrieve a single Sanity document by its ID. Returns the full document with all fields.

Parameters
id

Generic CLI call

kosmo integrations:call sanity.sanity_get_document '{"id":"example_id"}' --json

Provider shortcut

kosmo integrations:sanity sanity_get_document '{"id":"example_id"}' --json

sanity.sanity_create_document

Write write

Create a new document in the Sanity dataset. The document data must include a _type field matching a schema type.

Parameters
document

Generic CLI call

kosmo integrations:call sanity.sanity_create_document '{"document":"example_document"}' --json

Provider shortcut

kosmo integrations:sanity sanity_create_document '{"document":"example_document"}' --json

sanity.sanity_update_document

Write write

Update an existing Sanity document by applying a patch with the specified fields.

Parameters
id, set

Generic CLI call

kosmo integrations:call sanity.sanity_update_document '{"id":"example_id","set":"example_set"}' --json

Provider shortcut

kosmo integrations:sanity sanity_update_document '{"id":"example_id","set":"example_set"}' --json

sanity.sanity_delete_document

Write write

Delete a document from the Sanity dataset by its ID. This action is permanent.

Parameters
id

Generic CLI call

kosmo integrations:call sanity.sanity_delete_document '{"id":"example_id"}' --json

Provider shortcut

kosmo integrations:sanity sanity_delete_document '{"id":"example_id"}' --json

sanity.sanity_list_projects

Read read

List all Sanity projects accessible to the authenticated user. Requires a management API token.

Parameters
none

Generic CLI call

kosmo integrations:call sanity.sanity_list_projects '{}' --json

Provider shortcut

kosmo integrations:sanity sanity_list_projects '{}' --json

sanity.sanity_get_current_user

Read read

Get the currently authenticated Sanity user. Useful for verifying credentials and checking user identity.

Parameters
none

Generic CLI call

kosmo integrations:call sanity.sanity_get_current_user '{}' --json

Provider shortcut

kosmo integrations:sanity sanity_get_current_user '{}' --json

Function Schemas

Use these parameter tables when building CLI payloads without calling integrations:schema first.

sanity.sanity_query_documents

Query documents in Sanity using GROQ (Graph-Relational Object Queries). Returns matching documents with their fields.

Operation
Read read
Schema command
kosmo integrations:schema sanity.sanity_query_documents --json
ParameterTypeRequiredDescription
query string yes GROQ query string (e.g., `*[_type == "post"]`). See https://www.sanity.io/docs/groq for syntax.
params object no Optional parameters referenced in the query as $paramName (e.g., `{"type": "post"}` used as `*[_type == $type]`).

sanity.sanity_get_document

Retrieve a single Sanity document by its ID. Returns the full document with all fields.

Operation
Read read
Schema command
kosmo integrations:schema sanity.sanity_get_document --json
ParameterTypeRequiredDescription
id string yes The document ID (e.g., "post-123" or a draft ID like "drafts.post-123").

sanity.sanity_create_document

Create a new document in the Sanity dataset. The document data must include a _type field matching a schema type.

Operation
Write write
Schema command
kosmo integrations:schema sanity.sanity_create_document --json
ParameterTypeRequiredDescription
document object yes Document data as a JSON object. Must include a "_type" field (e.g., {"_type": "post", "title": "Hello", "body": "World"}).

sanity.sanity_update_document

Update an existing Sanity document by applying a patch with the specified fields.

Operation
Write write
Schema command
kosmo integrations:schema sanity.sanity_update_document --json
ParameterTypeRequiredDescription
id string yes The document ID to update (e.g., "post-123").
set object yes Fields to update as a JSON object (e.g., {"title": "Updated Title", "published": true}). Only the specified fields are changed.

sanity.sanity_delete_document

Delete a document from the Sanity dataset by its ID. This action is permanent.

Operation
Write write
Schema command
kosmo integrations:schema sanity.sanity_delete_document --json
ParameterTypeRequiredDescription
id string yes The document ID to delete (e.g., "post-123").

sanity.sanity_list_projects

List all Sanity projects accessible to the authenticated user. Requires a management API token.

Operation
Read read
Schema command
kosmo integrations:schema sanity.sanity_list_projects --json
ParameterTypeRequiredDescription
No parameters.

sanity.sanity_get_current_user

Get the currently authenticated Sanity user. Useful for verifying credentials and checking user identity.

Operation
Read read
Schema command
kosmo integrations:schema sanity.sanity_get_current_user --json
ParameterTypeRequiredDescription
No parameters.

Permissions

Headless calls still follow the integration read/write permission policy. Configure read/write defaults with integrations:configure. Add --force only for trusted automation that should bypass that policy.