greoptimedb-mcp服务器
](https://pypi.org/project/greptimedb-mcp-server/)  
一种模型上下文协议(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,请将此添加到您的配置中(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"greptimedb": {
"command": "greptimedb-mcp-server",
"args": ["--host", "localhost", "--database", "public"]
}
}
}特性
工具
| 工具 | 说明 |
|---|---|
execute_sql | 使用格式(csv/json/makdown)和限制选项执行SQL查询 |
execute_tql | 执行TQL(兼容PromQL)查询以进行时间序列分析 |
query_range | 使用RANGE/ALIGN语法执行时间窗口聚合查询 |
describe_table | 获取包含列名、类型和约束的表架构 |
explain_query | 分析SQL或TQL查询执行计划 |
health_check | 检查数据库连接状态和服务器版本 |
管道管理
| 工具 | 说明 |
|---|---|
list_pipelines | 列出所有管道或获取特定管道的详细信息 |
create_pipeline | 使用YAML配置创建新管道 |
dryrun_pipeline | 使用示例数据测试管道,而不写入数据库 |
delete_pipeline | 删除管道的特定版本 |
仪表板管理
| 工具 | 说明 |
|---|---|
list_dashboards | 列出所有Perses仪表板定义 |
create_dashboard | 创建或更新Perses仪表板定义 |
delete_dashboard | 删除仪表板定义 |
资源和提示
- 资源:通过浏览表格
greptime:///dataURI - 提示:用于常见任务的内置模板--
pipeline_creator,log_pipeline,metrics_analysis,promql_analysis,iot_monitoring,trace_analysis,table_operation
有关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
# 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 \
--transport stdioHTTP服务器模式
用于容器化或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 3000DNS重新绑定保护
默认情况下,DNS重新绑定保护为 残疾的 为了与代理、网关和Kubernetes服务兼容。要启用它,请使用 --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应用级安全门
所有查询都通过一个安全门:
- 积木:删除、删除、截断、更新、插入、更改、创建、授予、撤销、执行、加载、复制
- 积木:编码的旁路尝试(十六进制、UNHEX、CHAR)
- 允许:选择、显示、描述、TQL、解释、联合
数据屏蔽
敏感列会自动屏蔽(******)基于列名模式:
- 身份验证:
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许可证-请参阅 许可证.md.
致谢
灵感来源:
