# forAgent()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/mcp/for-agent/
Language: zh

`api.mcp.forAgent(names?) → Promise<Server[]>`

引擎已准备就绪的服务器: 允许的工具和标记。 这是 agents.create({ mcp }) 读物——你很少自己称呼它。

Status: tokens included · null means all · [] means none

```javascript
await api.mcp.forAgent();            // every connected server
await api.mcp.forAgent(["example"]); // these
await api.mcp.forAgent([]);          // none — and no request is made
```

## 和[]是不同的,两者都有用 {#null-vs-empty}

| 通过 | 含义 |
| --- | --- |
| `null` 或无 | 每个连接服务器 |
| `["a", "b"]` | 这两人 |
| `[]` | 毫无保留,它立即返回,没有问。 |

> **保持警戒**
>
> 只有允许的工具才能出来, 所以每个服务器都取走不是它听起来像打开的门。 一个没有允许的服务器不会贡献任何东西 。

## 带有标志 {#tokens}

引擎需要他们联系每个服务器, 所以这是包括它们在内的列表。 他们被解密给认证的所有人, 其他人也不要—— 不要记录返回的内容 。

## 探员给你读了 {#agent}

```javascript
api.agents.create({ runtime: "local", machine: pc, model, mcp: ["example"] });
// mcp absent  → every connected server
// mcp: []     → none
```

每次运行开始时都会重新读取, 因此从另一个窗口连接到服务器, 无需重新启动软件包的维持 。

## 何时直接呼叫 {#when-yourself}

当你在制造引擎的工具时 使自己塑造自己 `createMcpTools()` 精确地取回返回的 。 单是声明, [() 工具](/zh/sdk/ref/mcp/tools) 是使用该工具的。

- [createMcpTools()](/zh/sdk/ref/mcp-client/create-mcp-tools): 是什么消耗了这些。
- [选项 · 工具与库](/zh/sdk/ref/agents/options/tools): 选择 mcp 选项 。
- [api.mcp](/zh/sdk/ref/mcp): 连接、列出和使用服务器。

```python
api.mcp.for_agent()              # every connected server
api.mcp.for_agent(["example"])   # these
api.mcp.for_agent([])            # none — and no request is made
```

```python
api.agents.create(runtime="local", machine=pc, model=model, mcp=["example"])
# mcp absent → every connected server
# mcp=[]     → none
```
