Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
126 changes: 126 additions & 0 deletions tools/tool_clickhouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# ClickHouse 数据库查询工具

一个强大的 ClickHouse 列式数据库查询工具,支持对接 ClickHouse 20.x 及以上版本,为 MaxKB 智能体平台提供数据库查询能力。

## 功能特性

- ✅ 支持 ClickHouse 20.x ~ 25.x (推荐 21.8+)
- ✅ 提供完整的数据库查询操作
- ✅ 集成到 MaxKB 智能体平台
- ✅ 简单易用的配置和部署
- ✅ 自动处理日期、Decimal、UUID、IPv4/IPv6 等数据类型
- ✅ 支持 Array、Tuple、Nested 等复杂数据类型
- ✅ 支持连接超时设置
- ✅ 支持结果集行数限制(自动添加 LIMIT)
- ✅ 支持 HTTP/HTTPS 连接
- ✅ 友好的中文错误提示

## 系统要求

- ClickHouse Server 20.x 或更高版本(推荐 21.8+)
- MaxKB 平台环境

## 安装依赖

在使用此工具之前,需要先安装所需的依赖包:

```bash
pip install clickhouse-connect>=0.6.0
```

依赖包说明:
- `clickhouse-connect>=0.6.0` - ClickHouse 官方推荐的 Python 驱动程序

## 参数说明

| 参数 | 类型 | 必填 | 默认值 | 说明 |
|------|------|------|--------|------|
| host | string | 是 | - | 数据库服务器地址 |
| port | string | 是 | 8123 | HTTP 端口号(HTTPS 默认 8443) |
| user | string | 是 | - | 用户名 |
| password | string | 是 | - | 密码 |
| database | string | 是 | - | 数据库名称 |
| query | string | 是 | - | SQL 查询语句 |
| timeout | number | 否 | 30 | 连接超时时间(秒) |
| max_rows | number | 否 | 1000 | 最大返回行数,设为0不限制 |
| use_https | boolean | 否 | False | 是否使用 HTTPS 连接 |

## 使用示例

```python
# 基础查询
result = query_clickhouse(
host="192.168.1.100",
port="8123",
user="default",
password="your_password",
database="test_db",
query="SELECT * FROM system.tables LIMIT 10"
)

# 带超时和行数限制的查询
result = query_clickhouse(
host="192.168.1.100",
port="8123",
user="default",
password="your_password",
database="test_db",
query="SELECT * FROM your_table",
timeout=60,
max_rows=500
)

# 使用 HTTPS 连接
result = query_clickhouse(
host="192.168.1.100",
port="8443",
user="default",
password="your_password",
database="test_db",
query="SELECT version()",
use_https=True
)
```

## 错误处理

工具会返回友好的中文错误提示:

| 错误类型 | 提示信息 |
|----------|----------|
| 连接失败 | 无法连接到数据库服务器 {host}:{port},请检查地址和端口 |
| 认证失败 | 认证失败,请检查用户名和密码 |
| 数据库不存在 | 数据库 '{database}' 不存在 |
| SQL语法错误 | SQL语法错误: {详细信息} |

## 返回格式

查询结果以 JSON 格式返回:

```json
[
{"column1": "value1", "column2": "value2"},
{"column1": "value3", "column2": "value4"}
]
```

## 支持的数据类型

| ClickHouse 类型 | 转换结果 |
|-----------------|----------|
| DateTime/Date | ISO 8601 格式字符串 |
| Decimal | 浮点数 |
| UUID | 字符串 |
| IPv4/IPv6 | 字符串 |
| Array | JSON 数组 |
| Tuple | JSON 数组 |
| Nested | JSON 对象 |
| FixedString/String | 字符串 |

## 注意事项

1. 默认使用 HTTP 协议(端口 8123),如需 HTTPS 请设置 `use_https=True` 并使用端口 8443
2. 检查防火墙是否允许 8123/8443 端口访问
3. 建议使用只读账户进行查询操作
4. 大数据量查询时建议设置 max_rows 参数限制返回行数
5. 如果查询语句没有 LIMIT,工具会自动添加 max_rows 限制
5 changes: 5 additions & 0 deletions tools/tool_clickhouse/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: ClickHouse 数据库查询
tags:
- 数据库查询
title: 实现 ClickHouse 列式数据库的查询操作
description: 实现 ClickHouse 列式数据库的查询操作,支持对接 ClickHouse 20.x 及以上版本,推荐 21.8+.
Binary file added tools/tool_clickhouse/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/tool_redis/1.0.0/Redis 查询.tool
Binary file not shown.
161 changes: 161 additions & 0 deletions tools/tool_redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Redis 数据库查询工具

