Skip to main content
Each recipe in this cookbook covers one job you can do in Confidence by prompting an AI assistant that has the Confidence MCP servers connected. A recipe gives you a prompt to copy, the tools the assistant calls, and a way to check the result.
The Confidence MCP servers are experimental. Tools and their parameters can change.

Before You Start

  • Connect the servers that a recipe needs. See MCP Servers.
  • Replace the example names in each prompt, such as new-checkout-flow or web-client, with your own.
  • The assistant chooses which tools to call. The tool calls listed in each recipe are the typical sequence, not a fixed script.
  • Review what the assistant proposes before it changes a flag, rule, or warehouse.
To create or launch an experiment, use the in-app Confidence Agent instead. The MCP servers can only read experiments. See Work with the Confidence Agent.

Set Up a Client and a Flag with Targeting

Goal: Create a client and a flag, and serve a variant to users in one country. Server: Flags Prompt:
What the assistant does:
  1. listClients to check whether web-client already exists.
  2. createClient with displayName and clientType (Frontend or Backend).
  3. getContextSchema to confirm that a country field exists. If not, addContextField adds it.
  4. createFlag with flagName, clientName, schemaObject, and variants.
  5. addTargetingRule with variantAllocations that sum to 100 and a payload with the country condition.
Check the result: Ask the assistant to run getFlag with summary=false and confirm that the rule and its split appear. Then follow the next recipe to resolve the flag for a test user.

Force a Variant for a Test User

Goal: Make one user always get a specific variant, and confirm that they do. Server: Flags Prompt:
What the assistant does:
  1. getContextSchema to find the entity field to use, such as user_id.
  2. addOverrideRule with flagName, entity, entityValue, and variantName.
  3. resolveFlag with flagName, clientName, entity, and entityValue.
Check the result: The resolveFlag output explains each evaluation step. Confirm that the override rule matched and that the variant is on. To turn the override off later, ask the assistant to call updateOverrideRule with enabled set to false, or deleteRule to remove it.

Roll a Flag Out to a Percentage

Goal: Turn a feature on for a share of matching users, and increase that share later. Server: Flags Prompt:
What the assistant does:
  1. getFlag to read the flag’s variants and existing rules.
  2. addTargetingRule with variantAllocations set to {"on": 100} and rolloutPercentage set to 25. Users outside the 25% fall through to the next rule.
  3. To change the percentage later, deleteRule removes the rule and addTargetingRule adds it again with the new rolloutPercentage. updateTargetingRule changes a rule’s targeting, variant split, or enabled state, but not its rollout percentage.
Check the result: Run getFlag with summary=false to see the rollout percentage on the rule. Resolve the flag for a few users with resolveFlag to see which ones enter the rule. To measure the impact of a rollout, create it as a rollout in Confidence instead. See Roll Out a Change.

Define an Event and Build a Metric on It

Goal: Register a custom event, confirm that it arrives, and create a metric from it. Server: Flags Prompt:
What the assistant does:
  1. createEventDefinition with eventDefinitionId and schema.
  2. You send events from your application with the SDK track() method. See Send Product Events.
  3. queryEventsUsage with eventDefinitionName and daysBack to show hourly publish and validation failure counts.
  4. listFactTables to find the fact table that Confidence creates when events start arriving.
  5. listEntities to find the entity, such as users.
  6. createMetric with displayName, entity, factTable, and a typeSpec such as {"averageMetricSpec":{"measurement":"order_value","aggregation":"SUM"}}.
Check the result: queryEventsUsage shows publish counts above zero and no validation failures. getMetric returns the new metric. To see values, follow the next recipe.

Calculate a Metric over a Time Window

Goal: Compute a metric over historical data in your warehouse. Server: Flags Prompt:
What the assistant does:
  1. checkWarehouseExists. Metric calculations require a warehouse. If none exists, follow Connect a Warehouse.
  2. listMetrics and listExposureTables to find the metric and exposure table names.
  3. createMetricCalculation with metric, exposureTable, startTime, and endTime.
  4. getMetricCalculation until the state is STATE_COMPLETED.
  5. queryMetricCalculation with groupByDimensions and accumulateDimension set to cohort_date for a time series.
Check the result: The assistant reports count, mean, variance, and sum per dimension. If the state is STATE_FAILED, ask the assistant to show the calculation details from getMetricCalculation.

Check an Experiment’s Results

Goal: Find an experiment and read its results. Server: Experiments Prompt:
What the assistant does:
  1. list_experiments with query set to checkout, or with a filter for state.
  2. get_experiment with experimentName to read the metrics, decision, and analysis result names.
  3. get_results with analysisResultName to read effect estimates, confidence intervals, and status messages.
  4. get_resource to look up any metric or segment that the results reference.
Check the result: Compare the summary with the experiment’s results page in Confidence. Set summary=false on get_results for the full output.

Clean Up Unused Flags

Goal: Find flags on a client that nothing uses or that are at full rollout, and archive the ones you no longer need. Server: Flags Prompt:
What the assistant does:
  1. analyzeFlagUsage with clientName.
  2. getFlagHistory with flagName, fromDate, and toDate for each candidate.
  3. After you confirm, archiveFlag with flagName for each flag.
Check the result: listFlags with state set to ARCHIVED lists the archived flags. An archived flag no longer resolves, so remove its code paths first. To restore a flag, ask the assistant to call unarchiveFlag.

Connect a Warehouse

Goal: Connect your data warehouse so Confidence can write assignments and events and calculate metrics. Server: Flags Prompt:
What the assistant does:
  1. checkWarehouseExists to confirm that the account has no warehouse yet.
  2. validateWarehouseConfig with warehouseType and configJson to check access to datasets, schemas, and roles.
  3. createWarehouse with warehouseType and configJson.
  4. createFlagAppliedConnection to export flag resolve events.
  5. createEventConnection to export custom events.
For Snowflake key-pair authentication, the assistant first calls createCryptoKey. You then register the public key in Snowflake. Check the result: checkWarehouseExists reports a warehouse. After flags resolve, listExposureTables lists exposure tables.

Record a Sample of Sessions

Goal: Record a sample of sessions for one client. Server: Flags Prompt:
What the assistant does:
  1. createRecordingPolicy with displayName and clientName.
  2. addRecordingRule with recordingPolicy, displayName, stableAudiencePercentage set to 50, sessionSampleRate set to 0.1 (a probability from 0 to 1), and environments as a JSON array of environment resource names. Rules are drafts by default.
  3. setRecordingRuleEnabled with recordingRule and enabled set to true.
Check the result: getRecordingPolicy returns the policy with its rules in evaluation order. See Set Up Session Recordings for the SDK setup.

Get SDK Integration Code

Goal: Get code to add Confidence flags to your application in your language. Server: Docs and SDK guides Prompt:
What the assistant does:
  1. getCodeSnippetAndSdkIntegrationTips with sdk, for example python. Supported values are java, kotlin, javascript, typescript, python, swift, go, and react.
  2. For local resolve in a backend service, getLocalResolveIntegrationGuide with sdk.
  3. searchDocumentation or grepDocumentation for related details.
Check the result: Run the code and resolve the flag. Then use resolveFlag on the Flags server to compare the variant with what your application receives.