Skip to main content
RapidDev - Software Development Agency
retool-integrationsDevelopment Workflow

How to Integrate Retool with Mercurial

Use Mercurial with Retool by integrating the Retool CLI into your Mercurial-based version control workflow. Export Retool app definitions as JSON files, commit them to your Mercurial repository, and use hg push/pull to promote app versions between environments. This workflow enables teams using Mercurial infrastructure to apply the same code review and release management practices to Retool apps that they use for application code.

What you'll learn

  • How to install and configure the Retool CLI for exporting and importing app definitions
  • How to structure a Mercurial repository to version-control Retool app definitions
  • How to use Mercurial branches to manage Retool app versions across staging and production environments
  • How to use hg hooks to automate Retool app deployment on branch changes
  • How the Mercurial workflow differs from the Git-based Retool workflow and how to adapt team processes
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate16 min read25 minutesDevOpsLast updated April 2026RapidDev Engineering Team
TL;DR

Use Mercurial with Retool by integrating the Retool CLI into your Mercurial-based version control workflow. Export Retool app definitions as JSON files, commit them to your Mercurial repository, and use hg push/pull to promote app versions between environments. This workflow enables teams using Mercurial infrastructure to apply the same code review and release management practices to Retool apps that they use for application code.

Quick facts about this guide
FactValue
ToolMercurial
CategoryDevOps
MethodDevelopment Workflow
DifficultyIntermediate
Time required25 minutes
Last updatedApril 2026

Why Use Mercurial with Retool?

Many enterprise teams — particularly those with roots in large-scale software development at companies like Facebook, Google, and Mozilla — operate Mercurial as their primary version control system. These teams have established code review pipelines, CI/CD tooling, and governance processes built around Mercurial, and they want to apply the same rigor to Retool internal tools that they apply to application code. Rather than adopting a parallel Git-based workflow for Retool, they extend their existing Mercurial infrastructure.

The core challenge is that Retool's native tooling (the Retool CLI and official documentation) assumes Git as the version control system. However, the Retool CLI's app export functionality is VCS-agnostic: it exports app definitions as JSON files to a local directory, and those files can be committed to any version control system. Teams using Mercurial simply replace git add/commit/push with hg add/commit/push in their workflow, and replace Git branching concepts with Mercurial's named branches or bookmarks.

A properly configured Mercurial workflow for Retool enables full code review of app definition changes before they reach production, rollback to any previous app version by importing an older commit's JSON export, environment parity between staging and production Retool instances, and audit trails of who changed which Retool apps and when — meeting compliance requirements that the Retool UI alone cannot satisfy.

Integration method

Development Workflow

Retool integrates with Mercurial through a development workflow that uses the Retool CLI to export app definitions as versioned JSON files, which are then managed in a Mercurial repository. Teams commit Retool app JSON exports after each significant change, use Mercurial branches for staging and production environments, and promote app versions by merging branches — applying the same VCS discipline to Retool apps as to application code. The Retool CLI handles the import and export of app definitions independently of which version control system stores them.

Prerequisites

  • A Retool account (Cloud or self-hosted, Business plan or higher) with admin access to use the Retool CLI
  • Mercurial installed and configured on your development workstations and CI/CD servers (hg version to confirm)
  • The Retool CLI installed: npm install -g retool-cli — confirm with retool --version
  • A Retool API token generated from Retool Settings → Retool API → Create API token (used to authenticate the Retool CLI)
  • A Mercurial repository already initialized and accessible to your team, either hosted (Bitbucket with Mercurial, or a self-hosted Heptapod instance) or local

Step-by-step guide

1

Install the Retool CLI and authenticate against your Retool instance

The Retool CLI is the core tool for exporting and importing Retool app definitions from the command line. Install it globally using npm, then configure it to connect to your Retool instance. Run: npm install -g retool-cli After installation, configure the CLI to connect to your Retool instance. Generate a Retool API token from Retool Settings → Retool API → Create API token. Copy the token — you will use it to authenticate the CLI. Set up the CLI configuration by running: retool login --host https://your-retool-instance.com --token YOUR_API_TOKEN For Retool Cloud, the host is typically https://yourcompany.retool.com. For self-hosted Retool, use your internal Retool URL. Verify authentication by running: retool apps list — this should display a list of apps in your Retool instance. If it returns an error, check that the API token is correct and that the Retool instance URL does not have a trailing slash. Note that the Retool CLI's app definition export format is JSON. Each exported app creates a single .json file containing the complete app definition including all components, queries, and resource references. The file name typically matches the app's display name with spaces replaced by hyphens or underscores. These JSON files are what you will track in your Mercurial repository.

