Files
market/skills/using-services/SKILL.zh-CN.md
T
yige 23b4124dc4 fix: using-services 先认出本 Agent 已接入的 MCP 服务端 / Recognize this Agent's own MCP servers before the catalog (#292)
## 中文

用户直接点名一个服务(如「用 xxx 这个服务」)时,这个服务常常就是本 Agent 已接入的 MCP 服务端。`using-services`
1.0.4 只讲如何查全局「应用与服务」目录,模型会先去目录和市场里找,绕一大圈才回到自己的 MCP 工具。

更新至 1.1.0:

- 描述把适用范围写在最前:本 Agent 已接入的 MCP 服务端不用本技能,按服务端 ID 用 `ToolCatalog`
检索其工具。技能目录只显示描述开头,三段描述都在 80 token 以内,能整段显示。
- 新增 Step 0:先看系统提示词里是否列出本轮可用的 MCP 服务端(较新的客户端才有,写成条件句);用
`ToolCatalog(query="<服务端 ID>")` 检索,检索不支持 `<ID>__*`
这类通配;工具名与加载方式以结果为准;不为确认接入情况去读配置文件或配置接口,因为 MCP 配置里的环境变量和请求头可能含明文凭据。
- Step 4 第 3 条改写:接入后工具注册为 `<serverId>__<工具名>`,名字不合规时模型看到的是改写后的名字,不要按习惯猜。
- 不写死加载工具的名字,也不设客户端下限:按服务端 ID 用 `ToolCatalog`
检索、按结果给出的方式加载,在现有各版本客户端上都成立。
- 同步目录元数据(描述、版本、更新日期);英文改为人工维护并刷新 `source_hash`,避免被自动翻译覆盖。

验证:中英标题数一致(15/15);`source_hash` 按 `scripts/i18n/translate.py`
的同一算法复算;`git diff --check` 通过;对改动做了语义审阅,无客户、伙伴或其他私有标识。本机没有 uv,目录与 i18n
校验以本 PR 的 CI 为准;私有词表的公开信息扫描未在本机运行。客户端 seed 将在本 PR
合入后单独更新。客户端侧配套改动(自我认知列出本轮的 MCP 服务端、`ToolCatalog` 按服务端 ID 整段命中)在
DesireCore 主仓单独提交,本技能不依赖它。

## English

When a user names a service ("use the xxx service"), it is often one of
this Agent's own MCP servers. `using-services` 1.0.4 only explained how
to search the global Apps & Services catalog, so the model searched the
catalog and marketplace first and took a long detour before reaching its
own MCP tools.

Version 1.1.0:

- The description now states the scope up front: this Agent's own MCP
servers do not need this skill; search `ToolCatalog` by the server ID
instead. The skill catalog shows only the start of a description, and
all three descriptions are under 80 tokens, so they are shown in full.
- New Step 0: check whether the system prompt lists this turn's MCP
servers (only newer clients have it, so the step is conditional); search
`ToolCatalog(query="<server ID>")`, which has no wildcard such as
`<ID>__*`; use the tool names and load method from the result; do not
read config files or config endpoints to confirm, because MCP
environment variables and headers may hold plaintext credentials.
- Step 4, item 3 rewritten: connected tools are registered as
`<serverId>__<toolName>`, and the model sees a rewritten name when that
breaks naming rules, so do not guess names.
- No hard-coded loader tool name and no minimum client version:
searching `ToolCatalog` by server ID and loading as the result says
holds on all current client versions.
- Catalog metadata synchronized (descriptions, version, date); English
is now human-maintained with a refreshed `source_hash`, so automatic
translation does not overwrite it.

