Workflows

Connect an agent over MCP

Install and authenticate the Workflows MCP server, register it with your agent, address a workflow environment, and see which tools change state.

Early access

@sanity/workflow-mcp is an MCP server that exposes your workflows as tools an agent can call. The agent can operate workflows (list what is deployed and running, inspect and diagnose an instance, start runs, and fire actions) and author new ones (read the DSL guide, validate a definition, and deploy it into a partition you name).

In this guide, you connect an MCP client such as Claude Code, Claude Desktop, or Cursor to the Workflows server, point the agent at the quick start's dev deployment, and watch it list the deployed workflows. Every tool, with its inputs and results, is in the Workflows MCP tools reference.

Before you start, you need:

  • The finished quick start: article-review deployed to the dev partition of your dataset.
  • Node.js 20 or later.
  • An MCP client.
  • An organization-level token with access to the quick start's dataset. Read access lets the agent inspect; starting runs, firing actions, and deploying need write access.

Install the server

The server runs over stdio, so your MCP client launches it; you do not start it yourself. Install it globally, with the engine from the same Workflows release, so clients can spawn the workflow-mcp binary.

npm install -g @sanity/workflow-mcp @sanity/workflow-engine

npm 7 and later and pnpm install peer dependencies automatically. If your package manager does not, also install @modelcontextprotocol/sdk and zod.

A client can also spawn the server without an install, with npx -y @sanity/workflow-mcp. That resolves the version each time the client boots the server, so a session can quietly pick up a new release; pinning a version in the command trades that for a pin that goes stale.

Register the server with your client

Register the server with the token in its environment. The server refuses to start without SANITY_AUTH_TOKEN, failing with Missing required environment variable: SANITY_AUTH_TOKEN. Claude Code registers it with one command; Claude Desktop, Cursor, and most other clients take the same shape as JSON.

claude mcp add sanity-workflows \
  --env SANITY_AUTH_TOKEN=YOUR_ORG_TOKEN \
  -- workflow-mcp

Replace YOUR_ORG_TOKEN with your token. The client stores it in its own config, so use a token you can revoke. Set SANITY_API_HOST in the same env block only to reach an API host other than https://api.sanity.io.

A GUI-launched client (Claude Desktop among them) may not inherit your shell PATH and then cannot resolve workflow-mcp. Register with the npx form instead, accepting that it resolves the version when the client boots the server: "command": "npx", "args": ["-y", "@sanity/workflow-mcp"].

The server authenticates at the organization level: the token says who acts, and each tool call says where. What the agent can actually read or change is decided by that token's access in the Content Lake, per call, so do not give the agent broader access than it needs. Workflow history records each action as the token's identity, which the engine resolves through /users/me, with the advisory execution context kind mcp and id workflow-mcp. The token cannot tell the person driving the agent apart from its own identity. See Actors and enforcement for execution contexts and triggered entries.

Target a workflow environment

The server has no default environment. Every tool that touches workflow data takes the address of one deployment: workflow_resource, its workflowResource written as <type>:<id>, and partition. For the quick start's dev deployment, that is:

{
  "workflow_resource": "dataset:PROJECT_ID.DATASET_NAME",
  "partition": "dev"
}

Tell the agent which workflow resource to use. Let it call workflows_list_partitions, which takes only workflow_resource, confirm the partition with you, and then pass the complete address to every other tool. A deployment that omits partition in sanity.workflow.ts uses default. One server can work across all your deployments. The address reference lists the formats and errors.

Verify the connection

Restart your client so it picks up the registration. In Claude Code, claude mcp list shows sanity-workflows as connected. Then ask the agent:

List the workflow partitions in dataset:PROJECT_ID.DATASET_NAME, then list the workflow definitions deployed in the dev partition.

The agent calls workflows_list_partitions and then workflows_list_definitions. Expect results like these:

{"partitions": ["dev"]}

If a call fails with Missing required environment variable, the client did not pass the token. If the partition list is empty, the token cannot read that dataset or nothing is deployed there.

Know what the agent can change

The agent can survey, inspect, and diagnose freely. It changes state through exactly three tools:

  • Call workflows_start to start a run.
  • Use workflows_fire_action to advance an instance after reading its current state.
  • Call workflows_deploy_definition to deploy a workflow definition.

The Content Lake is the boundary. The checks the tools make (disabled actions, guard verdicts, and validation) are advisory conveniences for the agent. Enforcement is dataset access control (custom roles) evaluated against the server’s token and parameters. A token that can’t write in an environment can’t fire actions or deploy into it.

Before letting the agent call workflows_deploy_definition for a definition that needs a newer reader model, follow Upgrade Workflows packages and pass the reviewed expectedMinReaderModel; omitted, the tool acknowledges the baseline model 4. The required model depends on the definition's features, not the package version.

Turn off telemetry

The server sends adoption telemetry that follows your account's telemetry consent. Each tool call logs one "Workflows MCP Tool Called" event with the tool name, a success flag, and whether a list cursor was used, never arguments, cursor values, or results. Set DO_NOT_TRACK=1 in the server's env to opt out.

Embed the tools in another MCP server

To add the Workflows tools to an MCP server you already run, register them with registerWorkflowTools. Your host keeps authentication and transport (tokenFor and baseClientConfigFor here), and the package supplies the client policy and engine for each addressed call.

import {createClient, type ClientConfig} from '@sanity/client'
import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'
import {
  createWorkflowEngine,
  registerWorkflowTools,
  type WorkflowToolExtra,
  workflowAddressFromInput,
  workflowClientConfig,
} from '@sanity/workflow-mcp'

declare function tokenFor(extra: WorkflowToolExtra): string
declare function baseClientConfigFor(extra: WorkflowToolExtra): ClientConfig

const server = new McpServer({name: 'my-host', version: '1.0.0'})

registerWorkflowTools(server, (extra, input) => {
  const address = workflowAddressFromInput(input)
  const client = createClient(
    workflowClientConfig({
      resource: address.workflowResource,
      token: tokenFor(extra),
      base: baseClientConfigFor(extra),
    }),
  )

  return {engine: createWorkflowEngine({address, client})}
})

The Embedding API documents every export: client policy, telemetry, custom registration with WORKFLOW_TOOLS and toolInputJsonSchema, error rendering, and the partition-discovery constants.

Next steps

Was this page helpful?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme