Skip to main content

A Model Context Protocol (MCP) server that enables secure interaction with IoTDB databases. This server allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.

Project description

IoTDB MCP Server

smithery badge

English | 中文

Overview

A Model Context Protocol (MCP) server implementation that provides database interaction and business intelligence capabilities through IoTDB. This server enables running SQL queries and interacting with IoTDB using different SQL dialects (Tree Model and Table Model).

Components

Resources

The server doesn't expose any resources.

Prompts

The server doesn't provide any prompts.

Tools

The server offers different tools for IoTDB Tree Model and Table Model. You can choose between them by setting the "IOTDB_SQL_DIALECT" configuration to either "tree" or "table".

Tree Model

  • metadata_query
    • Execute SHOW/COUNT queries to read metadata from the database
    • Input:
      • query_sql (string): The SHOW/COUNT SQL query to execute
    • Supported query types:
      • SHOW DATABASES [path]
      • SHOW TIMESERIES [path]
      • SHOW CHILD PATHS [path]
      • SHOW CHILD NODES [path]
      • SHOW DEVICES [path]
      • COUNT TIMESERIES [path]
      • COUNT NODES [path]
      • COUNT DEVICES [path]
    • Returns: Query results as array of objects
  • select_query
    • Execute SELECT queries to read data from the database
    • Input:
      • query_sql (string): The SELECT SQL query to execute (using TREE dialect, time using ISO 8601 format, e.g. 2017-11-01T00:08:00.000)
    • Supported functions:
      • SUM, COUNT, MAX_VALUE, MIN_VALUE, AVG, VARIANCE, MAX_TIME, MIN_TIME, etc.
    • Returns: Query results as array of objects
  • export_query
    • Execute a query and export the results to a CSV or Excel file
    • Input:
      • query_sql (string): The SQL query to execute (using TREE dialect)
      • format (string): Export format, either "csv" or "excel" (default: "csv")
      • filename (string): Optional filename for the exported file. If not provided, a unique filename will be generated.
    • Returns: Information about the exported file and a preview of the data (max 10 rows)

Table Model

Query Tools
  • read_query
    • Execute SELECT queries to read data from the database
    • Input:
      • query_sql (string): The SELECT SQL query to execute (using TABLE dialect, time using ISO 8601 format, e.g. 2017-11-01T00:08:00.000)
    • Returns: Query results as array of objects
Schema Tools
  • list_tables

    • Get a list of all tables in the database
    • No input required
    • Returns: Array of table names
  • describe_table

    • View schema information for a specific table
    • Input:
      • table_name (string): Name of table to describe
    • Returns: Array of column definitions with names and types
  • export_table_query

    • Execute a query and export the results to a CSV or Excel file
    • Input:
      • query_sql (string): The SQL query to execute (using TABLE dialect)
      • format (string): Export format, either "csv" or "excel" (default: "csv")
      • filename (string): Optional filename for the exported file. If not provided, a unique filename will be generated.
    • Returns: Information about the exported file and a preview of the data (max 10 rows)

Configuration Options

IoTDB MCP Server supports the following configuration options, which can be set via environment variables or command-line arguments:

Option Environment Variable Default Value Description
--host IOTDB_HOST 127.0.0.1 IoTDB host address
--port IOTDB_PORT 6667 IoTDB port
--user IOTDB_USER root IoTDB username
--password IOTDB_PASSWORD root IoTDB password
--database IOTDB_DATABASE test IoTDB database name
--sql-dialect IOTDB_SQL_DIALECT table SQL dialect: tree or table
--export-path IOTDB_EXPORT_PATH /tmp Path for exporting query results

Performance Optimizations

IoTDB MCP Server includes the following performance optimization features:

  1. Session Pool Management: Uses optimized session pool configurations, supporting up to 100 concurrent sessions
  2. Optimized Fetch Size: For queries, a fetch size of 1024 is set
  3. Connection Retry: Configured automatic retry mechanism for connection failures
  4. Timeout Management: Session wait timeout set to 5000 milliseconds for improved reliability
  5. Export Functionality: Support for exporting query results to CSV or Excel formats

Prerequisites

  • Python environment
  • uv package manager
  • IoTDB installation
  • MCP server dependencies

Development

# Clone the repository
git clone https://github.com/apache/iotdb-mcp-server.git
cd iotdb-mcp-server

# Create virtual environment
uv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
uv sync

Claude Desktop Integration

Configure the MCP server in Claude Desktop's configuration file:

macOS

Location: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows

Location: %APPDATA%/Claude/claude_desktop_config.json

You may need to put the full path to the uv executable in the command field. You can get this by running which uv on MacOS/Linux or where uv on Windows.

Claude Desktop Configuration Example

Add the following configuration to Claude Desktop's configuration file:

{
  "mcpServers": {
    "iotdb": {
      "command": "uv",
      "args": [
        "--directory",
        "/Users/your_username/iotdb-mcp-server/src/iotdb_mcp_server",
        "run",
        "server.py"
      ],
      "env": {
        "IOTDB_HOST": "127.0.0.1",
        "IOTDB_PORT": "6667",
        "IOTDB_USER": "root",
        "IOTDB_PASSWORD": "root",
        "IOTDB_DATABASE": "test",
        "IOTDB_SQL_DIALECT": "table",
        "IOTDB_EXPORT_PATH": "/path/to/export/folder"
      }
    }
  }
}

Note: Make sure to replace the --directory parameter's path with your actual repository clone path.

Error Handling and Logging

IoTDB MCP Server includes comprehensive error handling and logging capabilities:

  1. Log Level: Logging level is set to INFO, allowing you to view server status in the console
  2. Exception Handling: All database operations include exception handling to ensure graceful handling and meaningful error messages when errors occur
  3. Session Management: Automatic closure of used sessions to prevent resource leaks
  4. Parameter Validation: Basic validation of user-input SQL queries to ensure only allowed query types are executed

Docker Support

You can build a container image for the IoTDB MCP Server using the Dockerfile in the project root:

# Build Docker image
docker build -t iotdb-mcp-server .

# Run container
docker run -e IOTDB_HOST=<your-iotdb-host> -e IOTDB_PORT=<your-iotdb-port> -e IOTDB_USER=<your-iotdb-user> -e IOTDB_PASSWORD=<your-iotdb-password> iotdb-mcp-server

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_apache_iotdb_mcp_server-0.2.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_apache_iotdb_mcp_server-0.2.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_apache_iotdb_mcp_server-0.2.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_apache_iotdb_mcp_server-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1d881307820ea0ad5709c94191a323226f6b9c357bb7f6fef3ef97dfe105d352
MD5 000c5b15f5062f5e72667ea90e2d53f1
BLAKE2b-256 40e34c7c99e34411265ea3c2ed8241945a5efe868f001d44327f6ec1bf5d3787

See more details on using hashes here.

File details

Details for the file iflow_mcp_apache_iotdb_mcp_server-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_apache_iotdb_mcp_server-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_apache_iotdb_mcp_server-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff8e8548d63a0ab6757e5211346ac4497b757310ddaf9703c8fd5fa45df37db4
MD5 a7b6c5fa352d121fb49f7ef1597b7779
BLAKE2b-256 aeb20964aaf7f40beab2ff61209db3e1cea71f2c549d917fea61df84b1d0e36a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page