Skip to main content
The DataGen SDK lets you execute MCP tools programmatically from your own codebase. While the DataGen MCP server handles discovery and interactive use, the SDK enables production-ready scripts, batch processing, and scheduled automations at scale.

Why Use the SDK?

You’ve already connected your MCP servers through DataGen. Now you need to use those tools in production code without reimplementing authentication flows or managing credentials. The core problem: When you scale beyond simple MCP tool calls, you hit limitations:
ChallengeWithout SDKWith DataGen SDK
Batch operationsSequential MCP calls, token explosionParallel execution, local data handling
Large datasets50K leads = 50K API round-tripsProcess locally, summarize results
Credential managementScatter API keys across codebasesSingle DATAGEN_API_KEY, auth handled by gateway
Error handlingAd-hoc retry logic per serviceBuilt-in exponential backoff
Production deploymentCustom auth code per providerSame code in dev and prod
The SDK advantage:
MCP Tool Call (interactive):
  User request → LLM → MCP tool → Result → LLM → Response
  Each call flows through LLM context (expensive for large operations)

SDK Execution (production):
  Your code → DatagenClient.executeTool() → Gateway → Result
  Data stays local, only final results matter

When to Use SDK vs MCP Tools

Use MCP Tools When

  • Interactive discovery and debugging
  • Simple one-off operations
  • Learning tool schemas with getToolDetails
  • AI agent-assisted development

Use SDK When

  • Batch processing (100+ operations)
  • Scheduled jobs and cron tasks
  • CI/CD pipelines
  • Production applications
  • Large data processing
Rule of thumb:
  • < 5 tool calls, small results - Direct MCP tool call
  • > 5 calls, large data, complex logic - Write code using SDK

Installation

Quick Install

pip install datagen-python-sdk
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install datagen-python-sdk

Set Your API Key

Get your API key from datagen.dev/account?tab=api:
export DATAGEN_API_KEY="your_api_key_here"

Verify Installation

python -c "from datagen_sdk import DatagenClient; print('SDK installed successfully')"
MCP Prompt Installation: If you’re using Claude Code with DataGen MCP, you can run the install-datagen-python-sdk prompt to get guided installation steps.

Quick Start

from datagen_sdk import DatagenClient

client = DatagenClient()

# Send an email through Gmail MCP
result = client.execute_tool(
    "mcp_Gmail_gmail_send_email",
    {
        "to": "user@example.com",
        "subject": "Hello from DataGen",
        "body": "This email was sent using the DataGen SDK!"
    }
)

print(result)

Examples

Batch Email Campaign

Process contacts and send personalized emails:
from datagen_sdk import DatagenClient

client = DatagenClient()

# Get contacts from database
contacts = client.execute_tool(
    "mcp_Supabase_run_sql",
    {
        "params": {
            "sql": "SELECT email, name FROM users WHERE signup_date > NOW() - INTERVAL '7 days'",
            "projectId": "your-project-id",
            "databaseName": "your-db"
        }
    }
)

# Send personalized emails
for contact in contacts:
    client.execute_tool(
        "mcp_Gmail_gmail_send_email",
        {
            "to": contact["email"],
            "subject": "Welcome!",
            "body": f"Hi {contact['name']}, thanks for signing up!"
        }
    )
    print(f"Sent to {contact['email']}")

Error Handling

Handle authentication and tool execution errors:
from datagen_sdk import DatagenClient, DatagenAuthError, DatagenToolError

client = DatagenClient(
    retries=3,           # Retry up to 3 times
    backoff_seconds=0.5  # Exponential backoff
)

try:
    result = client.execute_tool(
        "mcp_Linear_list_projects",
        {"limit": 10}
    )
    print(result)
except DatagenAuthError:
    print("Authentication failed - check your API key or MCP connection")
except DatagenToolError as e:
    print(f"Tool execution failed: {e.message}")

Multi-Service Workflow

Combine multiple MCP tools in a single workflow:
from datagen_sdk import DatagenClient

client = DatagenClient()

# 1. Fetch high-priority leads from database
leads = client.execute_tool(
    "mcp_Supabase_run_sql",
    {
        "params": {
            "sql": "SELECT * FROM leads WHERE score > 80",
            "projectId": "your-project",
            "databaseName": "your-db"
        }
    }
)

# 2. Create tasks in Linear for each lead
for lead in leads:
    issue = client.execute_tool(
        "mcp_Linear_create_issue",
        {
            "title": f"Follow up with {lead['company']}",
            "description": f"Contact: {lead['email']}\nScore: {lead['score']}",
            "teamId": "your-team-id"
        }
    )
    print(f"Created Linear issue: {issue['id']}")

# 3. Notify team on Slack
client.execute_tool(
    "mcp_Slack_chat_postMessage",
    {
        "channel": "#sales",
        "text": f"Created {len(leads)} follow-up tasks for high-priority leads"
    }
)

API Reference

Client Configuration

from datagen_sdk import DatagenClient

client = DatagenClient(
    api_key=None,           # Default: from DATAGEN_API_KEY env var
    base_url="https://api.datagen.dev",
    timeout=30,             # Request timeout in seconds
    retries=0,              # Retry attempts for failed requests
    backoff_seconds=0.5     # Initial backoff for retries
)

Execute Tool

The primary method for calling MCP tools:
result = client.execute_tool(
    tool_alias_name: str,   # e.g., "mcp_Gmail_gmail_send_email"
    parameters: dict = {}   # Tool-specific parameters
)

Error Types

ErrorDescription
DatagenAuthErrorAuthentication failed (401/403) - check API key or MCP connection
DatagenToolErrorTool execution failed - check parameters match schema
DatagenHttpErrorNetwork or HTTP-level errors

Best Practices

Before writing production code, use the getToolDetails MCP tool to confirm exact parameter names and types:
# Via MCP or SDK
details = client.execute_tool("getToolDetails", {"tool_name": "mcp_Gmail_gmail_send_email"})
print(details["inputSchema"])
Never hardcode API keys in your code. The SDK automatically reads from DATAGEN_API_KEY:
export DATAGEN_API_KEY="your_api_key_here"
Configure retries and backoff for resilient production code:
client = DatagenClient(retries=3, backoff_seconds=1.0)
Wrap tool calls in try/except and handle specific error types:
try:
    result = client.execute_tool("mcp_Gmail_gmail_send_email", {...})
except DatagenAuthError:
    # Re-authenticate or check MCP connection
except DatagenToolError as e:
    # Log error and retry with corrected params

Resources

Python SDK

Source code, examples, and documentation

TypeScript SDK

Source code, examples, and documentation

Get API Key

Generate your DataGen API key

Connect MCP Servers

Add Gmail, Slack, Linear, and more