# connect()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/mcp/connect/
Language: zh

`api.mcp.connect({ url, name?, token?, tools?, category?, label? }) → Promise<Server>`

检查地址,握手,阅读服务器的工具,并保存连接。按此顺序,四个步骤,顺序是安全。

Status: check, then contact · https only · no tool allowed by default

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `url` | string | 必填 | 服务器的地址 **仅限https。** |
| `name` | string |  | 名字在这里,不在时从域名中提取 |
| `token` | string |  | 访问标记, 以其他方式加密, 从未插入 URL. |
| `tools` | string[] | none | **允许使用哪些工具 。** 没有这份清单,就没有一份清单。 |
| `category` | string | exec | `read` · `write` · `exec` - 允许其工具携带。 |
| `label` | string |  | 显示名称。 |

## 四步四步 {#order}

- 地址由平台——计划加以检查,并解决公开讲话的问题。
- 软件包与检查过的地址握手,谈判修改。
- 它读取服务器的工具列表。
- 连接已保存, 与目录和已商定的修改 。

> **支票在包裹触碰任何东西之前就来**
>
> 在应用程序中,软件包通常运行在您的服务器上。一个未加控制的地址可以是网络内部的地址,可以要求地址指向地址所在的地方,也可以将答案交回。首先检查是什么使输入的地址能够安全地被接受。

## 不允许任何东西, 除非列出 {#tools}

```javascript
// Connected, and completely inert — no tool is allowed
await api.mcp.connect({ url, name: "example" });

// Two tools, read-only
await api.mcp.connect({ url, name: "example", tools: ["search_docs", "get_issue"], category: "read" });
```

每一个转弯都有一个申报成本的代号, 所以一个提供 90 个工具的服务器 将会为每步运行增加固定成本, 无需任何人要求。 连接第一, 然后再选择 [(更新)](/zh/sdk/ref/mcp/update) 通常的形状。

## 故意故意违约 {#category}

协议带有只读提示, 但服务器会声明它本身 。 `exec` 使用工具的方式要求使用每种方式,但必须完全使用—— 设置 `read` 只有当你知道工具的作用时

## 牌子清干净一次 {#token}

周围空间、报价和复制的“ Bearer ”被移除——它们使一些服务器拒绝信头,而从未读过信物。 *内* 被拒绝而非补丁: 猜想哪个象征比说这更糟糕。

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| url_required | 400 | 无地址。 |
| url_not_https | 400 | 普通的 http 会发送未加密的代号 。 |
| url_blocked | 400 | 地址不公开解决。 |
| mcp_token_malformed | 400 | 象征性含有一个空间 。 |
| mcp_token_required · mcp_unauthorized | 401 | 服务器想要一个标记, 或者拒绝给定的标记 。 |
| mcp_redirect | 502 | 服务器以重定向回应, 从未被跟踪 。 |
| mcp_protocol_unsupported | 502 | 没有共同的修订。 |
| mcp_unreachable · mcp_timeout | 502 □ 504 | 无法及时答复。 |

- [地址检查](/zh/sdk/mcp/address-check): 支票是做什么的? 支票是做什么的?
- [允许的工具](/zh/sdk/mcp/allowed-tools): 为什么没有默认允许?
- [错误](/zh/sdk/mcp/errors): 每一个代码和该如何处理它。

```python
# Connected, and completely inert — no tool is allowed
api.mcp.connect(url=url, name="example")

# Two tools, read-only
api.mcp.connect(url=url, name="example", tools=["search_docs", "get_issue"], category="read")
```
