Query and mutate a Sanity Content Lake — GROQ queries, transactional document mutations, publishing, revision history and dataset management.
Sanity ships in the w6w first-party pack. It declares 11 actions, 2 health checks, and the host runs its code in a sandbox that never sees the credential.
io.w6w.sanitySanity is a headless CMS built around a structured content store, and this app queries and mutates it from a workflow: running GROQ queries, fetching documents by id, and creating, patching, or deleting content, with unpublished drafts filtered out of query results by default. It is built for workflows that read or update structured content directly, rather than through Sanity’s own Studio editor.
Publishing and unpublishing go through Sanity’s dedicated publish mechanism rather than a manual replace-and-delete, so a document’s revision history and any scheduled release stay intact. A document’s history can be read as of a specific moment or revision, a whole dataset can be exported for backup, and every project and dataset a token can see can be listed — useful before pointing a workflow at the right one, since a mistyped dataset name returns an empty result rather than an error. Query-based patches and deletes support a dry run first, since a broad query can otherwise change far more than intended.
Three routes to the same 11 actions. The Workflow tab is generated from Sanity's own manifest and carries its real ids, so it is copy-pasteable; the Code and CLI examples are the same call for any action on any app, so every app-specific value in them is a blank you fill in.
dataset-list The datasets in this project. They share a schema and share no documents — pointing at the wrong one returns nothing rather than failing.
document-create Create a document, with Sanity's three modes: fail if it exists, skip if it exists, or replace it wholesale. Replace is not a merge — omitted fields are deleted.
document-delete Delete by id or by query. Deleting a published document leaves its draft behind — they are separate documents — so this can remove both in one transaction.
document-export Every document in a dataset as NDJSON — drafts included. A backup and migration tool, not a way to answer a question.
document-get Fetch one or more documents directly by id — cheaper than a query when the ids are known. Ask for `drafts.<id>` too if you want to see the unpublished edit.
document-history A document as it stood at a moment or a revision — the answer to 'what did this say before', within the plan's retention window.
document-patch Change part of a document, by id or by query. Operations run set → setIfMissing → unset → inc → dec → insert, whatever order you write them in.
document-publish Promote a draft to published through Sanity's Actions API — which owns the semantics, rather than hand-rolling a replace-plus-delete. The Studio's schema is not enforced here.
document-query Run a GROQ query. Remember that drafts are separate documents with a `drafts.` id prefix, so an unfiltered query returns each edited document twice.
document-unpublish Take a document off the published dataset, turning it back into a draft. The content survives and can be published again — unlike a delete.
project-list Projects this token can see, from the management API. A token that lists several is broader than a per-project token — worth knowing.
A workflow step names the app and the action, and the editor fills in the
connection when you pick one. This is the Step shape from the
workflow spec, carrying Sanity's real ids.
{
"manifestVersion": "2",
"name": "sanity-example",
"steps": [
{
"id": "document-create",
"uses": {
"app": "io.w6w.sanity",
"action": "document-create",
"connection": "conn_YOUR_CONNECTION_ID"
},
"with": {
"mode": "<mode>",
"document": "<document>"
}
}
]
}document-create dataset-list document-export document-get document-history +6 more actions available
Every app-specific value here is a blank you have to fill in. An
app action is reached through the connection that authenticates it, so the
address is a connection id, not the app id — and connections belong to your account,
so a public page cannot know yours. Create one for Sanity, then fill in
the three blanks: conn_YOUR_CONNECTION_ID, the action key, and the
parameters that action declares. The call itself is real — the shape is transcribed
from the studio's own snippet builder, which prints the same kind of blanks — but
nothing in it is specific to Sanity. The Workflow tab is where this app's
real ids are.
npm install @w6w/sdkyarn add @w6w/sdkpnpm add @w6w/sdkdeno add npm:@w6w/sdkimport { W6wClient, isActionRun } from "@w6w/sdk";
// Reads W6W_BASE_URL and W6W_TOKEN from the environment when omitted.
const client = new W6wClient();
const envelope = await client.run({
urn: "conn_YOUR_CONNECTION_ID",
action: "document-create",
payload: {
mode: "<value>",
document: "<value>",
// dryRun: "<value>",
// returnDocuments: "<value>",
// visibility: "<value>",
// transactionId: "<value>",
// dataset: "<value>",
},
});
if (isActionRun(envelope)) console.log(envelope.value); npm install -g @w6w/cli w6w run conn_YOUR_CONNECTION_ID --action document-create --payload '{"mode":"<value>","document":"<value>"}' Give an AI agent Sanity — without giving it Sanity's credentials. One MCP endpoint exposes every app, function and workflow the caller is entitled to, as tools it can discover and run. Access is granted per team while we onboard.
One tool call{
"name": "w6w_invoke",
"arguments": {
"ref": "app:io.w6w.sanity#document-create",
"input": {
"mode": "<mode>",
"document": "<document>"
}
}
}
Every tool names its target with a single ref. The
app: form above doesn't name a connection at all — the
host resolves which of the caller's Sanity connections to sign
with, and refuses rather than guesses when the answer is ambiguous.
The token is attached host-side, at the moment of the call. It is never a tool argument, never in the model's context, and never in a transcript — so a prompt injection has nothing to exfiltrate.
Tools are derived per end user from what that person has actually connected and is entitled to — not one shared bot identity carrying the union of everyone's access.
Multi-step work runs on the workflow engine and returns a run handle the agent can poll — retries, branching and state survive the conversation that started them.
Sanity's declared health checks are on the surface too, so an agent can tell "the vendor is down" from "your credential expired" before it burns a retry on either.
The MCP surface is part of the hosted platform. Sanity itself is MIT, and the runtime that executes it is source-available (FSL).
Sanity declares its own checks, so its health is a property of the app rather than something the host guesses at.
The Content Lake, API and CDN components — the ones this app's queries and mutations ride on. Studio and the management dashboard are excluded.
Runs an empty GROQ query against this connection's own project and dataset — the check that catches a wrong project id or a mistyped dataset, which no credential test can.