Sanity Library Reference Docs
    Preparing search index...

    Function createMcpSessionTelemetry

    • Create the Workflows telemetry for one MCP session.

      Events go to the first project the session binds to. They carry the package version, project id, and dataset, never tool arguments, results, or a user id.

      Nothing is sent when denied is true. Otherwise the account's consent is checked at the first send, retried if that check fails, and cached for the session. Sending never throws.

      Parameters

      Returns McpSessionTelemetry

      Assumes the host has clientForResource and telemetryEnabled, and that address and client belong to the current tool call.

      import {createMcpSessionTelemetry, createWorkflowEngine} from '@sanity/workflow-mcp'

      const telemetry = createMcpSessionTelemetry({
      clientFor: (resource) => clientForResource(resource),
      denied: !telemetryEnabled,
      })

      // For each tool call:
      telemetry.bind(address.workflowResource)
      const engine = createWorkflowEngine({address, client, telemetry: telemetry.logger})

      // When the session closes:
      await telemetry.flush()
      telemetry.end()