GreptimeDB MCP Server
公式AIアシスタントに、GreptimeDB内のデータを安全かつ構造化された方法で探索・分析する手段を提供します。
ドキュメント
greptimedb-mcp-server
GreptimeDB 向け Model Context Protocol (MCP) サーバーです。GreptimeDB は、メトリクス、ログ、トレースを単一エンジンで処理するオープンソースの可観測性データベースです。
AI アシスタントが SQL、TQL (PromQL 互換)、RANGE クエリを使用して GreptimeDB をクエリ・分析できるようにします。読み取り専用の強制やデータマスキングなどのセキュリティ機能が組み込まれています。
クイックスタート
# Install
pip install greptimedb-mcp-server
# Run (connects to localhost:4002 by default)
greptimedb-mcp-server --host localhost --database public
Claude Desktop の場合、設定ファイル (macOS では ~/Library/Application Support/Claude/claude_desktop_config.json) に以下を追加します。
{
"mcpServers": {
"greptimedb": {
"command": "greptimedb-mcp-server",
"args": ["--host", "localhost", "--database", "public"]
}
}
}
機能
ツール
| ツール | 説明 |
|---|---|
execute_sql | フォーマット (csv/json/markdown) と制限オプションを指定して SQL クエリを実行 |
execute_tql | 時系列分析のための TQL (PromQL 互換) クエリを実行 |
query_range | RANGE/ALIGN 構文を使用した時間ウィンドウ集計クエリを実行 |
describe_table | テーブルプロファイル (スキーマ、セマンティックメタデータ、最新サンプル行、クエリガイダンス) を検査 |
explain_query | SQL または TQL クエリの実行計画を分析 (analyze=true でランタイム統計を取得。analyze=true と共に verbose=true を追加すると、パーティションごとのスキャンメトリクスとインデックスプルーニングカウンターを取得) |
health_check | データベース接続ステータスとサーバーバージョンを確認 |
パイプライン管理
| ツール | 説明 |
|---|---|
list_pipelines | すべてのパイプラインを一覧表示、または特定のパイプラインの詳細を取得 |
create_pipeline | YAML 設定で新しいパイプラインを作成 |
dryrun_pipeline | データベースに書き込まずにサンプルデータでパイプラインをテスト |
delete_pipeline | パイプラインの特定のバージョンを削除 |
ダッシュボード管理
| ツール | 説明 |
|---|---|
list_dashboards | すべての Perses ダッシュボード定義を一覧表示 |
create_dashboard | Perses ダッシュボード定義を作成または更新 |
delete_dashboard | ダッシュボード定義を削除 |
リソースとプロンプト
- リソース:
greptime://<table>/dataURI 経由でテーブルを参照 - プロンプト: 一般的なタスク向けの組み込み Jinja テンプレート —
pipeline_creator、log_pipeline、metrics_analysis、promql_analysis、trace_analysis、table_operation、schema_design_advisor、observability_correlation、ingestion_troubleshooting、query_performance_tuning
LLM 統合とプロンプトの使用方法については、docs/llm-instructions.md を参照してください。
設定
環境変数
GREPTIMEDB_HOST=localhost # Database host
GREPTIMEDB_PORT=4002 # MySQL protocol port (default: 4002)
GREPTIMEDB_USER=root # Database user
GREPTIMEDB_PASSWORD= # Database password
GREPTIMEDB_DATABASE=public # Database name
GREPTIMEDB_TIMEZONE=UTC # Session timezone
# Optional
GREPTIMEDB_HTTP_PORT=4000 # HTTP API port for pipeline/dashboard management
GREPTIMEDB_HTTP_PROTOCOL=http # HTTP protocol (http/https)
GREPTIMEDB_POOL_SIZE=5 # Connection pool size
GREPTIMEDB_MASK_ENABLED=true # Enable sensitive data masking
GREPTIMEDB_MASK_PATTERNS= # Additional patterns (comma-separated)
GREPTIMEDB_AUDIT_ENABLED=true # Enable audit logging
GREPTIMEDB_ALLOW_WRITE=false # Allow write/DDL via execute_sql (DANGEROUS, local/test only)
# Transport (for HTTP server mode)
GREPTIMEDB_TRANSPORT=stdio # stdio, sse, or streamable-http
GREPTIMEDB_LISTEN_HOST=0.0.0.0 # HTTP server bind host
GREPTIMEDB_LISTEN_PORT=8080 # HTTP server bind port
GREPTIMEDB_ALLOWED_HOSTS= # DNS rebinding protection (comma-separated)
GREPTIMEDB_ALLOWED_ORIGINS= # CORS allowed origins (comma-separated)
CLI 引数
greptimedb-mcp-server \
--host localhost \
--port 4002 \
--database public \
--user root \
--password "" \
--timezone UTC \
--pool-size 5 \
--mask-enabled true \
--allow-write false \
--transport stdio
HTTP サーバーモード
コンテナ化または Kubernetes デプロイメント向けです。mcp>=1.8.0 が必要です。
# Streamable HTTP (recommended for production)
greptimedb-mcp-server --transport streamable-http --listen-port 8080
# SSE mode (legacy)
greptimedb-mcp-server --transport sse --listen-port 3000
DNS リバインディング保護
デフォルトでは、プロキシ、ゲートウェイ、Kubernetes サービスとの互換性のため、DNS リバインディング保護は無効になっています。有効にするには、--allowed-hosts を使用します。
# Enable DNS rebinding protection with allowed hosts
greptimedb-mcp-server --transport streamable-http \
--allowed-hosts "localhost:*,127.0.0.1:*,my-service.namespace:*"
# With custom allowed origins for CORS
greptimedb-mcp-server --transport streamable-http \
--allowed-hosts "my-service.namespace:*" \
--allowed-origins "http://localhost:*,https://my-app.example.com"
# Or via environment variables
GREPTIMEDB_ALLOWED_HOSTS="localhost:*,my-service.namespace:*" \
GREPTIMEDB_ALLOWED_ORIGINS="http://localhost:*" \
greptimedb-mcp-server --transport streamable-http
421 Invalid Host Header エラーが発生した場合は、保護を無効にする (デフォルト) か、許可リストにホストを追加してください。
セキュリティ
読み取り専用データベースユーザー (推奨)
静的ユーザープロバイダー を使用して、GreptimeDB に読み取り専用ユーザーを作成します。
mcp_readonly:readonly=your_secure_password
アプリケーションレベルのセキュリティゲート
すべてのクエリは、以下の処理を行うセキュリティゲートを通過します。
- ブロック: DROP、DELETE、TRUNCATE、UPDATE、INSERT、ALTER、CREATE、GRANT、REVOKE、EXEC、LOAD、COPY
- ブロック: エンコードされたバイパス試行 (hex、UNHEX、CHAR)
- 許可: SELECT、SHOW、DESCRIBE、TQL、EXPLAIN、UNION
書き込みモード (デフォルトで無効)
サーバーはデフォルトで読み取り専用です。ローカル開発やテストのために、
execute_sql ツールを通じて、書き込み/破壊的 SQL (CREATE、DROP、ALTER、INSERT、
UPDATE、DELETE などの DDL/DML) を許可するには、書き込みモードを有効にします。
# Environment variable
GREPTIMEDB_ALLOW_WRITE=true greptimedb-mcp-server
# Or CLI argument
greptimedb-mcp-server --allow-write true
有効にすると、execute_sql のセキュリティゲートがバイパスされ、サーバーは起動時に警告をログに記録します。
⚠️ 危険: これにより、AI アシスタントがデータベースに対して破壊的なステートメントを実行できるようになります。 本番データに対して有効にしないでください。読み取りアクセスのみが必要な場合は、読み取り専用データベースユーザーと組み合わせてください。
データマスキング
機密列は、列名パターンに基づいて自動的にマスク (******) されます。
- 認証:
password、secret、token、api_key、credential - 金融:
credit_card、cvv、bank_account - 個人:
ssn、id_card、passport
カスタムパターンを追加するには、--mask-patterns phone,email で設定します。
監査ログ
すべてのツール呼び出しがログに記録されます。
2025-12-10 10:30:45 - greptimedb_mcp_server.audit - INFO - [AUDIT] execute_sql | query="SELECT * FROM cpu LIMIT 10" | success=True | duration_ms=45.2
無効にするには --audit-enabled false を使用します。
開発
# Clone and setup
git clone https://github.com/GreptimeTeam/greptimedb-mcp-server.git
cd greptimedb-mcp-server
uv venv && source .venv/bin/activate
uv sync
# Run tests
pytest
# Format & lint
uv run black .
uv run flake8 src
# Debug with MCP Inspector
npx @modelcontextprotocol/inspector uv --directory . run -m greptimedb_mcp_server.server
ライセンス
MIT ライセンス - LICENSE.md を参照してください。
謝辞
以下から着想を得ています。