Validation: heading counts match (15/15); `source_hash` recomputed with
the same algorithm as `scripts/i18n/translate.py`; `git diff --check`
passed; changes reviewed semantically with no customer, partner or other
private identifiers. uv is not installed locally, so catalog and i18n
validation rely on this PR's CI; the private-token public-information
scan was not run locally. The client seed will be updated in a separate
PR after this merges. The companion client change (self-awareness lists
this turn's MCP servers; `ToolCatalog` matches a whole server ID) goes
to the DesireCore main repository separately; this skill does not depend
on it.
2026-11-17 21:04:26 +08:00

6.1 KiB
Raw Blame History

使用服务(using-services)

原生应用与对外协议

DesireCore Control 是供外部智能体使用的 native-app,不是已经安装的内部 MCP 服务。看到它的管理页或对外 /mcp 端点,不代表本 Agent 获准通过 using-services 调用、注册它或绕过 GUI 审批。应用生命周期使用 app-install-manager(1.5.2 或更新版本),运行时 GUI 接管使用受治理的 ControlDesireCoreGui。应用安装不得生成内部服务或 svc-* 技能。

L0:一句话总结

教会 Agent 如何从全局"应用与服务目录"里查找并正确调用服务。

L1:概述

"应用与服务目录"存放所有已注册的 HTTP/MCP 服务。本元技能是你的 使用手册: 帮你 找到 合适的服务、正确 调用它。每个非平凡的注册服务还会自动生成 专属 svc-<id> Skill —— 优先用专属技能;本元技能是临时发现的兜底。

何时使用

  • 用户让你做某件事,目录里可能有现成服务(如"搜产品库"、"发通知")
  • 你看到可用技能里有 svc-<id> —— 直接激活它
  • 你打算调用一个 HTTP API,想先查目录,借力治理、凭据注入和审计

何时不要用

  • 用户给了一次性 URL —— 直接 HttpRequest 即可
  • 你已激活了 svc-<id> 专属 Skill —— 跟着它走,更具体
  • 用户点名的服务已是本 Agent 接入的 MCP 服务端 —— 按 Step 0 直接找到它的工具,不必查目录

L2:如何发现并调用

Step 0 — 先确认是不是本 Agent 已接入的 MCP 服务端

用户点名的服务(如「用 xxx 这个服务」)可能就是本 Agent 已接入的 MCP 服务端,服务端 ID 就是接入时用的名字。这时不需要查目录:

  1. 系统提示词里若列出了本轮可用的 MCP 服务端(较新的客户端才有这一段),先在其中核对;没有这一段不代表没有接入。
  2. 用 ToolCatalog 按服务端 ID 检索,例如 ToolCatalog(query="<服务端 ID>", max_results=20)。query 只写 ID 本身,不要写 <ID>__* 这类通配:检索不支持通配,会一个都查不到。返回条数等于 max_results 时可能还有更多,调大后再查。
  3. 命中后以结果里的工具名为准,不要按命名习惯拼名字(见 Step 4 第 3 条)。结果标明某个工具尚未声明时,按结果给出的加载方式加载,下一次模型请求起再调用;查到的是该服务端的认证工具时,按它的说明先完成认证。到这里就不必继续本技能。
  4. 查不到时再从 Step 1 查目录。

确认接入情况只用以上方式,不要为此读取本 Agent 的配置文件或配置接口:MCP 配置里的环境变量和请求头可能含明文凭据。

Step 1 — 列目录

拉取注册表:

tool: HttpRequest
parameters:
  url: http://127.0.0.1:<agent-service-port>/api/registry/services
  method: GET

响应(节选):

{
  "data": {
    "services": [
      {
        "id": "acme-search-api",
        "name": "Acme 搜索 API",
        "protocol": "http",
        "endpoint": "https://api.acme.example/search",
        "tags": ["search", "products"],
        "status": "online",
        "origin": "agent",
        "reviewStatus": "approved",
        "riskLevel": "medium",
        "operations": [...]
      }
    ],
    "total": 1,
    "source": "official"
  }
}

Step 2 — 选候选

按 tags、protocol、name 过滤。调用 前 必须检查:

  • status === 'online' → 可以调
  • status === 'offline' / 'error' → 告诉用户服务下线,别 盲目重试
  • status === 'degraded' → 降级使用,告诉用户
  • reviewStatus === 'pending'(仅 origin='agent')→ 只有当 registeredBy 就是你自己时才能调;否则请用户在 Store UI 提升后再用
  • riskLevel === 'critical' → 每次调用都会触发人类审批

Step 3 — 构造请求(HTTP 服务)

如果服务声明了 operations,优先用 —— 它们是稳定契约点。URL 拼成 <endpoint><operation.path>。

tool: HttpRequest
parameters:
  url: https://api.acme.example/search/v1/items?q=widget
  method: GET
  headers:
    Authorization: "Bearer ${secrets/api-keys/acme}"   # 调用时解引用

如果服务带 auth.secretRef,不要 在聊天里向用户索要明文凭据。 HttpRequest 工具会自动解引用。

Step 4 — 构造请求(MCP 服务)

MCP 服务不走 HttpRequest,它通过 Agent 的 mcp_servers 配置暴露成工具:

  1. 若你的 Agent 还没接入该 MCP,POST http://127.0.0.1:<agent-service-port>/api/agents/<your-id>/mcp-servers 传 { serverId: '<service.id>', config: <connection> }
  2. 下轮 query 时 MCP discovery 会自动暴露该服务器的工具
  3. 接入生效后,工具在本 Agent 的工具池里注册为 <serverId>__<工具名>;名字不符合模型接口的字符或长度要求时,模型看到的是改写后的另一个名字。所以不要按远端声明名或命名习惯猜调用名:按 Step 0 用 ToolCatalog 以服务端 ID 检索,以结果里的名字为准;结果标明未声明的,按结果给出的加载方式加载后再调用。

Step 5 — 处理响应

  • 2xx → 解析使用
  • 4xx → 多半是客户端错(参数错、缺鉴权);修好后可重试一次,仍失败就告诉用户
  • 5xx → 服务端问题,把目录里的 status 一并告诉用户
  • service-approval 拒绝 → 响应里会有 "decision":"rejected";不要重试,问用户怎么办

Step 6 — 不要绕开目录

如果目录里有该服务,就用目录。直接调未声明的 URL 虽然 HttpRequest 也能成功,但你会失去:

  • 高风险操作的审批闸门
  • 凭据注入(你得自己问用户要 key)
  • 审计追踪与 lastUsed 统计
  • 其他 Agent 复用你的调用模式

常见失败模式

  • 目录读取失败:降级直接 HttpRequest,并告诉用户已绕开治理。
  • 没匹配上:问用户要不要 注册 一个新的 —— 激活 registering-services。
  • status === 'offline':汇报情况,建议检查底层服务,不要 强行调用。