Pro tip: Store the Retool API token as an environment variable (RETOOL_API_TOKEN) rather than passing it as a CLI flag. Set this variable in your shell profile for local development and as a CI secret variable for automated workflows. The CLI will pick up RETOOL_API_TOKEN automatically if the environment variable is set.

Expected result: The Retool CLI is installed and authenticated. Running 'retool apps list' displays your Retool apps. You have confirmed that the CLI can communicate with your Retool instance using the API token.

2

Set up the Mercurial repository structure for Retool app definitions

Establish a consistent directory structure in your Mercurial repository for Retool app definitions. A recommended structure separates app definitions by Retool environment (development, staging, production) or by team/function, depending on your organization's structure. If you are adding Retool app definitions to an existing monorepo, create a new directory at the repository root: retool-apps/ with subdirectories for each environment or team. If Retool apps will be the primary content of the repository, initialize a dedicated repository with the root as the app storage location. Create a directory structure such as: retool-apps/ apps/ — exported Retool app JSON files resources/ — documentation of resource configurations (NOT credentials) README.md — instructions for the export/import workflow Add a .hgignore file at the repository root to exclude any temporary files generated by the Retool CLI: syntax: glob *.tmp .retool-cache/ Create the initial commit with the directory structure: hg add retool-apps/ && hg commit -m 'chore: initialize Retool apps directory structure' For environment branching, create named branches for staging and production: hg branch staging && hg commit -m 'chore: create staging branch' then switch back to default (development) as the primary working branch. This three-branch structure mirrors common Mercurial promotion workflows used in enterprise environments.

.hgignore
1# .hgignore file for Retool app repository
2syntax: glob
3
4# Retool CLI cache files
5.retool-cache/
6*.retool.tmp
7
8# Editor temp files
9*.swp
10*.swo
11.DS_Store
12Thumbs.db
13
14# Node modules if any tooling is co-located
15node_modules/

Pro tip: In Mercurial, named branches are permanent and immutable once committed — a 'develop' branch will always exist in the repository history. If you prefer more lightweight branch management similar to Git's feature branches, use Mercurial bookmarks instead of named branches. Bookmarks are movable pointers that behave more like Git branches and are the preferred branching mechanism in modern Mercurial workflows.

Expected result: Your Mercurial repository has a retool-apps/apps/ directory structure with an initial commit. Named branches for staging and production exist. A .hgignore file excludes CLI cache files. The repository is in a clean state ready to receive app definition exports.

3

Export Retool app definitions and commit them to Mercurial

With the CLI configured and the repository structured, establish the workflow for exporting app definitions and committing them to Mercurial after making changes in the Retool editor. After making changes to a Retool app in the browser editor, export the updated definition using the Retool CLI: retool apps export --app 'App Name' --output ./retool-apps/apps/app-name.json Verify the export by reviewing the generated JSON file. The file contains the full app definition — component tree, query configurations, transformers, event handlers, and layout information. Do not edit this file manually; always edit through the Retool editor and re-export. Check the Mercurial status to see what changed: hg status — the modified .json file appears as 'M' for modified (if it existed before) or '?' for a new untracked file. Stage and commit the change: hg add retool-apps/apps/app-name.json (only needed for new files) hg commit -m 'feat: add user search filter to Customer Support Panel' Write commit messages using conventional commit format (feat:, fix:, chore:) so the history is human-readable and integrates with any automated changelog generation in your CI pipeline. For teams exporting multiple apps simultaneously, the Retool CLI supports exporting all apps at once: retool apps export --all --output ./retool-apps/apps/ — this creates or updates a JSON file for each app. Review hg diff after this export to confirm only the intended apps changed before committing.

export-and-commit.sh
1# Shell script for consistent Retool app export and commit
2# Save as retool-apps/export-and-commit.sh
3#!/bin/sh
4
5APP_NAME="$1"
6COMMIT_MSG="$2"
7
8if [ -z "$APP_NAME" ] || [ -z "$COMMIT_MSG" ]; then
9 echo "Usage: ./export-and-commit.sh 'App Name' 'commit message'"
10 exit 1
11fi
12
13# Convert app name to filename (lowercase, spaces to hyphens)
14FILENAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
15
16# Export the app
17retool apps export --app "$APP_NAME" --output "./apps/${FILENAME}.json"
18
19if [ $? -ne 0 ]; then
20 echo "Export failed — check Retool CLI authentication"
21 exit 1
22fi
23
24# Stage and commit
25hg add "./apps/${FILENAME}.json" 2>/dev/null || true
26hg commit -m "$COMMIT_MSG"
27echo "Exported and committed: $APP_NAME"