一个强大的 Redis 数据库查询工具,支持执行各种 Redis 命令,为 MaxKB 智能体平台提供 Redis 查询能力。

## 功能特性

- ✅ 支持 Redis 2.6 及以上版本
- ✅ 支持所有 Redis 命令(GET、SET、HGETALL、KEYS 等)
- ✅ 集成到 MaxKB 智能体平台
- ✅ 简单易用的配置和部署
- ✅ 自动处理字节、列表、集合、哈希等数据类型
- ✅ 支持带引号的参数解析
- ✅ 支持连接超时设置
- ✅ 支持结果数量限制
- ✅ 友好的中文错误提示

## 系统要求

- Redis 2.6 或更高版本
- MaxKB 平台环境

## 安装依赖

在使用此工具之前,需要先安装所需的依赖包:

```bash
pip install redis==5.0.1
```

依赖包说明:
- `redis==5.0.1` - Redis Python 客户端

## 参数说明

| 参数 | 类型 | 必填 | 默认值 | 说明 |
|------|------|------|--------|------|
| host | string | 是 | - | Redis 服务器地址 |
| port | string | 是 | 6379 | 端口号 |
| password | string | 否 | - | 密码,无密码时留空 |
| db | string | 是 | 0 | 数据库索引(0-15) |
| command | string | 是 | - | Redis 命令 |
| timeout | number | 否 | 30 | 连接超时时间(秒) |
| max_results | number | 否 | 1000 | 最大返回结果数,设为0不限制 |

## 使用示例

```python
# 获取单个键值
result = query_redis(
host="127.0.0.1",
port="6379",
password="",
db="0",
command="GET mykey"
)

# 查找所有键
result = query_redis(
host="127.0.0.1",
port="6379",
password="your_password",
db="0",
command="KEYS *"
)

# 获取哈希表所有字段
result = query_redis(
host="127.0.0.1",
port="6379",
password="your_password",
db="0",
command="HGETALL user:1001"
)

# 获取列表元素
result = query_redis(
host="127.0.0.1",
port="6379",
password="",
db="0",
command="LRANGE mylist 0 -1"
)

# 带引号参数
result = query_redis(
host="127.0.0.1",
port="6379",
password="",
db="0",
command='SET mykey "hello world"'
)
```

## 常用命令参考

| 命令 | 说明 | 示例 |
|------|------|------|
| GET | 获取字符串值 | GET key |
| SET | 设置字符串值 | SET key value |
| KEYS | 查找键 | KEYS pattern |
| HGET | 获取哈希字段 | HGET hash field |
| HGETALL | 获取哈希所有字段 | HGETALL hash |
| LRANGE | 获取列表范围 | LRANGE list 0 -1 |
| SMEMBERS | 获取集合所有成员 | SMEMBERS set |
| ZRANGE | 获取有序集合范围 | ZRANGE zset 0 -1 |
| TTL | 获取键过期时间 | TTL key |
| TYPE | 获取键类型 | TYPE key |
| INFO | 获取服务器信息 | INFO |
| DBSIZE | 获取键数量 | DBSIZE |

## 错误处理

工具会返回友好的中文错误提示:

| 错误类型 | 提示信息 |
|----------|----------|
| 连接失败 | 无法连接到 Redis 服务器 {host}:{port},请检查地址和端口 |
| 认证失败 | 认证失败,请检查密码 |
| 命令错误 | 命令执行错误: {详细信息} |
| 连接超时 | 连接超时,请检查网络或增加 timeout 参数 |

## 返回格式

查询结果以 JSON 格式返回:

```json
{
"command": "GET mykey",
"result": "myvalue",
"type": "bytes"
}
```

列表/集合结果:
```json
{
"command": "KEYS *",
"result": ["key1", "key2", "key3"],
"type": "list"
}
```

哈希结果:
```json
{
"command": "HGETALL user:1001",
"result": {
"name": "张三",
"age": "25"
},
"type": "dict"
}
```

## 注意事项

1. 生产环境建议配置 Redis 密码认证
2. 检查防火墙是否允许 6379 端口访问
3. 建议使用只读账户进行查询操作
4. 大数据量查询时建议设置 max_results 参数限制返回数量
5. KEYS 命令在大数据量时可能影响性能,建议使用 SCAN 替代
5 changes: 5 additions & 0 deletions tools/tool_redis/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Redis 数据库查询
tags:
- 数据库查询
title: 实现 Redis 的查询操作
description: 实现 Redis 的查询操作,支持执行各种 Redis 命令,包括 GET、SET、HGETALL、KEYS 等.
Binary file added tools/tool_redis/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.