# Servers

Servers 把 AgentTeam Desktop 连接到 AgentTeam server workspace。一个 AgentTeam server 连接负责接收入站 AgentTeam 消息、发送 Agent 出站消息，并向本地 runtime 暴露受限 MCP 工具。

## 支持的连接

每个 server 连接都有稳定 ID、enabled 状态、可选显示名称、描述、可选绑定 Agent、server URL、workspace ID、machine ID 和 machine API key。

## Agent 路由

普通 AgentTeam 消息中，dispatcher 按以下顺序解析目标 Agent：

1. 显式消息目标，包括 AgentTeam server 指定的 Agent ID
2. 当前会话的 `/agent` override
3. server 级 Agent 绑定
4. 配置中的 `default_agent`

Slash command 会在普通 dispatch 之前处理。

## Dashboard 工作流

Servers 页可以：

- 查看 AgentTeam server 连接的 enabled 状态、Agent 绑定和近期流量统计
- 添加 AgentTeam server 连接
- 编辑名称、描述、enabled 状态和 Agent 绑定
- 查看 server 连接暴露的 MCP 工具
- 删除 server 连接

server 工具接口：

```text
GET /api/internal/servers/:id/tools
```

## AgentTeam server 连接

推荐的 machine 接入路径：

```bash
agentteam daemon --server-url https://agentteam.pingcap.com --api-key <machineApiKey>
```

该命令会保存或更新 AgentTeam server auth，并在需要时启动 daemon。重连一个 AgentTeam server 不会禁用本地已有的其他 enabled AgentTeam server 连接。

也可以显式添加额外 AgentTeam server auth：

```bash
agentteam channel add --agentteam.server-url https://agentteam.pingcap.com --agentteam.api-key <key>
```

AgentTeam 协议中的 agent start/stop/sleep、workspace scan/read/delete/reset、recovery restore、recovery artifact cleanup 等命令都在 AgentTeam server 连接内部处理。只有 `agent:deliver` 用户消息会转发给 dispatcher。

## CLI

`agentteam auth` 是主要用户入口：

```bash
agentteam auth login --server-url https://agentteam.pingcap.com --api-key <machine-api-key>
agentteam auth status
agentteam auth logout <server-id>
```

隐藏 legacy `agentteam channel` 命令仍可供旧脚本使用：

```bash
agentteam channel list
agentteam channel list -f json
agentteam channel get <id>
agentteam channel add [name] --agentteam.server-url <url> --agentteam.api-key <key>
agentteam channel update <id> --agent <agent-id>
agentteam channel delete <id>
agentteam channel rm <id>
agentteam channel enable <id>
agentteam channel disable <id>
```

`channel list` 和 `channel get` 支持 `--format/-f table|json|jsonc|yaml|toml`。
