---
orphan: true
---
# 批量创建 MCP 工具

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

将已探测或已保存的 MCP 连接中的工具批量创建为工作区工具。

```text
POST https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/connections/actions/batch-create-mcp-tools
```

## 调用前准备

准备具有目标工作区访问权限的个人访问令牌和目标工作区 ID。

## 请求体

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} 请求示例

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/connections/actions/batch-create-mcp-tools" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "connection_id": "'"$CONNECTION_ID"'",
    "items": [
      {
        "tool_name": "search_docs",
        "name": "搜索文档"
      }
    ]
  }'
```

:::::
:::::{tab-item} 参数说明

| 字段 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `connection_id` | string | 否 | 已保存的 MCP 连接 ID。 |
| `name` | string | 否 | 新建连接的名称。 |
| `endpoint_uri` | string | 否 | 新建连接的 MCP 服务地址。 |
| `transport` | string | 否 | MCP 传输方式。 |
| `auth_type` | string | 否 | 认证类型。 |
| `api_key_header` | string | 否 | API Key 使用的请求头名称。 |
| `credential` | object | 否 | MCP 凭据。 |
| `visibility` | string | 否 | 新建连接的可见范围。 |
| `items` | object（对象数组） | 是 | 要创建的 MCP 工具列表。 |
| `items[].tool_name` | string | 是 | MCP 服务发现的工具名称。 |
| `items[].name` | string | 是 | 创建后的工具名称。 |
| `items[].description` | string | 否 | 工具说明。 |
| `items[].input_schema` | object | 否 | 工具输入 Schema。 |
| `items[].output_schema` | object | 否 | 工具输出 Schema。 |
| `items[].tags` | string（字符串数组） | 否 | 工具标签。 |
| `items[].category` | string | 否 | 工具分类。 |

:::::
::::::
:::::::

## 成功响应

成功时返回 `200` 和创建结果。

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} 响应示例

```json
{"code":0,"data":{"items":[]}}
```

:::::
:::::{tab-item} 字段说明

::::{tab-set}

:::{tab-item} 列表数据

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `data.items` | array | 批量创建结果。 |

:::

::::

:::::
::::::
:::::::

## 错误响应

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} 响应示例

```json
{"code":2,"message":"invalid request"}
```

:::::
:::::{tab-item} 字段说明

::::{tab-set}
:::{tab-item} 通用字段

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `code` | integer | 错误代码。 |
| `message` | string | 面向调用者的错误信息。 |

:::
::::

:::::
::::::
:::::::