Pro tip: After exporting a Retool app, always run 'hg diff retool-apps/apps/app-name.json' before committing to review the actual changes to the JSON definition. This confirms you are committing the expected changes and not accidentally including unrelated modifications from other app edits you may have made during the same Retool session.

Expected result: Mercurial history shows commit entries for each Retool app change, with meaningful commit messages. Running 'hg log retool-apps/apps/customer-support-panel.json' shows the full revision history for that specific app.

4

Promote app changes between environments using Mercurial branches

Establish the promotion workflow that moves Retool app definitions from development to staging to production using Mercurial named branches (or bookmarks). This mirrors the application deployment process your team already uses for code. The workflow: 1. Developer makes changes in the development Retool instance, exports the app definition, commits to the 'default' branch in Mercurial. 2. Code review is conducted on the JSON diff. Reviewers examine what component properties, queries, or layouts changed. 3. After approval, merge the change to the 'staging' branch: hg update staging && hg merge default && hg commit -m 'chore: promote customer-support-panel to staging' 4. The Retool CLI imports the staging branch version into the staging Retool instance: retool apps import --file ./apps/customer-support-panel.json --instance https://staging.retool.yourdomain.com 5. QA validation on the staging Retool instance. 6. If staging looks good, merge to 'production' branch and import into the production Retool instance. For the import step to work on multiple Retool instances, configure separate Retool CLI profiles for each environment, each with its own API token. Use environment variables to switch between profiles: RETOOL_API_TOKEN=staging_token retool apps import ... For complex multi-environment deployments with many apps, RapidDev can help architect a more robust Retool app lifecycle management solution that integrates with your existing Mercurial-based CI/CD infrastructure.

deploy-to-staging.sh
1# hg hook configuration for automated Retool import on branch promotion
2# Add to your .hg/hgrc file on the CI server
3
4[hooks]
5# Trigger after a push to the staging branch
6changegroup.retool-staging = python:hooks/retool_deploy.py:deploy_staging
7
8# Or use a simpler shell hook:
9# changegroup.retool-staging = sh hooks/deploy-to-staging.sh
10
11---
12# hooks/deploy-to-staging.sh
13#!/bin/sh
14BRANCH=$(hg branch)
15if [ "$BRANCH" = "staging" ]; then
16 echo "Deploying Retool apps to staging instance..."
17 RETOOL_API_TOKEN=$RETOOL_STAGING_TOKEN \
18 retool apps import --all --directory ./apps/ \
19 --instance https://staging.retool.yourdomain.com
20fi

Pro tip: Mercurial's 'named branches' are embedded in commit metadata and persist forever in repository history. If your team prefers a cleaner branch lifecycle, use Mercurial bookmarks for feature branches and reserve named branches only for long-lived environment branches (staging, production). Bookmarks can be deleted after merging, keeping the branch namespace clean.

Expected result: App changes flow through the Mercurial branch structure from default to staging to production. Each promotion creates an explicit Mercurial merge commit. The hg log for any app file shows its full promotion history across environments.

5

Roll back a Retool app to a previous version using Mercurial history

One of the key benefits of version-controlling Retool app definitions is the ability to roll back to any previous version using Mercurial's revision history. This is particularly valuable when a Retool app change causes an incident and needs to be reverted immediately. To roll back a specific app to a previous version: 1. Identify the target revision: hg log -l 20 retool-apps/apps/broken-app.json — look for the last known-good commit hash or revision number in the output. 2. Extract the app definition from that revision: hg cat -r {revision_number} retool-apps/apps/broken-app.json > /tmp/rollback-app.json 3. Import the extracted definition into the Retool instance: retool apps import --file /tmp/rollback-app.json 4. Verify the rollback worked by checking the app in the Retool browser interface. 5. Commit the rollback in Mercurial: hg revert -r {target_revision} retool-apps/apps/broken-app.json && hg commit -m 'fix: roll back broken-app to revision {revision_number} (revert breaking change from {bad_revision})' Note that in Mercurial, unlike Git, you should NOT rewrite history using hg strip or hg amend on branches that have been pushed to a shared repository. Instead, always create a new forward commit that reverts the broken change — this preserves the full history including the failed attempt, which is valuable for post-incident review. Document this rollback procedure in your team's runbook alongside application rollback procedures so on-call engineers know the exact steps without needing to research them during an incident.

