> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oasm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AI 智能体与 MCP

> AI Studio 智能体和外部 MCP 客户端如何通过 query_attack_surface 工具读取你的攻击面

[AI Studio](https://docs.oasm.io/zh/ai-studio/overview.md) 智能体和 [MCP 服务器](https://docs.oasm.io/zh/settings/mcp.md)通过 Attack Surface Query 读取攻击面。用自然语言提问，例如 *"我有哪些目标？"*、*"api.example.com 上暴露了什么？"*、*"哪些主机提供 HTTP 但没有 HTTPS？"*、*"按严重漏洞数量对我的主机排序"*，智能体会自动编写查询。

## 工具

| 工具 | 作用 |
| - | - |
| `query_attack_surface` | 运行一批查询（与 `POST /api/attack-surface/query` 的 JSON 相同），外加可选的 `projectId` |
| `describe_attack_surface` | 列出调用方可读取的资源、字段、运算符和关系 |

两者都是只读工具，因此即使在手动审批模式下也无需审批即可运行。在 **Agent** 模式下，与所有工具一样，它们会在已批准计划的某个步骤进行中时运行。

`query_attack_surface` 取代了之前按主题划分的查询工具。仍然引用旧工具名的智能体定义和设置可以继续使用：这些名称现在都指向 `query_attack_surface`。

| 旧工具 | 现在 |
| - | - |
| `retrieve_targets` | `from: "targets"` |
| `enumerate_assets`、`examine_target_assets`、`inspect_asset` | `from: "hosts"` 或 `"services"`（按 `target.value`、`value` 或 `id` 过滤） |
| `list_network_ports` | `from: "services"` |
| `fingerprint_technologies` | `from: "technologies"` |
| `verify_tls_settings` | `from: "tls"` |
| `discover_vulnerabilities` | `from: "vulnerabilities"` |

> [!NOTE]
>
> 单个漏洞的完整详情（描述、概念验证、修复建议、证据、时间线）仍由 `investigate_vulnerability` 提供，仪表盘评分和趋势仍由 `gather_statistics` 提供。

## 智能体如何学习查询语言

* **工具描述**包含规则以及每种资源的确切字段名，它们由服务器校验所用的同一份目录生成，因此模型无需猜测字段名。
* **`attack-surface-query` 技能**（参见[技能](https://docs.oasm.io/zh/ai-studio/settings/skills.md)）讲解完整的语言：运算符、时间、聚合、分页、限制、错误及其修复方法，并附带现成的查询示例。智能体在每次对话的首次查询前加载它，所有内置智能体都声明了该技能。
* **错误信息是为模型编写的**：未知字段会列出该资源的有效字段，不可分组的字段会列出可分组的字段，超出预算的查询会说明需要修改什么。智能体会修正整个调用并重新发送一次。

## 权限和范围

* 智能体代表发起对话的成员执行操作：每种资源都需要该成员具备读取权限（`asset.read`、`vulnerability.read`、`target.read`）。
* **项目对话**会将所有查询锁定在该项目的资产内；模型传入的 `projectId` 无法越出该范围。
* 在 **MCP 服务器**上，由于使用工作区 API 密钥进行身份验证且没有对应成员，该工具以 `asset.read`、`vulnerability.read` 和 `target.read` 权限读取数据。

## 限制

智能体和 MCP 客户端的限制比 API 更严格：每次调用 5 个查询、每个查询 200 行、3 个 include、每个 include 20 个子项、每个过滤器 20 个条件、每条语句 3 秒、每个响应 64 KB，并且不包含大型 HTTP 字段（`body`、headers）。它们不能使用报告模式。语言的其他功能同样可用：嵌套过滤、关系测试、条件聚合、`having` 以及补全的时间序列。参见[分页、限制与成本](https://docs.oasm.io/zh/attack-surface-query/paging-and-limits.md#limits)。

## 在 MCP 客户端中使用

按照 [MCP 服务器](https://docs.oasm.io/zh/settings/mcp.md)中的说明连接客户端，然后让助手调用 `describe_attack_surface` 和 `query_attack_surface`。一次调用如下所示：

```json theme={null}
{
  "queries": {
    "exposed": {
      "from": "services",
      "select": ["host.value", "port", "http.title"],
      "where": { "logic": "and", "items": [{ "field": "port", "op": "in", "value": ["3389", "445", "6379"] }] }
    }
  }
}
```

查询错误会作为普通结果返回，即 `{ "error": { "code", "message", "issues", "hints" } }`，因此助手可以读取错误并重试。

> [!WARNING]
>
> MCP 服务器上已不再提供旧的工具名（`enumerate_assets`、`retrieve_targets` 等）。调用过它们的 MCP 客户端或脚本必须改用 `query_attack_surface`。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.