工具 API
管理与执行工具
端点
| 方法 | 路径 | 用途 |
|---|---|---|
| GET | /api/v1/tools | 列出所有工具 |
| GET | /api/v1/tools/filters | 获取筛选选项(类型、分类、状态、团队、创建者) |
| GET | /api/v1/tools/legacy?team_id={team_id} | 旧版团队工具列表(按种类分组) |
| GET | /api/v1/tools/builtin | 列出全部内置工具 |
| GET | /api/v1/tools/file-parsers?team_id={team_id} | 列出可用于文件上传的解析器 |
| GET | /api/v1/tools/id/{tool_id} | 通过 ID 获取工具详情 |
| GET | /api/v1/tools/name/{tool_name}?team_id={team_id} | 通过名称获取工具详情 |
| POST | /api/v1/tools/test | 单次测试工具(无独立执行端点) |
| POST | /api/v1/tools/execute-code | 在沙箱中直接运行代码 |
| POST | /api/v1/tools?team_id={team_id} | 创建自定义工具 |
| PUT | /api/v1/tools/{tool_id} | 更新工具配置 |
| DELETE | /api/v1/tools/{tool_id} | 删除自定义工具 |
| POST | /api/v1/tools/{tool_id}/toggle | 切换工具的启用状态 |
| POST | /api/v1/tools/{tool_id}/duplicate | 复制工具(副本默认禁用) |
| GET | /api/v1/tools/config?team_id={team_id} | 列出工具配置(凭证) |
| GET | /api/v1/tools/config/{tool_name}?team_id={team_id} | 获取单个工具配置 |
| POST | /api/v1/tools/config?team_id={team_id} | 创建工具配置 |
| PUT | /api/v1/tools/config/{tool_name}?team_id={team_id} | 更新工具配置 |
| DELETE | /api/v1/tools/config/{tool_name}?team_id={team_id} | 删除工具配置 |
| POST | /api/v1/tools/{tool_id}/share | 将工具共享给其他团队 |
| GET | /api/v1/tools/{tool_id}/shares | 查询工具的共享列表 |
| DELETE | /api/v1/tools/{tool_id}/share/{team_id} | 取消对指定团队的共享 |
| GET | /api/v1/tools/shared-with-me?team_id={team_id} | 查询共享给指定团队的工具 |
| POST | /api/v1/tools/mcp/list-tools | 动态发现 MCP Server 的工具定义 |
| POST | /api/v1/tools/database/test-connection | 测试数据库连通性 |
身份验证
所有端点需要经过认证的 JWT 用户会话。管理与执行路由不接受 API Key 认证。
所需权限:
tool:read— 查看工具tool:create— 创建工具tool:update— 更新工具tool:delete— 删除工具tool:execute— 执行/测试工具
列出工具
获取所有可用工具的列表,支持分页、搜索和多维筛选。
查询参数
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
page | integer | 否 | 1 | 页码 |
page_size | integer | 否 | 10 | 每页条数(最大 100) |
search | string | 否 | - | 按名称或显示名称搜索 |
type | array | 否 | - | 按类型筛选:builtin、custom、mcp(可重复) |
category | array | 否 | - | 按分类筛选(可重复) |
status | array | 否 | - | 按启用状态筛选(可重复) |
team_id | array | 否 | - | 按所属团队筛选(可重复) |
creator | array | 否 | - | 按创建者筛选(可重复) |
请求示例
curl -X GET "https://your-domain.com/api/v1/tools?category=search" \
-H "Authorization: Bearer YOUR_TOKEN"响应
成功 (200 OK):
{
"code": 0,
"data": {
"items": [
{
"id": "tool-123",
"name": "web_search",
"display_name": "Web Search",
"description": "Search the internet for information",
"type": "builtin",
"category": "search",
"icon": "🔍",
"parameters": [
{
"name": "query",
"type": "string",
"description": "Search query",
"required": true
},
{
"name": "max_results",
"type": "integer",
"description": "Maximum number of results",
"required": false,
"default": 5
}
],
"is_enabled": true,
"requires_config": false,
"config_fields": [],
"custom_type": null,
"http_config": null,
"code_config": null,
"mcp_config": null,
"team_id": null,
"created_by_id": null,
"created_by_name": null,
"is_owned": true,
"owner_team_id": null,
"owner_team_name": null,
"share_permission": null,
"shared_with_count": 0
}
],
"total": 15,
"page": 1,
"page_size": 10
},
"msg": "success"
}工具筛选选项
GET /api/v1/tools/filters需要 tool:read。返回当前用户可访问工具的筛选项,用于构建列表页的筛选下拉。
{
"code": 0,
"data": {
"types": [
{ "value": "builtin", "label": "builtin" },
{ "value": "custom", "label": "custom" },
{ "value": "mcp", "label": "mcp" }
],
"categories": [{ "value": "search", "label": "search" }],
"statuses": [
{ "value": "enabled", "label": "enabled" },
{ "value": "disabled", "label": "disabled" }
],
"teams": [{ "value": "team-123", "label": "Engineering" }],
"creators": [{ "value": "alice", "label": "alice" }]
},
"msg": "success"
}categories 为全部已定义的工具分类并集上可访问工具中出现的自定义分类;teams 为当前用户可访问的团队;creators 为可访问工具的去重创建者名。
旧版团队工具列表
GET /api/v1/tools/legacy?team_id={team_id}旧版兼容端点,返回按种类分组(builtin / custom / mcp)的团队工具。新集成应优先使用 GET /api/v1/tools(见上文"列出工具")。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
team_id | string | 是 | - | 团队 UUID |
include_shared | boolean | 否 | true | 是否包含其他团队共享给该团队的工具 |
builtin 始终返回完整内置工具清单;custom 与 mcp 返回该团队自己的工具(排除其他成员的私有工具),并在 include_shared=true 时合并共享进来的工具。
内置工具
GET /api/v1/tools/builtin返回全部内置工具(含沙箱工具 artifact、bash、edit、read、write)。内置工具没有数据库记录,因此这些对象的 id 为 null,custom_type 为 null。
文件解析器
GET /api/v1/tools/file-parsers?team_id={team_id}返回可用于文件上传解析的工具:内置解析器(如 markitdown)加上该团队启用的、category=file 的自定义工具。需要 tool:read 与团队成员身份。
获取工具详情
支持通过工具 ID 或名称查询。名称查询需附加 team_id 参数。
路径参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
tool_id | string | 是 | 工具 UUID(用于 GET /id/{tool_id}) |
tool_name | string | 是 | 工具名称(用于 GET /name/{tool_name}) |
请求示例
curl -X GET "https://your-domain.com/api/v1/tools/id/tool-123" \
-H "Authorization: Bearer YOUR_TOKEN"响应
成功 (200 OK):
{
"code": 0,
"data": {
"id": "tool-123",
"name": "web_search",
"display_name": "Web Search",
"description": "Search the internet for information",
"type": "builtin",
"category": "search",
"icon": "🔍",
"parameters": [...],
"is_enabled": true,
"requires_config": false,
"config_fields": [],
"custom_type": null,
"http_config": null,
"code_config": null,
"mcp_config": null,
"team_id": null,
"created_by_id": null,
"created_by_name": null,
"is_owned": true,
"owner_team_id": null,
"owner_team_name": null,
"share_permission": null,
"shared_with_count": 0,
"created_at": null,
"updated_at": null
},
"msg": "success"
}测试工具
按名称单次执行工具并传入参数。注意: 没有独立的 POST /tools/{tool_id}/execute 端点,统一使用此接口。
请求体
{
"name": "web_search",
"arguments": {
"query": "artificial intelligence",
"max_results": 5
}
}请求字段
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
name | string | 是 | 工具名称 |
arguments | object | 否 | 工具参数 |
请求示例
curl -X POST "https://your-domain.com/api/v1/tools/test" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "web_search",
"arguments": {
"query": "artificial intelligence",
"max_results": 5
}
}'响应
成功 (200 OK):
{
"code": 0,
"data": {
"name": "web_search",
"success": true,
"result": {
"results": [
{
"title": "Artificial Intelligence - Wikipedia",
"url": "https://en.wikipedia.org/wiki/Artificial_intelligence",
"snippet": "Artificial intelligence (AI) is intelligence demonstrated by machines..."
}
]
},
"error": null,
"logs": null,
"artifacts": [],
"duration_ms": 1200
},
"msg": "success"
}错误 (400 Bad Request):
{
"code": 1001,
"data": {
"field": "arguments.query",
"error": "Query is required"
},
"msg": "Validation failed"
}执行代码
直接在沙箱中运行 JavaScript/Python 代码,无需保存为工具。
请求体
{
"language": "python",
"code": "print(1 + 1)",
"params": {},
"timeout": 30,
"python_packages": ["requests"]
}请求字段
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
language | string | 是 | 代码语言:javascript、python |
code | string | 是 | 代码内容 |
params | object | 否 | 输入参数 |
timeout | number | 否 | 超时秒数(1-60,默认 30) |
command | array | 否 | 自定义命令(argv 数组) |
python_packages | array | 否 | 需要安装的 Python 包 |
js_packages | array | 否 | 需要安装的 JavaScript 包 |
python_package_index_url | string | 否 | Python 包镜像 URL |
node_package_registry_url | string | 否 | JavaScript 包注册表 URL |
artifacts | array | 否 | 沙箱产物配置 |
limits | object | 否 | 资源限制(timeout_seconds、disk_mb、max_stdout_kb、max_stderr_kb) |
请求示例
curl -X POST "https://your-domain.com/api/v1/tools/execute-code" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"language": "python",
"code": "print(1 + 1)"
}'响应
成功 (200 OK):
{
"code": 0,
"data": {
"success": true,
"result": "2\n",
"error": null,
"logs": null,
"artifacts": [],
"duration_ms": 350
},
"msg": "success"
}创建自定义工具
创建自定义工具。team_id 为必填查询参数。
查询参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
team_id | string | 是 | 拥有该工具的团队 UUID |
请求体
{
"name": "crm_lookup",
"display_name": "CRM Lookup",
"description": "Look up customer information in CRM",
"category": "data",
"type": "custom",
"custom_type": "http",
"icon": "👤",
"parameters": [
{
"name": "customer_id",
"type": "string",
"required": true,
"description": "Customer ID to lookup"
}
],
"http_config": {
"method": "GET",
"url": "https://api.crm.example.com/customers/{customer_id}",
"headers": {
"X-API-Key": "crm_..."
},
"timeout": 30
},
"credentials": {},
"is_enabled": true
}请求字段
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
name | string | 是 | 工具名称(唯一标识,最大 100 字符) |
display_name | string | 是 | 显示名称(最大 100 字符) |
description | string | 否 | 工具描述 |
icon | string | 否 | 图标(emoji 或 URL,最大 100 字符) |
category | string | 否 | 工具分类(默认 other) |
type | string | 否 | 工具类型:builtin、custom、mcp(默认 custom) |
custom_type | string | 否 | 自定义工具类型:http、code、database(仅 type=custom 时有效) |
visibility | string | 否 | 工具可见性:private 或 team(默认 private) |
parameters | array | 否 | 参数定义(name、type、description、required、enum、default) |
http_config | object | 否 | HTTP 配置(method、url、headers、query_params、body_template、content_type、form_fields、timeout、response_path) |
code_config | object | 否 | 代码配置(language、code、command、python_packages、js_packages、python_package_index_url、node_package_registry_url、artifacts、limits) |
database_config | object | 否 | 数据库配置(db_type、host、port、database、username、password、ssl、url、db、auth_source、timeout、max_limit) |
mcp_config | object | 否 | MCP Server 配置(transport、command、args、env、url、headers) |
credentials | object | 否 | 工具凭证 |
is_enabled | boolean | 否 | 启用状态(默认 true) |
name 必须匹配 ^[a-zA-Z][a-zA-Z0-9_]*$(字母开头,只含字母、数字、下划线),否则返回 1001 tool_name_invalid_format;同团队内重名返回 5001 tool_name_exists。
请求示例
curl -X POST "https://your-domain.com/api/v1/tools?team_id=team-123" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "crm_lookup",
"display_name": "CRM Lookup",
"description": "Look up customer information in CRM",
"category": "data",
"type": "custom",
"custom_type": "http",
"parameters": [
{
"name": "customer_id",
"type": "string",
"required": true
}
],
"http_config": {
"method": "GET",
"url": "https://api.crm.example.com/customers/{customer_id}"
}
}'响应
成功 (200 OK):
{
"code": 0,
"data": {
"id": "tool-789",
"name": "crm_lookup",
"display_name": "CRM Lookup",
"description": "Look up customer information in CRM",
"type": "custom",
"category": "data",
"custom_type": "http",
"is_enabled": true,
"team_id": "team-123",
"created_at": "2026-02-11T16:00:00Z",
"updated_at": "2026-02-11T16:00:00Z",
"created_by_name": "alice"
},
"msg": "Tool created successfully"
}更新工具
更新工具配置。所有字段均为可选,只需包含要更新的字段。
路径参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
tool_id | string | 是 | 工具 UUID |
请求体
{
"display_name": "CRM Lookup (Updated)",
"is_enabled": true,
"http_config": {
"timeout": 60
}
}请求示例
curl -X PUT "https://your-domain.com/api/v1/tools/tool-789" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"display_name": "CRM Lookup (Updated)",
"is_enabled": true
}'响应
成功 (200 OK):
{
"code": 0,
"data": {
"id": "tool-789",
"name": "crm_lookup",
"display_name": "CRM Lookup (Updated)",
"type": "custom",
"is_enabled": true,
"team_id": "team-123",
"created_at": "2026-02-11T16:00:00Z",
"updated_at": "2026-02-11T16:05:00Z",
"created_by_name": "alice"
},
"msg": "Tool updated successfully"
}删除工具
删除自定义工具。
路径参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
tool_id | string | 是 | 工具 UUID |
请求示例
curl -X DELETE "https://your-domain.com/api/v1/tools/tool-789" \
-H "Authorization: Bearer YOUR_TOKEN"响应
成功 (200 OK):
{
"code": 0,
"data": null,
"msg": "Tool deleted successfully"
}启用 / 停用工具
POST /api/v1/tools/{tool_id}/toggle翻转工具的启用状态,无请求体。只有数据库存储的工具(custom、mcp)可切换;内置工具始终启用。调用者需为工具创建者或团队管理员,并具备 tool:update。
curl -X POST "https://your-domain.com/api/v1/tools/tool-789/toggle" \
-H "Authorization: Bearer YOUR_TOKEN"成功响应(200 OK): 返回更新后的 ToolDetailOut,is_enabled 为翻转后的值,msg 为 "Tool updated successfully"。
复制工具
POST /api/v1/tools/{tool_id}/duplicate在工具所属团队内复制一份。需要 tool:create 权限与工具所属团队的管理员角色。
curl -X POST "https://your-domain.com/api/v1/tools/tool-789/duplicate" \
-H "Authorization: Bearer YOUR_TOKEN"副本规则:
- 可见性固定为
private,is_enabled固定为false(复制后需手动启用)。 - 名称追加
_copy;若已存在则依次尝试_copy_1、_copy_2……直到唯一。 - 显示名称追加
(Copy)。 - 复制
code_config、database_config、mcp_config与credentials。
复制会连同 credentials 一起复制,因此副本会继承原工具的凭证。复制后请及时轮换或删除不需要的凭据。
跨团队共享工具
将自定义工具或 MCP 工具共享给同一工作区中的其他团队。共享需要「工具所属团队的管理员」权限;不能共享给工具自己所属的团队。
共享工具
POST /api/v1/tools/{tool_id}/share| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
team_id | string | 是 | 接收共享的团队 UUID |
permission | string | 否 | read_only(可查看并使用)或 read_execute(还可查看执行结果),默认 read_only |
curl -X POST "https://your-domain.com/api/v1/tools/tool-789/share" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"team_id": "team-456", "permission": "read_execute"}'响应返回共享记录,包含 id、tool_id、tool_name、tool_display_name、shared_with_team_id、shared_with_team_name、permission、shared_by_id、shared_by_name、shared_at。
查询工具的共享列表
GET /api/v1/tools/{tool_id}/shares返回 { "shares": [...], "total": N },仅工具所属团队的成员可读。
查询共享给团队的工具
GET /api/v1/tools/shared-with-me?team_id={team_id}team_id 为必填查询参数。返回的工具项带 is_owned: false、owner_team_id、owner_team_name 与 share_permission。
取消共享
DELETE /api/v1/tools/{tool_id}/share/{team_id}工具配置(凭证)
工具配置用于为内置工具或数据库工具存储凭证(API Key、Token 等),可以全局(仅超级管理员)或按团队存储。
GET /api/v1/tools/config?team_id={team_id}
GET /api/v1/tools/config/{tool_name}?team_id={team_id}
POST /api/v1/tools/config?team_id={team_id}
PUT /api/v1/tools/config/{tool_name}?team_id={team_id}
DELETE /api/v1/tools/config/{tool_name}?team_id={team_id}| 参数 | 位置 | 必填 | 描述 |
|---|---|---|---|
team_id | 查询参数 | 否 | 团队 UUID;省略时操作全局配置(仅超级管理员) |
tool_name | 路径参数 | 是(get/put/delete) | 工具名,例如 web_search |
创建请求体:
{
"tool_name": "web_search",
"credentials": {
"TAVILY_API_KEY": "tvly-..."
}
}更新请求体只需 credentials:
{
"credentials": {
"TAVILY_API_KEY": "tvly-updated"
}
}权限与行为:
- 带
team_id时,创建/更新/删除需要团队管理员角色,读取只需团队成员身份。 - 不带
team_id时,读取与写入都仅限超级管理员。 - 读取某个已知内置工具名但尚无记录的团队配置时,会自动创建一份空配置;未知工具名返回
404。 - 删除成功时
data为null。
MCP 与数据库工具诊断
发现 MCP Server 工具
POST /api/v1/tools/mcp/list-tools在保存 MCP 工具前,先连接 MCP Server 拉取可用工具定义。
{
"mcp_config": {
"transport": "sse",
"command": null,
"args": [],
"env": {},
"url": "https://mcp.internal.example.com/sse",
"headers": {}
}
}mcp_config.transport 支持 stdio、sse、http:stdio 使用 command、args、env;sse/http 使用 url 与 headers。
响应返回 tools(每个工具含名称、描述与参数 schema)、server_name 与 server_version。
该端点会向 url 或 command 指定的目标发起真实网络调用。目标地址受部署级出站网络白名单限制,被拦截时返回 400。
测试数据库连通性
POST /api/v1/tools/database/test-connection{
"db_type": "postgresql",
"host": "db.example.com",
"port": 5432,
"database": "analytics",
"username": "readonly",
"password": "secret_password",
"ssl": true,
"timeout": 15,
"max_limit": 100
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
db_type | string | 是 | postgresql、mysql、redis、mongodb |
host | string | 否 | 主机名或 IP |
port | integer | 否 | 端口号 |
database | string | 否 | 数据库名称 |
username | string | 否 | 用户名 |
password | string | 否 | 密码 |
ssl | string | boolean | 否 | SSL 配置 |
url | string | 否 | Redis / MongoDB 连接 URL(替代 host/port) |
db | integer | 否 | Redis 逻辑库序号 |
auth_source | string | 否 | MongoDB 认证库 |
timeout | integer | 否 | 查询超时秒数(1–120,默认 15) |
max_limit | integer | 否 | 最大返回记录数(1–1000,默认 100) |
连接失败时返回 400,msg 为具体失败原因(例如 database_connection_failed)。
错误代码
| 代码 | 消息 | 描述 |
|---|---|---|
4000 | Not found | 工具不存在 |
4004 | Team not found | 目标团队不存在 |
3000 | Permission denied | 权限不足(共享需要团队管理员) |
3003 | Team admin required | 需要工具所属团队的管理员角色 |
5001 | Already exists | 团队内已存在同名工具 |
5104 | Duplicate name | 工具已共享给该团队,或该工具配置已存在 |
1001 | Validation failed | 请求数据无效(含工具名格式非法) |
1002 | Bad request | 共享给工具自身所属团队、数据库连接测试失败等 |
注意: 当前无每端点限流实现,这些端点未配置限流中间件。代码
6300-6306保留给 SSO 错误,工具 API 未使用。
代码示例
Python
import requests
def list_tools(token):
"""列出所有可用工具。"""
url = "https://your-domain.com/api/v1/tools"
headers = {
"Authorization": f"Bearer {token}"
}
response = requests.get(url, headers=headers)
result = response.json()
if result['code'] == 0:
return result['data']['items']
else:
raise Exception(f"Error: {result['msg']}")
def test_tool(token, name, arguments):
"""单次执行工具。"""
url = "https://your-domain.com/api/v1/tools/test"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {
"name": name,
"arguments": arguments
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result['code'] == 0:
return result['data']['result']
else:
raise Exception(f"Error: {result['msg']}")
# 使用
tools = list_tools("YOUR_TOKEN")
for tool in tools:
print(f"Tool: {tool['display_name']} ({tool['category']})")
# 执行网络搜索
result = test_tool(
"YOUR_TOKEN",
"web_search",
{"query": "artificial intelligence", "max_results": 5}
)
print(f"Search results: {result['results']}")JavaScript
async function listTools(token) {
const response = await fetch(
'https://your-domain.com/api/v1/tools',
{
headers: {
'Authorization': `Bearer ${token}`,
},
}
);
const result = await response.json();
if (result.code === 0) {
return result.data.items;
} else {
throw new Error(result.msg);
}
}
async function testTool(token, name, arguments) {
const response = await fetch(
'https://your-domain.com/api/v1/tools/test',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: name,
arguments: arguments,
}),
}
);
const result = await response.json();
if (result.code === 0) {
return result.data.result;
} else {
throw new Error(result.msg);
}
}
// 使用
const tools = await listTools('YOUR_TOKEN');
tools.forEach(tool => {
console.log(`Tool: ${tool.display_name} (${tool.category})`);
});
// 执行网络搜索
const result = await testTool(
'YOUR_TOKEN',
'web_search',
{ query: 'artificial intelligence', max_results: 5 }
);
console.log('Search results:', result.results);相关文档
这篇文章对你有帮助吗?