ClouisleClouisle

工具 API

管理与执行工具

端点

方法路径用途
GET/api/v1/tools列出所有工具
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}删除自定义工具

身份验证

所有端点需要经过认证的 JWT 用户会话。管理与执行路由不接受 API Key 认证。

所需权限:

  • tool:read — 查看工具
  • tool:create — 创建工具
  • tool:update — 更新工具
  • tool:delete — 删除工具
  • tool:execute — 执行/测试工具

列出工具

获取所有可用工具的列表,支持分页、搜索和多维筛选。

查询参数

参数类型必填默认值描述
pageinteger1页码
page_sizeinteger10每页条数(最大 100)
searchstring-按名称或显示名称搜索
typearray-按类型筛选:builtincustommcp(可重复)
categoryarray-按分类筛选(可重复)
statusarray-按启用状态筛选(可重复)
team_idarray-按所属团队筛选(可重复)
creatorarray-按创建者筛选(可重复)

请求示例

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"
}

获取工具详情

支持通过工具 ID 或名称查询。名称查询需附加 team_id 参数。

路径参数

参数类型必填描述
tool_idstring工具 UUID(用于 GET /id/{tool_id}
tool_namestring工具名称(用于 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
  }
}

请求字段

字段类型必填描述
namestring工具名称
argumentsobject工具参数

请求示例

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"]
}

请求字段

字段类型必填描述
languagestring代码语言:javascriptpython
codestring代码内容
paramsobject输入参数
timeoutnumber超时秒数(1-60,默认 30)
commandarray自定义命令(argv 数组)
python_packagesarray需要安装的 Python 包
js_packagesarray需要安装的 JavaScript 包
python_package_index_urlstringPython 包镜像 URL
node_package_registry_urlstringJavaScript 包注册表 URL
artifactsarray沙箱产物配置
limitsobject资源限制(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_idstring拥有该工具的团队 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
}

请求字段

字段类型必填描述
namestring工具名称(唯一标识,最大 100 字符)
display_namestring显示名称(最大 100 字符)
descriptionstring工具描述
iconstring图标(emoji 或 URL,最大 100 字符)
categorystring工具分类(默认 other
typestring工具类型:builtincustommcp(默认 custom
custom_typestring自定义工具类型:httpcodemcp(仅 type=custom 时有效)
parametersarray参数定义(name、type、description、required、enum、default)
http_configobjectHTTP 配置(method、url、headers、query_params、body_template、content_type、form_fields、timeout、response_path)
code_configobject代码配置(language、code、command、python_packages、js_packages、artifacts、limits)
mcp_configobjectMCP Server 配置(transport、command、args、env、url、headers)
credentialsobject工具凭证
is_enabledboolean启用状态(默认 true)

请求示例

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_idstring工具 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_idstring工具 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"
}

错误代码

代码消息描述
4000Not found工具不存在
3000Permission denied权限不足
1001Validation failed请求数据无效

注意: 当前无每端点限流实现,这些端点未配置限流中间件。代码 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);

相关文档

这篇文章对你有帮助吗?

本页目录