All Tonic.ai guides
Category

How to use Structural data and Claude Code for test automation

Yuliia Korabelska is a Senior Software Engineer at Tonic.ai, passionate about AI and synthetic data. She enjoys exploring both programming languages and human languages, and brings a curious, growth-driven mindset to everything she builds. Born in Ukraine, she carries her cultural roots into her work with pride and perspective.
Author
Yuliia Korabelska
December 12, 2025

Creating comprehensive automated tests is often hindered by two major challenges:

  • Obtaining realistic test data that mirrors production environments without exposing sensitive information.
  • Manually crafting test cases that cover the diverse scenarios present in real-world data.

Traditional approaches require developers to either use granular subsets of production data, which risks privacy violations, or to generate synthetic data, which doesn't always capture the complexity and edge cases of actual usage patterns.

By combining Tonic Structural's de-identification capabilities with Claude Code's AI-powered development workflow, teams can overcome both obstacles simultaneously.

Structural creates a fully de-identified database that preserves the statistical properties and realistic patterns of production data.

Claude Code can then query this safe dataset directly through MCP (Model Context Protocol) connections to automatically generate test cases that are based on the actual data distributions, relationships, and edge cases present in your system—eliminating guesswork and dramatically accelerating test automation development.

In this guide, we’ll show you how to set up a connection from Claude Code to MCP, and then provide an example of defining an automated test that uses that connection to query and analyze Structural output data.

Set up the Claude Code connection to MCP

Prerequisites

Before you begin, make sure that you have Claude Code installed on your system.

Step 1: Install the PostgreSQL MCP Server

You'll need to install the open-source postgres-mcp (or mcp-server-mysql for MySQL) server.

To pull the Docker image: run:

docker pull crystaldba/postgres-mcp

Step 2: Add postgres-mcp to your project

In your project directory, to add the postgres-mcp server, run the following command.

claude mcp add postgres-mcp --env 
"DATABASE_URI=postgresql://your_user:password@host:5432/database_name" 
-- docker run -i --rm -e DATABASE_URI crystaldba/postgres-mcp 
--access-mode=restricted

This adds an MCP server for the specific project.

In the command:

  • Replace your_user, password, host, port, and database_name with your actual database connection details to a Tonic Structural destination database.
  • For —access-mode, choose either restricted or unrestricted:
    • --access-mode=restricted - Read-only mode (recommended for safety)
    • --access-mode=unrestricted - Allows Claude to make changes to the database

Step 3: Verify the connection

To check that postgres-mcp is properly connected: run:

claude mcp list

You should see postgres-mcp with a ✓ Connected status.

Step 4: Configure Claude instructions

Create a CLAUDE.md file in your project directory.

Edit your CLAUDE.md file to include instructions for Claude on how to use the MCP.

Here's an example configuration:

## Adding new Tests

- Use postgres-mcp to retrieve data from 100% 
de-identified staging database to use for writing tests. 
It has realistic data that has to be used for tests. 
When you retrieve that data, think about how it can be 
used in the tests and which tests need it.
Streamline automated testing by eliminating data bottlenecks.

Accelerate your release cycles and bring an end to bugs in production with rapid access to quality test data.

Start writing tests

Now that you’re set up, you can open Claude and start to write automation tests that use the MCP connection to your Tonic data.

Example: generating test cases for hospital patient data

Here's an example of how I used Claude with our sample hospital management application:

We have a hospital management application, and I added a new form to create patient records. I gave Claude this prompt:

"Can you add tests for the create patient form? Use postgres-mcp to get data for the tests."

Claude queried my Tonic Structural database to understand the actual data patterns and demographics present in the de-identified data. Based on this analysis, Claude automatically generated comprehensive test cases that covered:

  • Patients with only required fields populated
  • Missing required field scenarios
  • Patients with all optional fields present
  • Different sex and gender combinations found in the database
  • Various marital statuses present in the data
  • Different demographic variations

The key benefit was that Claude determined which categories and variations of patient data actually exist in our database, and then created realistic test cases based on those real-world patterns rather than making assumptions.

Other example workflows

Here are some other example workflows:

  • Example 1: Ask Claude to write tests for types of insurance coverage for a patient, to look into combinations of insurance coverage types and insurance providers in the table. Add specific test cases to cover those combinations.
  • Example 2: Ask Claude to look at the table and find out which columns have null or empty string values. Add sufficient test coverage for each nullable/empty string column.

Claude uses the postgres-mcp connection to query your de-identified tonic database, and then generates realistic test cases based on the actual data patterns.

Streamline test automation with Tonic Structural

When developing a comprehensive set of automated tests, it can be challenging both to get the realistic data that you need for the tests and also to find the time to write all of the tests that you need to cover all of the possible scenarios.

If you already use Structural to produce de-identified data, you can combine those safe-to-use datasets with Claude code to quickly produce complete and accurate tests.

Based on your prompt, Claude queries the data to understand the structure and then generates tests based on its analysis.

To learn more about data de-identification with Tonic Structural, connect with our team or start a free trial of Structural today.

Accelerate development with high-quality, privacy-respecting synthetic test data from Tonic.ai.Boost development speed and maintain data privacy with Tonic.ai's synthetic data solutions, ensuring secure and efficient test environments.