Treasure Data MCP Server
MCP (Model Context Protocol) server for Treasure Data, enabling AI assistants to query and interact with Treasure Data through a secure, controlled interface.
🚀 Public Preview
This MCP server is currently in a public preview. We're excited for you to try it out and welcome your feedback to help us improve the service.
Please note: During this preview period, use of the server is free. However, we plan to introduce a usage-based pricing model in the future, which will be based on the number of queries issued. We will provide ample notice and detailed pricing information before any charges are implemented.
Your feedback during this phase is invaluable and will help us shape the future of this tool. Thank you for being an early adopter!
Features
🔍 Query databases, tables, and schemas through information_schema
📊 Execute SQL queries with automatic result limiting for LLM contexts
🔒 Security-first design with read-only mode by default
🌍 Multi-site support (US, JP, EU, AP regions)
🚀 Zero-install execution via npx
🎯 CDP (Customer Data Platform) integration for segment and activation management (Experimental)
🔄 Workflow monitoring and control - view execution status, logs, and retry failed workflows
📝 Comprehensive audit logging for all operations
Prerequisites
Node.js Installation
This MCP server requires Node.js version 18.0.0 or higher. If you don't have Node.js installed:
Download Node.js from nodejs.org
Choose the LTS (Long Term Support) version
The installer includes
npmandnpx
Verify installation by running:
Alternative installation methods:
macOS:
brew install node(using Homebrew)Windows: Use the installer from nodejs.org or
winget install OpenJS.NodeJSLinux: Use your distribution's package manager or NodeSource repositories
Installation
Using npx (recommended)
No installation needed! Configure your MCP tool to run @treasuredata/mcp-server directly via npx:
What is npx? npx is a package runner that comes with npm 5.2+. It downloads and runs packages without installing them globally, ensuring you always use the latest version.
Global installation
If you prefer a traditional installation:
Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
Configuration Options
TD_API_KEY(required): Your Treasure Data API keyTD_SITE(optional): Region endpoint -us01(default),jp01,eu01,ap02,ap03,devTD_ENABLE_UPDATES(optional): Enable write operations (execute tool) -false(default),trueTD_DATABASE(optional): Default database for queries (e.g.,sample_datasets)
Claude Code Integration
Claude Code provides built-in support for MCP servers through the claude mcp add command. To use this MCP server with Claude Code:
This command:
Adds the server with the name "td"
Sets the TD_API_KEY environment variable to your API key value
Configures Claude Code to use
npx @treasuredata/mcp-server(always uses latest version)
Additional Configuration
You can also specify additional environment variables:
Once configured, Claude Code will automatically have access to all the tools described below for querying and analyzing your Treasure Data.
Available Tools
1. list_databases
List all databases in your Treasure Data account.
Example:
2. list_tables
List all tables in a specific database.
Parameters:
database(string, optional): Database name. If omitted, uses the current database context (TD_DATABASE or last used database)
Example:
With default database configured:
3. describe_table
Get schema information for a specific table.
Parameters:
database(string, optional): Database name. If omitted, uses the current database context (TD_DATABASE or last used database)table(string, required): Table name
Example:
With default database configured:
4. query
Execute read-only SQL queries (SELECT, SHOW, DESCRIBE).
Parameters:
sql(string, required): SQL query to executelimit(number, optional): Max rows (default: 40, max: 10000)
Performance Tip: For tables with a time column, use td_interval() or td_time_range() to limit the time range:
td_interval(time, '-30d/now')- Last 30 daystd_interval(time, '-7d/now')- Last 7 daystd_interval(time, '-1d')- Yesterday onlytd_interval(time, '-1h/now')- Last hourtd_time_range(time, '2024-01-01', '2024-01-31')- Specific date range
Example:
Example with time range:
5. execute
Execute write operations (UPDATE, INSERT, DELETE, etc.) - requires TD_ENABLE_UPDATES=true.
Parameters:
sql(string, required): SQL statement to execute
Example:
6. use_database
Switch the current database context for subsequent queries.
Parameters:
database(string, required): Database to switch to
Example:
After switching, all queries will use the new database by default unless explicitly specified.
7. current_database
Get the current database context being used for queries.
Parameters: None
Example:
Response:
CDP Tools (Customer Data Platform) - EXPERIMENTAL
Note: CDP tools are currently experimental and may not cover all use cases. Additional functionality will be added based on user feedback.
The following tools are available for interacting with Treasure Data's Customer Data Platform (CDP):
8. list_parent_segments
List all parent segments in your CDP account.
Parameters: None
Example:
9. get_parent_segment
Get details of a specific parent segment.
Parameters:
parent_segment_id(integer, required): The ID of the parent segment
Example:
10. list_segments
List all segments under a specific parent segment.
Parameters:
parent_segment_id(integer, required): The ID of the parent segment
Example:
11. list_activations
List all activations (syndications) for a specific segment.
Parameters:
parent_segment_id(integer, required): The ID of the parent segmentsegment_id(integer, required): The ID of the segment
Example:
12. get_segment
Get detailed information about a specific segment, including its rules and metadata.
Parameters:
parent_segment_id(integer, required): The parent segment IDsegment_id(integer, required): The segment ID
Example:
13. parent_segment_sql
Get the SQL statement for a parent segment.
Parameters:
parent_segment_id(integer, required): The parent segment ID
Example:
Response Example:
14. segment_sql
Get the SQL statement for a segment with filtering conditions applied to the parent segment.
Parameters:
parent_segment_id(integer, required): The parent segment IDsegment_id(integer, required): The segment ID
Example:
Response Example:
Workflow Tools (Experimental) - Monitor and Control Digdag Workflows
Note: These workflow tools are experimental and provide detailed access to workflow sessions, attempts, and tasks. They are subject to change in future releases.
The following tools are available for monitoring and controlling Digdag workflows. These tools integrate with Treasure Data's workflow engine based on Digdag:
15. list_projects
List all workflow projects.
Parameters:
limit(number, optional): Maximum results (default: 100)last_id(string, optional): Pagination cursor
Example:
16. list_workflows
List workflows, optionally filtered by project name.
Parameters:
project_name(string, optional): Project name to filter bylimit(number, optional): Maximum results (default: 100)last_id(string, optional): Pagination cursor
Examples:
17. list_sessions
List workflow execution sessions with filtering options.
Parameters:
project_name(string, optional): Filter by project nameworkflow_name(string, optional): Filter by workflow namestatus(string, optional): Filter by status (running,success,error,killed,planned)from_time(string, optional): Start time (ISO 8601)to_time(string, optional): End time (ISO 8601)limit(number, optional): Maximum results (default: 100)last_id(string, optional): Pagination cursor
Example:
18. get_session_attempts
Get all attempts for a specific session.
Parameters:
session_id(string, required): Session ID
Example:
19. get_attempt_tasks
List all tasks within an attempt with their execution status.
Parameters:
attempt_id(string, required): Attempt IDinclude_subtasks(boolean, optional): Include subtasks (default: true)
Example:
20. get_task_logs
Retrieve logs for a specific task within an attempt.
Parameters:
attempt_id(string, required): Attempt IDtask_name(string, required): Task name (e.g., "+main+task1")offset(number, optional): Log offset in byteslimit(number, optional): Maximum bytes to retrieve (default: 1MB)
Example:
21. kill_attempt
Request cancellation of a running attempt.
Parameters:
attempt_id(string, required): Attempt IDreason(string, optional): Reason for cancellation
Example:
22. retry_session
Retry a session from the beginning or a specific task.
Parameters:
session_id(string, required): Session IDfrom_task(string, optional): Task name to retry fromretry_params(object, optional): Override parameters for retry
Example:
23. retry_attempt
Retry a specific attempt with resume capabilities.
Parameters:
attempt_id(string, required): Attempt ID to retryresume_from(string, optional): Task name to resume from (skip successful tasks)retry_params(object, optional): Override parameters for retryforce(boolean, optional): Force retry even if attempt is running (default: false)
Example:
Security
Read-only by default: Write operations (execute tool) require explicit configuration with
TD_ENABLE_UPDATES=trueQuery validation: All queries are validated before execution
Audit logging: All operations are logged for security monitoring
Row limiting: Automatic LIMIT injection for SELECT queries to prevent large responses
Workflow control operations: kill_attempt, retry_session, and retry_attempt are enabled by default as they are safe operations that don't modify data directly
Basic Prompt for Using td-mcp-server
When interacting with an AI assistant that has td-mcp-server configured, you can use prompts like these to effectively work with your Treasure Data:
Initial Setup Prompt
Common Task Prompts
Data Exploration:
Data Analysis:
Time-based Queries:
CDP Segment Analysis:
Workflow Monitoring:
Workflow Troubleshooting:
Usage Examples
With Claude Desktop
Ask Claude to analyze your data:
Query specific data:
Get table schemas:
Example Conversations
User: "What's the total number of records in the www_access table?"
Assistant: I'll query the www_access table to get the total record count.
[Executes query and returns results]
The www_access table contains 5,000 total records.
Working with Multiple Databases
User: "I need to work with the production_logs database instead of sample_datasets"
Assistant: I'll switch to the production_logs database for you.
[Uses use_database tool]
Now switched to production_logs database. All subsequent queries will use this database by default unless you specify otherwise.
Complex Analysis Example
User: "Can you analyze user behavior patterns in our access logs for the past month?"
Assistant: I'll analyze the user behavior patterns from your access logs. Let me break this down into several queries:
First, let me check the table structure: [Describes table to understand available columns]
Now I'll analyze the overall traffic pattern for the past month:
Let me identify the most popular pages:
[Continues with analysis and insights...]
Development
Example Configurations
See the examples/ directory for sample configurations:
claude-desktop-config.json- Basic Claude Desktop setupdevelopment-config.json- Local development with loggingmulti-region-config.json- Multi-region setup
Developer Notes
For information on testing this MCP server with GitHub Copilot Chat agent mode, see DEVELOPER_NOTES.md.
License
Apache License 2.0
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
Support
For issues and feature requests, please visit: https://github.com/treasure-data/td-mcp-server/issues