rollback-app.sh
1#!/bin/sh
2# Retool app rollback script using Mercurial history
3# Usage: ./rollback-app.sh 'app-filename.json' {target_revision}
4
5APP_FILE="$1"
6TARGET_REV="$2"
7
8if [ -z "$APP_FILE" ] || [ -z "$TARGET_REV" ]; then
9 echo "Usage: ./rollback-app.sh apps/app-name.json {revision_number}"
10 echo "Run 'hg log -l 20 apps/app-name.json' to find target revision"
11 exit 1
12fi
13
14# Extract the app definition from the target revision
15hg cat -r $TARGET_REV $APP_FILE > /tmp/retool-rollback.json
16
17if [ $? -ne 0 ]; then
18 echo "Failed to extract revision $TARGET_REV from Mercurial"
19 exit 1
20fi
21
22# Import into Retool (uses RETOOL_API_TOKEN from environment)
23retool apps import --file /tmp/retool-rollback.json
24
25# Commit the rollback in Mercurial
26hg revert -r $TARGET_REV $APP_FILE
27hg commit -m "fix: rollback $APP_FILE to revision $TARGET_REV"
28
29echo "Rollback complete. App has been restored to revision $TARGET_REV."

Pro tip: Keep a note of Mercurial revision numbers (not just hashes) for recent production deployments in a team wiki or deployment log. During an incident, quickly identifying 'we want to go back to the version from Friday's deploy at revision 1042' is faster than searching hg log output under pressure.

Expected result: The rollback script successfully extracts the app definition from a previous Mercurial revision and imports it into the Retool instance. The Mercurial log shows a clean rollback commit that documents why the revert was made and which revision was restored.

Common use cases

Establish a code-reviewed Retool app promotion workflow using Mercurial branches

Structure your Retool apps in a Mercurial repository with named branches for each environment (default for development, staging, production). Developers export app definitions to the development branch after making changes in the Retool editor, open a code review for the JSON diff, and merge to staging for testing — then production after approval. Mercurial's named branches provide a stable promotion path with full audit history.

Retool Prompt

Set up a Mercurial repository structure with three named branches (develop, staging, production) for Retool app definitions. Configure the Retool CLI to export all apps to the apps/ directory. Define an hg hook that triggers the Retool CLI import command when changes are merged to the staging or production branch, automatically updating the Retool instance for that environment.

Copy this prompt to try it in Retool

Version-control Retool app definitions alongside backend API code

Store Retool app definitions in the same Mercurial monorepo as the backend services they front-end. When a developer changes a backend API response format, they update both the backend code and the Retool app definition in the same Mercurial commit or review. This keeps the frontend tool in sync with the backend and makes it obvious which Retool app version works with which API version.

Retool Prompt

Add a retool-apps/ directory to an existing Mercurial monorepo alongside the backend service directories. Use the Retool CLI to export the relevant app definitions into this directory after each UI change. Include retool-apps/ in code review alongside the backend changes it accompanies, so reviewers see the full scope of changes — backend logic and the Retool interface — together.

Copy this prompt to try it in Retool

Implement rollback capability for Retool apps using Mercurial history

Use Mercurial's revision history as a rollback mechanism for Retool apps. When a Retool app change causes issues in production, identify the last known-good revision using hg log, extract the app definition JSON from that revision, and use the Retool CLI to import it back into the Retool instance. This provides the same rollback capability for internal tools that teams use for application deployments.

Retool Prompt

Create a runbook for Retool app rollbacks using Mercurial: identify the last good revision with 'hg log -l 10 apps/', use 'hg cat -r {revision} apps/{appname}.json' to extract the old definition, and import it with the Retool CLI's import command. Document this procedure in your team's incident response playbook so on-call engineers can roll back Retool apps without Retool admin access.

Copy this prompt to try it in Retool

Troubleshooting

Retool CLI returns 'Unauthorized' error when running retool apps list or export commands

Cause: The RETOOL_API_TOKEN environment variable is not set, has expired, or the token was generated for a different Retool instance than the one configured in the CLI. API tokens in Retool are tied to a specific instance and user account.

Solution: Verify the RETOOL_API_TOKEN is set in the current shell session (echo $RETOOL_API_TOKEN). Generate a fresh API token from Retool Settings → Retool API → Create API token. Re-run retool login with the new token and the correct instance URL. Confirm the instance URL does not have a trailing slash and matches exactly how your Retool instance is accessed.

