增加 SuperAgent MCP 内嵌接口和配置文档

This commit is contained in:
andy
2026-07-09 17:49:53 +08:00
parent a2119a8d06
commit e12bfd77e1
25 changed files with 2236 additions and 0 deletions

View File

@@ -0,0 +1,445 @@
# TH Hotel SuperAgent MCP Tools 契约
## 1. 文档信息
| 项目 | 内容 |
| --- | --- |
| 文档版本 | 0.1 |
| 日期 | 2026-07-09 |
| 状态 | 草案 |
| 适用范围 | SuperAgent 可调用的 TH Hotel MCP tools |
## 2. 通用约定
内嵌 MCP endpoint 对 SuperAgent 暴露工具,并在当前 Spring Boot 进程内直接调用已有业务 Service。
通用默认值:
| 字段 | 默认值 | 中文说明 |
| --- | --- | --- |
| `source_provider` | `AGENTBUS` | 来源提供方 |
| `source_channel` | `EMAIL` | 来源渠道 |
通用返回建议:
```json
{
"success": true,
"request_id": "req-from-backend-or-mcp",
"trace_id": "trace-from-superagent",
"data": {},
"warnings": [],
"error": null
}
```
中文说明:
- 只读查询工具优先保持后端查询响应 envelope。
- 写入工具保持后端任务结果响应的业务字段。
- MCP tool result 中可以同时提供机器可读结构化数据和简短中文摘要。
- 如果业务 Service 返回受控错误MCP endpoint 应把错误码和中文 message 保留到结构化结果中。
## 3. Tool: th_hotel_query_case_context
### 3.1 用途
查询订单上下文,用于判断当前邮件提到的 group、confirmation 或 reservation key 是否已经存在、
是否存在未完成任务,以及是否可以创建新任务。
### 3.2 何时使用
- SuperAgent 识别出 `group_code``confirmation_number``reservation_no` 后。
- 需要判断当前邮件应新建任务、更新已有对象、取消对象或进入人工复核时。
### 3.3 不应使用
- 不应把该工具当作全文搜索。
- 不应使用历史邮件中不确定的 key 直接创建业务结论。
### 3.4 输入 Schema
```json
{
"type": "object",
"additionalProperties": false,
"properties": {
"hotel_id": {
"type": "string",
"description": "酒店上下文 ID"
},
"group_code": {
"type": ["string", "null"],
"description": "Group / Allotment 查询 key"
},
"confirmation_number": {
"type": ["string", "null"],
"description": "FIT confirmation number 查询 key"
},
"reservation_no": {
"type": ["string", "null"],
"description": "OPERA reservation no"
},
"object_type_hint": {
"type": ["string", "null"],
"description": "调用方推测的对象类型"
},
"target_key_source": {
"type": ["string", "null"],
"description": "key 来源,例如 body_current 或 body_thread_evidence"
},
"body_thread_used_only_as_evidence": {
"type": "boolean",
"description": "历史线程 key 是否仅作为证据"
}
},
"required": ["hotel_id"]
}
```
补充约束:`group_code``confirmation_number``reservation_no` 至少一个非空。
### 3.5 输出
输出对应 REST 接口:
```text
POST /api/ai-query/v1/case-context
```
核心字段:
- `matched_order_records[]`:匹配到的订单。
- `pending_or_open_tasks[]`:未完成或可见任务。
- `target_object_validation`:是否允许创建、更新、取消或附加凭证。
- `warnings[]`:缺少 OPERA 投影等限制。
完整字段以 `superagent-api-contract.md` 第 4 节为准。
## 4. Tool: th_hotel_query_object_detail
### 4.1 用途
查询指定对象详情。第一版主要用于查询 `ORDER:{order_id}` 对象。
### 4.2 何时使用
- 已通过上下文查询拿到 `object_id`
- 需要查看订单状态、业务 key、可更新/可取消状态或已知字段。
### 4.3 输入 Schema
```json
{
"type": "object",
"additionalProperties": false,
"properties": {
"hotel_id": {
"type": "string",
"description": "酒店上下文 ID"
},
"object_id": {
"type": "string",
"description": "查询对象 ID第一版支持 ORDER:{order_id}"
},
"object_type": {
"type": ["string", "null"],
"description": "调用方对象类型提示"
}
},
"required": ["hotel_id", "object_id"]
}
```
### 4.4 输出
输出对应 REST 接口:
```text
POST /api/ai-query/v1/object-detail
```
核心字段:
- `object_id`:对象 ID。
- `order_id`:订单内部 ID 字符串。
- `group_code``confirmation_number``reservation_no`:业务 key。
- `status`:订单状态。
- `can_update``can_cancel`:可操作状态。
- `hard_validation_warnings[]`:硬校验提示。
说明:该响应中的 `source_message_id` 当前是本系统内部 SourceMessage Inbox ID不应作为
SuperAgent 提交任务结果时的外部 `source_message_id`
完整字段以 `superagent-api-contract.md` 第 5 节为准。
## 5. Tool: th_hotel_list_message_conversation_tasks
### 5.1 用途
查询某个邮件会话下已经生成的所有任务,避免 SuperAgent 对同一邮件链重复拆同类任务。
### 5.2 何时使用
- 当前邮件属于一个已有邮件会话。
- 需要判断历史邮件是否已经生成任务。
- 需要按时间顺序查看同一邮件链上的任务进展。
### 5.3 输入 Schema
```json
{
"type": "object",
"additionalProperties": false,
"properties": {
"hotel_id": {
"type": "string",
"description": "酒店上下文 ID"
},
"source_provider": {
"type": ["string", "null"],
"description": "来源提供方,默认 AGENTBUS"
},
"source_channel": {
"type": ["string", "null"],
"description": "来源渠道,默认 EMAIL"
},
"external_conversation_id": {
"type": ["string", "null"],
"description": "外部邮件会话 ID"
},
"source_message_id": {
"type": ["string", "null"],
"description": "外部来源消息 ID可作为锚点反查会话"
}
},
"required": ["hotel_id"]
}
```
补充约束:
- `external_conversation_id``source_message_id` 至少一个非空。
- 两者同时传入时,后端按 `external_conversation_id` 查询为准。
- 查询按 `hotel_id + source_provider + source_channel + external_conversation_id` 隔离。
### 5.4 输出
输出对应 REST 接口:
```text
POST /api/ai-query/v1/message-conversation/tasks
```
排序规则:
1. 先按邮件接收时间正序。
2. 同一封邮件下按任务创建时间正序。
3. 时间相同时按任务 ID 正序。
核心字段:
- `task_count`:任务数量。
- `tasks[].external_source_message_id`:外部来源消息 ID。
- `tasks[].task_id`:任务 ID。
- `tasks[].task_status`:任务状态。
- `tasks[].system_task_type`:系统任务类型。
- `tasks[].task_created_at`:任务创建时间。
完整字段以 `superagent-api-contract.md` 第 6 节为准。
## 6. Tool: th_hotel_list_message_conversation_messages
### 6.1 用途
查询邮件会话下所有受控正文,供 SuperAgent 在需要历史上下文时读取。
### 6.2 何时使用
- 当前邮件需要结合历史邮件判断。
- 需要给业务人员后续展示原文能力预留接口证据。
- 需要按时间顺序读取邮件链正文。
### 6.3 安全边界
该工具不返回:
- 原始未清洗 HTML。
- 附件 URL。
- 内嵌图片 URL。
- `attachments``inline_images``external_url`
- HTML 中的 `href/src` 外链属性。
后端读取正文时会写 SourceMessage 原文访问审计。
### 6.4 输入 Schema
输入字段与 `th_hotel_list_message_conversation_tasks` 相同:
```json
{
"type": "object",
"additionalProperties": false,
"properties": {
"hotel_id": {
"type": "string",
"description": "酒店上下文 ID"
},
"source_provider": {
"type": ["string", "null"],
"description": "来源提供方,默认 AGENTBUS"
},
"source_channel": {
"type": ["string", "null"],
"description": "来源渠道,默认 EMAIL"
},
"external_conversation_id": {
"type": ["string", "null"],
"description": "外部邮件会话 ID"
},
"source_message_id": {
"type": ["string", "null"],
"description": "外部来源消息 ID可作为锚点反查会话"
}
},
"required": ["hotel_id"]
}
```
### 6.5 输出
输出对应 REST 接口:
```text
POST /api/ai-query/v1/message-conversation/messages
```
核心字段:
- `message_count`:邮件数量。
- `messages[].external_source_message_id`:外部来源消息 ID。
- `messages[].received_at`:邮件接收时间。
- `messages[].text_body`:纯文本正文。
- `messages[].html_body_sanitized`:清洗后的 HTML。
- `messages[].html_render_mode`HTML 渲染模式。
完整字段以 `superagent-api-contract.md` 第 7 节为准。
## 7. Tool: th_hotel_submit_task_results
### 7.1 用途
提交 SuperAgent 对单封外部来源消息的 AI 任务识别结果。该工具会写入 AI 过渡层、订单、任务和任务卡。
### 7.2 何时使用
- SuperAgent 已完成当前邮件的最终任务拆分。
- 已确认 `hotel_id` 和外部 `source_message_id` 来自 AgentBus payload。
- 需要把 AI 任务结果交给 TH Hotel 后端进入人工确认流程。
### 7.3 不应使用
- 不应在试探、草稿、未完成推理阶段调用。
- 不应把历史邮件中的外部来源消息 ID 当作当前邮件 ID 提交。
- 不应在缺少 `hotel_id``source_message_id` 时调用。
### 7.4 输入 Schema
```json
{
"type": "object",
"additionalProperties": false,
"properties": {
"hotel_id": {
"type": "string",
"description": "酒店上下文 ID"
},
"source_provider": {
"type": ["string", "null"],
"description": "来源提供方,默认 AGENTBUS"
},
"source_channel": {
"type": ["string", "null"],
"description": "来源渠道,默认 EMAIL"
},
"source_message_id": {
"type": "string",
"description": "外部来源消息 ID对应 AgentBus source.external_message_id"
},
"ai_task_results": {
"type": "array",
"description": "AI 拆分出的任务结果,必须保留数组顺序",
"items": {
"type": "object"
}
},
"extraction_warnings": {
"type": "array",
"description": "AI 抽取警告",
"items": {
"type": "object"
}
}
},
"required": ["hotel_id", "source_message_id", "ai_task_results"]
}
```
说明:
- `ai_task_results[]` 内部字段较多,完整结构以 `superagent-api-contract.md` 第 8 节为准。
- MCP endpoint 不应重排 `ai_task_results[]`
- 如后续需要强 schema 校验,可在 MCP endpoint 内复制 REST 契约中的细粒度字段约束。
### 7.5 输出
输出对应 REST 接口:
```text
POST /api/integrations/superagent/task-results
```
核心字段:
- `batch_id`:批次 ID。
- `idempotent_replay`:是否幂等重放。
- `accepted_count`:接收数量。
- `items[].ai_transition_id`AI 过渡层 ID。
- `items[].order_id`:订单 ID。
- `items[].task_id`:任务 ID。
- `items[].task_status`:任务状态。
完整字段以 `superagent-api-contract.md` 第 8 节为准。
## 8. 错误处理约定
MCP endpoint 应保留业务错误信息:
```json
{
"success": false,
"request_id": "req-001",
"trace_id": "trace-001",
"data": null,
"warnings": [],
"error": {
"code": "AUTH_SIGNATURE_INVALID",
"message": "签名校验失败。",
"details": {}
}
}
```
常见错误码以 `superagent-api-contract.md` 第 9 节为准。
MCP 层新增错误建议:
| 错误码 | 中文说明 |
| --- | --- |
| `MCP_AUTH_INVALID` | MCP 层访问凭证缺失或无效 |
| `MCP_TOOL_DISABLED` | 工具未启用,例如生产临时关闭写入工具 |
| `MCP_REQUEST_INVALID` | MCP JSON-RPC 请求体不合法 |
| `MCP_REQUEST_BODY_TOO_LARGE` | MCP 请求体超过 10MB 默认限制或环境配置限制 |
| `MCP_METHOD_NOT_FOUND` | MCP 方法不存在 |
| `MCP_TOOL_NOT_FOUND` | MCP 工具不存在 |
| `MCP_INTERNAL_ERROR` | MCP endpoint 内部异常 |