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:| Challenge | Without SDK | With DataGen SDK |
|---|---|---|
| Batch operations | Sequential MCP calls, token explosion | Parallel execution, local data handling |
| Large datasets | 50K leads = 50K API round-trips | Process locally, summarize results |
| Credential management | Scatter API keys across codebases | Single DATAGEN_API_KEY, auth handled by gateway |
| Error handling | Ad-hoc retry logic per service | Built-in exponential backoff |
| Production deployment | Custom auth code per provider | Same code in dev and prod |
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
- < 5 tool calls, small results - Direct MCP tool call
- > 5 calls, large data, complex logic - Write code using SDK
Installation
- Python
- TypeScript
Quick Install
With Virtual Environment (Recommended)
Set Your API Key
Get your API key from datagen.dev/account?tab=api:Verify Installation
Quick Start
- Python
- TypeScript
Examples
Batch Email Campaign
Process contacts and send personalized emails:- Python
- TypeScript
Error Handling
Handle authentication and tool execution errors:- Python
- TypeScript
Multi-Service Workflow
Combine multiple MCP tools in a single workflow:- Python
- TypeScript
API Reference
Client Configuration
- Python
- TypeScript
Execute Tool
The primary method for calling MCP tools:- Python
- TypeScript
Error Types
| Error | Description |
|---|---|
DatagenAuthError | Authentication failed (401/403) - check API key or MCP connection |
DatagenToolError | Tool execution failed - check parameters match schema |
DatagenHttpError | Network or HTTP-level errors |
Best Practices
Always discover tool schemas first
Always discover tool schemas first
Before writing production code, use the
getToolDetails MCP tool to confirm exact parameter names and types:Use environment variables for API keys
Use environment variables for API keys
Never hardcode API keys in your code. The SDK automatically reads from
DATAGEN_API_KEY:Enable retries for production
Enable retries for production
Configure retries and backoff for resilient production code:
Handle errors gracefully
Handle errors gracefully
Wrap tool calls in try/except and handle specific error types:
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