Mercurial shows the Retool app JSON as unchanged (hg status shows nothing) after making edits in the Retool browser editor

Cause: The Retool CLI export command was not run after making browser edits. Retool app changes made in the browser editor are not automatically reflected in the exported JSON file — the export command must be run manually after each set of changes.

Solution: Run the Retool CLI export command explicitly after making browser edits: retool apps export --app 'App Name' --output ./apps/app-name.json. Then check hg status again. Build this export step into your team's workflow as a checklist item before any Mercurial commit, or create a git-hook-equivalent hg pre-commit hook that reminds developers to export before committing.

Importing a Retool app from Mercurial history into a different Retool instance fails with 'Resource not found' errors

Cause: The exported app definition references Resources (database connections, REST API resources) by name, and those resource names do not exist in the target Retool instance. Resource names must match exactly between instances for an imported app to function correctly.

Solution: Before promoting app definitions between environments, ensure that all Resources referenced by the app exist with identical names in the target Retool instance. Maintain a resources documentation file in the Mercurial repository (do not store credentials, only resource names and types) so environment setup is reproducible. Use Retool's environment variable feature to handle differences in connection strings between instances while keeping resource names identical.

Best practices

  • Export Retool app definitions to Mercurial immediately after making and testing browser editor changes — don't let the Mercurial history diverge from the actual app state by accumulating multiple untracked changes.
  • Write meaningful Mercurial commit messages for Retool app exports using conventional commit format: 'feat: add date range filter to Sales Dashboard' is more useful than 'update app JSON'.
  • Never edit Retool app definition JSON files directly in a text editor — always make changes in the Retool browser editor and re-export. Manual JSON edits can introduce syntax errors that break the import.
  • Use Mercurial bookmarks instead of named branches for feature-level changes to Retool apps — bookmarks are lightweight and can be deleted after merging, keeping the branch history clean.
  • Store Retool API tokens as environment variables or CI secrets, never in the Mercurial repository — even in ignored files, treat credentials as sensitive and keep them out of version control entirely.
  • Maintain a separate Retool instance for staging that mirrors the production instance's Resource configuration — this ensures that promoted app definitions work identically in production without 'works in staging' surprises.
  • Run 'hg diff' on exported app JSON files before committing to review what actually changed in the app definition — this catches unintended changes from other Retool session edits that should not be included in the commit.

Alternatives

Frequently asked questions

Is Mercurial officially supported by Retool's version control tooling?

Retool's official documentation and CLI tooling assume Git as the version control system. There is no native Mercurial integration built into Retool's product. The Mercurial workflow described here is a manual adaptation: the Retool CLI exports and imports VCS-agnostic JSON files, and Mercurial stores those files. Teams using Mercurial need to adapt Git-centric Retool documentation to Mercurial equivalents (hg commit instead of git commit, hg merge instead of git merge, etc.).

Can I use Bitbucket with Mercurial for Retool app definitions?

Bitbucket removed Mercurial support in June 2020 — only Git repositories are supported on Bitbucket. Teams still using Mercurial typically host repositories on Heptapod (GitLab fork with Mercurial support), self-hosted Mercurial servers, or RhodeCode. If you are using Bitbucket and have migrated to Git, the Git-based Retool workflow applies directly. If you are on a Mercurial hosting platform that supports webhooks, you can trigger Retool CLI import commands via webhook on push events.

How do Mercurial's named branches differ from Git branches in the context of a Retool promotion workflow?

Mercurial named branches are embedded in commit metadata and are permanent — a branch name like 'staging' will always exist in the repository history. Git branches are mutable pointers that can be deleted. For Retool app promotion, this means Mercurial's named branches work well for long-lived environment branches (default, staging, production) but are heavyweight for short-lived feature branches. Use Mercurial bookmarks for feature-level Retool app work — they behave more like Git branches and can be deleted after merging.

What happens to Retool queries and resource references when importing an app definition exported from a different environment?

Retool app definitions reference Resources by name — not by connection string or credentials. When you import a definition exported from the development environment into production, Retool resolves resource references against the production instance's configured Resources. If production has a resource named 'Production PostgreSQL' but the app references 'Dev PostgreSQL', the import will succeed but queries using 'Dev PostgreSQL' will fail at runtime. Maintain identical Resource names across all Retool environments to avoid this issue.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Integrations are where projects stall

We wire Retool integrations like this one every week — auth, webhooks, edge cases included. Fixed-price builds from $13K, delivered in 6–10 weeks.

Talk to an integration engineer

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.