Sanity
Run bounded GROQ reads and create, patch, or delete documents in one Sanity dataset
Connect Sanity when a project needs structured content from one Content Lake dataset. The AI can query the existing documents and perform explicit mutations without exposing a token to generated client code.
Sanity supports a shared project connection. Every published app user acts through the same configured project, dataset, and token.
Availability
A Swarmz administrator must show Sanity under Platform config > Integrations. Sanity does not need a Swarmz OAuth app. The workspace supplies a project token.
Before you connect
Create a dedicated robot token in the Sanity project under Settings > API > Tokens. Choose a viewer role for read-only projects or an editor/custom role for document mutations. Sanity recommends a dedicated token with appropriate permissions for third-party services.
You also need the Sanity Project ID and Dataset name. The connection is pinned to that pair; a prompt cannot redirect it to another Sanity project.
Connect Sanity
- In the project, open Settings > Integrations and select Sanity.
- Select Add connection.
- Enter the Project ID and Dataset.
- Paste the robot token into API key, then select Save connection.
Swarmz validates the token with a bounded query against that dataset. The encrypted token remains behind the connector gateway.
Available operations
| Operation | What it does | Limit per minute |
|---|---|---|
query_documents | Runs a read-only GROQ query and returns at most 50 results | 30 |
get_document | Gets one document by exact ID | 30 |
create_document | Creates one document with an explicit _type | 10 |
patch_document | Sets, initializes, or unsets named fields | 10 |
delete_document | Deletes one document by exact ID | 10 |
Queries may use published or drafts perspective. Mutations accept fixed document, patch, or delete shapes; the connector does not accept arbitrary transaction bodies.
Ask the AI to use Sanity
- “Build a searchable article page from our Sanity
postdocuments. Return no more than 20 results.” - “Create a draft
releaseNotedocument with this title and body.” - “Add a moderation screen that patches only
statusandreviewedAt.” - “Delete the test document with this exact ID after I approve the write.”
For a live site, ask the AI to generate server code that queries Sanity through the connector gateway. Do not ask it to put the Sanity token in a public environment variable or browser bundle.
Use a Sanity MCP server in personal AI chat
If your Sanity setup exposes a compatible Streamable HTTP MCP server, add its HTTPS URL under Personal AI connectors. This is separate from the robot token above and remains personal build context. Swarmz discovers the server's live tools and asks before running tools that are not marked read-only. See Custom MCP server.
Verify Sanity
- Run
*[0...1]or ask for one known document type. - Get a known document by ID and compare its fields in Sanity Studio.
- In a test dataset, create a document with a unique
_idand_type. - Patch one field, read the document again, then delete it.
- Confirm the document no longer appears in the test dataset.
Troubleshoot and recover
If setup reports Sanity dataset configuration rejected, confirm the project ID, dataset spelling, and token membership. Dataset names are case-sensitive.
If reads work but mutations fail, replace the viewer token with an editor or custom-role token that grants only the required document permissions. Re-run the original read before attempting the write again.
To rotate a token, create a new Sanity token, edit the connection, and select Save changes. Verify a query, then delete the old token in Sanity. Select Remove in Swarmz to disconnect the project.