feiguazhitou-mcp-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,278 @@
1
+ import { CATALOG_STALE_AFTER_MS, COMMAND_NAME, DEFAULT_ENDPOINT, DEFAULT_TIMEOUT_MS, ENV, MAX_TIMEOUT_MS, RECOMMENDED_RPA_TIMEOUT_MS, } from "./constants.js";
2
+ import { outputLanguage, t } from "./i18n.js";
3
+ export const DESCRIBE_PROTOCOL = "feiguazhitou-mcp-cli.describe/v1";
4
+ export const DESCRIBE_PROTOCOL_VERSION = 1;
5
+ function commandDocument() {
6
+ const timeoutAppliesTo = outputLanguage() === "zh"
7
+ ? ["MCP schema 发现", "MCPorter 生成", "生成的 MCPorter 工具调用"]
8
+ : ["MCP schema discovery", "MCPorter generation", "generated MCPorter tool call"];
9
+ return {
10
+ protocol: DESCRIBE_PROTOCOL,
11
+ protocolVersion: DESCRIBE_PROTOCOL_VERSION,
12
+ role: t("单实例飞瓜智投 MCP 启动器与已生成工具目录。", "Single-instance Feiguazhitou MCP launcher and generated tool catalog."),
13
+ runtimeEnvironment: {
14
+ required: [],
15
+ optional: [ENV.endpoint, ENV.apiKey, ENV.headers, ENV.autoApprove, ENV.token, ENV.timeout, ENV.dataDirectory, ENV.language],
16
+ defaults: { endpoint: DEFAULT_ENDPOINT },
17
+ credentialRule: t("环境变量值只在运行时使用。Agent 默认使用 config set header HEADER --value-stdin 将用户提供的单个 Header 保存到本机未加密凭据文件;用户要求不保存时,Agent 改为 config unset header 与 config set header-env。实际 Header 值不会写入普通配置、目录、生成产物或命令输出。", "Environment variable values are runtime-only. By default, an Agent uses config set header HEADER --value-stdin to save one user-provided Header in a local unencrypted credential file. When the user opts out, the Agent uses config unset header and config set header-env instead. Actual Header values never enter ordinary config, catalogs, generated artifacts, or command output."),
18
+ },
19
+ configuration: {
20
+ endpoint: {
21
+ command: `${COMMAND_NAME} config set endpoint URL`,
22
+ rule: t("Agent 从用户选定的 MCP server 中识别当前 CLI 可用的 endpoint 后,单独设置 endpoint。", "After identifying the endpoint supported by the current CLI from the user-selected MCP server, the Agent sets the endpoint separately."),
23
+ },
24
+ header: {
25
+ persistentCommand: `${COMMAND_NAME} config set header HEADER --value-stdin`,
26
+ inputRule: t("Header 值必须只通过标准输入提供,不能出现在命令行参数中。", "A Header value must be supplied only through standard input, never in a command-line argument."),
27
+ defaultPersistence: true,
28
+ defaultRule: t("用户未选择时,Agent 默认逐个保存配置中的 Header。CLI 会报告本机未加密保存;支持 POSIX 权限的系统会限制为当前用户读写。", "When the user has not chosen otherwise, the Agent saves each configured Header by default. The CLI reports local unencrypted storage; systems with POSIX permissions restrict it to the current user."),
29
+ runtimeOnlyRule: t("用户要求不保存时,Agent 对每个 Header 先执行 config unset header HEADER,再执行 config set header-env HEADER ENV_VAR;实际值只放在后续 CLI 进程的环境变量中。", "When the user opts out, for each Header the Agent first runs config unset header HEADER, then config set header-env HEADER ENV_VAR; the actual value exists only in the environment of later CLI processes."),
30
+ },
31
+ approvalMetadata: {
32
+ environmentVariable: ENV.autoApprove,
33
+ rule: t("若用户配置包含 autoApprove,Agent 将原始 JSON 数组放入 FEIGUAZHITOU_CLI_AUTO_APPROVE 的后续 CLI 进程环境。它只标记本地目录,不会发送给 MCP,也不替代高影响操作的明确授权。", "When the user configuration contains autoApprove, the Agent puts its raw JSON array in FEIGUAZHITOU_CLI_AUTO_APPROVE for later CLI processes. It only annotates the local catalog, is never sent to MCP, and does not replace explicit authorization for high-impact actions."),
34
+ },
35
+ standardMcpConfigReference: {
36
+ purpose: t("用户提供的 mcpServers JSON 只供 Agent 理解并逐项配置 CLI;CLI 不接收、不解析整份 MCP 配置,也不会替 Agent 做字段映射。", "A user-provided mcpServers JSON document is only for an Agent to understand and configure the CLI one setting at a time. The CLI does not accept or parse the complete MCP configuration and does not map fields for the Agent."),
37
+ selectionRule: t("存在多个 server 时,Agent 依据用户指定的目标选择;不确定时先询问,不猜测。", "When multiple servers exist, the Agent selects the user-designated target; when uncertain, it asks rather than guessing."),
38
+ forwardCompatibilityRule: t("此说明不是字段白名单。Agent 根据 describe 中当前 CLI 的配置契约识别可映射字段;未知或未来字段保留为参考,不应被拒绝、删除或臆造映射。", "This guide is not a field allowlist. The Agent identifies mappable fields from the current CLI contract in describe; unknown or future fields remain reference information and must not be rejected, discarded, or given an invented mapping."),
39
+ workflow: [
40
+ t("先读取 describe,再理解用户配置。", "Read describe, then interpret the user configuration."),
41
+ t("逐项执行 endpoint、Header 与可选 autoApprove 的对应 CLI 配置或环境变量设置。", "Apply the corresponding CLI configuration or environment setting for endpoint, Headers, and optional autoApprove one item at a time."),
42
+ t("完成配置后显式执行 refresh,再读取 tools list。", "After configuration is complete, explicitly run refresh, then read tools list."),
43
+ ],
44
+ },
45
+ },
46
+ transport: {
47
+ mode: "cli-only",
48
+ directMcpAccess: "prohibited",
49
+ callerRule: t(`调用方不得直接连接本机 MCP endpoint 或通过其他 MCP client 调用工具;只能使用 ${COMMAND_NAME} 的规范命令。`, `Callers must not connect to the local MCP endpoint directly or invoke tools through another MCP client; use only canonical ${COMMAND_NAME} commands.`),
50
+ internalRule: t("CLI 会在内部连接 MCP;该限制仅适用于 CLI 的调用方。", "The CLI connects to MCP internally; this restriction applies only to callers of the CLI."),
51
+ },
52
+ timeout: {
53
+ environmentVariable: ENV.timeout,
54
+ defaultMs: DEFAULT_TIMEOUT_MS,
55
+ recommendedLongRunningMs: RECOMMENDED_RPA_TIMEOUT_MS,
56
+ minimumMs: 1,
57
+ maximumMs: MAX_TIMEOUT_MS,
58
+ appliesTo: timeoutAppliesTo,
59
+ refreshRule: t("生成产物会记录生成时的默认超时。每次 run 都会传入当前超时,因此修改超时后立即生效,不需要 refresh。", "Generated artifacts record their generation-time default timeout. Every run receives the current timeout, so a timeout change takes effect immediately without refresh."),
60
+ executionRule: t("启动器不会重试工具调用。若生成命令在 --output json 模式下失败且没有 stdout(例如超时),启动器返回 JSON 错误文档,并在 error.details.stderr 中逐字保留生成命令的原始错误。", "The launcher does not retry tool calls. If a generated command fails without stdout in --output json mode (for example, a timeout), the launcher returns a JSON error document and preserves the generated command's raw error verbatim in error.details.stderr."),
61
+ longRunningRule: t(`默认值已为 ${RECOMMENDED_RPA_TIMEOUT_MS}ms;需要其他等待上限时,config set timeout 会在下一次 run 中生效。`, `The default is already ${RECOMMENDED_RPA_TIMEOUT_MS}ms; config set timeout takes effect on the next run when a different limit is needed.`),
62
+ bootstrapCommand: t("describe 仅在本地执行,不会连接 MCP。", "describe is local-only and does not contact MCP."),
63
+ },
64
+ approval: {
65
+ environmentVariable: ENV.autoApprove,
66
+ format: t("MCP 原始工具名或生成 command 名组成的 JSON 数组。", "JSON array of raw MCP tool names or generated command names."),
67
+ catalogField: "tools[].autoApproved",
68
+ scope: t("仅为客户端运行时元数据。它不会作为 HTTP Header 发送,也不会授予服务端权限。", "Client-side runtime metadata only. It is not sent as an HTTP header and does not grant server-side permission."),
69
+ executionRule: t("run 没有交互式批准提示;执行 CLI 命令始终是明确的本地操作。", "run has no interactive approval prompt; invoking a CLI command remains an explicit local action."),
70
+ },
71
+ errors: {
72
+ protocol: "feiguazhitou-mcp-cli.error/v1",
73
+ useJsonOutput: t("传入 --output json,可将启动器失败以及没有 stdout 的生成命令失败作为 JSON 错误文档返回。", "Pass --output json to receive launcher failures and zero-stdout generated-command failures as JSON error documents."),
74
+ toolFailureExit: t("MCP 标准 isError:true、飞瓜 ok:false 或非零 BaseResp.StatusCode 会保留 MCP 输出并以退出码 1 结束。", "MCP isError:true, Feiguazhitou ok:false, and non-zero BaseResp.StatusCode preserve MCP output and end with exit code 1."),
75
+ generatedCommandFailure: t("生成命令非零退出且没有 stdout 时,返回 COMMAND_FAILED;error.details 包含 source、exitCode,以及原始 stderr。", "When a generated command exits nonzero without stdout, the CLI returns COMMAND_FAILED; error.details contains source, exitCode, and the raw stderr."),
76
+ recoverableCodes: {
77
+ ARTIFACT_MISSING: t("执行 refresh 后,再重试 tools list/show 或 run。", "Run refresh, then retry tools list/show or run."),
78
+ ARTIFACT_REFRESH_REQUIRED: t("HTTP Header 名称或生成 CLI 的失败退出码策略与产物不一致,请执行 refresh。", "Run refresh because the HTTP header names or generated CLI failure-exit policy differ from the artifact."),
79
+ TOOL_NOT_FOUND: t("执行 tools list,并从当前目录选择 command。", "Run tools list and choose a current command."),
80
+ },
81
+ },
82
+ discovery: {
83
+ workflow: [
84
+ {
85
+ step: 1,
86
+ command: [COMMAND_NAME, "describe", "--output", "json"],
87
+ purpose: t("读取本地命令契约。该命令离线执行,不连接 MCP。", "Read the local command contract. This command is offline and does not contact MCP."),
88
+ },
89
+ {
90
+ step: 2,
91
+ command: [COMMAND_NAME, "tools", "list", "--output", "json"],
92
+ purpose: t("读取本地缓存的工具目录,不连接 MCP。", "Read the local cached tool catalog without contacting MCP."),
93
+ onError: t("当 error.code 为 ARTIFACT_MISSING 时,先执行第 3 步再重试。", "When error.code is ARTIFACT_MISSING, run step 3 before retrying."),
94
+ },
95
+ {
96
+ step: 3,
97
+ command: [COMMAND_NAME, "refresh", "--output", "json"],
98
+ purpose: t("显式发现实时 MCP schema,并生成或更新本地产物。", "Explicitly discover the live MCP schema and generate or update the local artifact."),
99
+ },
100
+ {
101
+ step: 4,
102
+ command: [COMMAND_NAME, "tools", "show", "NAME", "--output", "json"],
103
+ purpose: t("读取精确的输入 schema。NAME 接受 MCP 工具名或生成 command 名。", "Read an exact input schema. NAME accepts an MCP tool name or generated command name."),
104
+ },
105
+ {
106
+ step: 5,
107
+ command: [COMMAND_NAME, "skills", "show", "feiguazhitou-mcp-cli"],
108
+ purpose: t("在执行工具前加载安装、配置和安全工作流指南。", "Load installation, configuration, and safe workflow guidance before executing tools."),
109
+ },
110
+ ],
111
+ commands: {
112
+ config: `${COMMAND_NAME} config set endpoint URL | config set header HEADER --value-stdin | config set header-env HEADER ENV_VAR`,
113
+ describe: `${COMMAND_NAME} describe [--output json|markdown]`,
114
+ refresh: `${COMMAND_NAME} refresh [--force] [--output json|text]`,
115
+ toolsList: `${COMMAND_NAME} tools list [--refresh] [--force] [--output json|text]`,
116
+ toolsShow: `${COMMAND_NAME} tools show NAME [--refresh] [--force] [--output json|markdown]`,
117
+ run: `${COMMAND_NAME} run COMMAND --raw '<JSON matching inputSchema>' --output json`,
118
+ skill: `${COMMAND_NAME} skills show feiguazhitou-mcp-cli`,
119
+ },
120
+ },
121
+ execution: {
122
+ commandPattern: `${COMMAND_NAME} run GENERATED_COMMAND --raw '<JSON matching inputSchema>' --output json`,
123
+ rawInput: {
124
+ inline: `${COMMAND_NAME} run GENERATED_COMMAND --raw '<JSON matching inputSchema>' --output json`,
125
+ file: `${COMMAND_NAME} run GENERATED_COMMAND --raw @INPUT.json --output json`,
126
+ standardInput: `cat INPUT.json | ${COMMAND_NAME} run GENERATED_COMMAND --raw - --output json`,
127
+ },
128
+ transportRule: t("禁止直连本机 MCP;所有工具调用必须通过 feiguazhitou-mcp-cli run。", "Direct local MCP access is prohibited; every tool invocation must go through feiguazhitou-mcp-cli run."),
129
+ concurrencyRule: t("飞瓜本机 MCP 按单会话使用。不要并发执行 run、refresh 或 doctor;必须等待上一条会连接 MCP 的命令完全结束后,再执行下一条。CLI 不会自动排队。", "Use the local Feiguazhitou MCP as a single session. Do not run run, refresh, or doctor concurrently; wait for each MCP-connecting command to finish before starting the next one. The CLI does not queue concurrent calls automatically."),
130
+ toolNameMapping: t("MCP 工具名使用下划线;生成的 command 用连字符替换下划线。", "MCP tool names use underscores; generated commands replace underscores with hyphens."),
131
+ refreshRule: t("run 不会隐式发现 schema。产物缺失、Header 名称变更或生成 CLI 策略更新时,请显式执行 refresh;仅修改超时不需要 refresh。", "run never performs implicit schema discovery. Refresh explicitly when an artifact is missing, header names changed, or the generated CLI policy changes; a timeout-only change does not require refresh."),
132
+ failureExitRule: t("工具响应会原样输出;当 MCP 标准 isError:true、飞瓜 ok:false 或非零 BaseResp.StatusCode 表示失败时,退出码为 1。", "Tool responses are printed unchanged; exit code is 1 when MCP isError:true, Feiguazhitou ok:false, or non-zero BaseResp.StatusCode indicates failure."),
133
+ generatedFailureRule: t("若生成命令在产生 MCP 响应前失败,且请求了 --output json,stdout 会返回 COMMAND_FAILED 错误文档;原始生成命令 stderr 位于 error.details.stderr。", "If a generated command fails before producing an MCP response and --output json was requested, stdout returns a COMMAND_FAILED error document; the raw generated-command stderr is in error.details.stderr."),
134
+ },
135
+ catalog: {
136
+ staleAfterMs: CATALOG_STALE_AFTER_MS,
137
+ staleRule: t("tools list/show 仅提示目录超过 7 天未检查,不会自动联网或 refresh。", "tools list/show only warn when the catalog has not been checked for over 7 days; they never connect or refresh automatically."),
138
+ },
139
+ safety: [
140
+ t("执行不熟悉的生成 command 前,先使用 tools list 和 tools show。", "Use tools list and tools show before executing an unfamiliar generated command."),
141
+ t("将返回的账号、订单、直播和分析数据视为敏感信息;不要持久化到本地配置、产物、Skill 或日志。", "Treat returned account, order, live-stream, and analytics data as sensitive; do not persist it in local config, artifacts, Skills, or logs."),
142
+ t("调用当前或未来可能修改账号状态、发布内容、删除数据或触发外部操作的工具前,须取得明确授权。", "Obtain explicit authorization before invoking a current or future tool that can change account state, publish content, delete data, or trigger external actions."),
143
+ ],
144
+ };
145
+ }
146
+ export function describeDocument() {
147
+ return commandDocument();
148
+ }
149
+ function guideMarkdown() {
150
+ if (outputLanguage() === "zh") {
151
+ return `# ${COMMAND_NAME} 命令指南
152
+
153
+ 将此 CLI 用作单个本地飞瓜智投 MCP 连接的发现优先接口。生成工具不会硬编码在启动器中。
154
+
155
+ ## 强制调用边界
156
+
157
+ Agent、脚本和其他调用方不得直接连接本机 MCP endpoint,也不得通过其他 MCP client 调用工具。所有工具调用必须通过
158
+ \`${COMMAND_NAME} run COMMAND ...\` 发起。CLI 会在内部连接 MCP;此约束不影响 CLI 自己的正常工作。
159
+
160
+ ## 串行调用要求
161
+
162
+ 飞瓜本机 MCP 按单会话使用。不要并发执行 \`run\`、\`refresh\` 或 \`doctor\`;必须等待上一条会连接 MCP 的命令完全结束后,再执行下一条。CLI 不会自动排队。
163
+
164
+ ## 从标准 MCP JSON 初始化
165
+
166
+ 用户在对话中提供的 \`mcpServers\` JSON 只供 Agent 理解并逐项配置 CLI。CLI 不读取或解析整份 JSON,也不代替 Agent 做字段映射。Agent 先执行 \`${COMMAND_NAME} describe --output json\`,再根据当前契约和用户指定的 server 逐项配置;多个 server 无法确定目标时先询问,不猜测。
167
+
168
+ 当前 CLI 需要 endpoint 时,Agent 从已选 server 中取对应地址,并执行:
169
+
170
+ \`${COMMAND_NAME} config set endpoint URL\`
171
+
172
+ 对用户配置中的每个 Header,用户没有要求不保存时,Agent 默认逐个执行 \`${COMMAND_NAME} config set header HEADER --value-stdin\`,只经标准输入提供该 Header 值,绝不把值放到命令行参数中。该命令会保存到本机未加密凭据文件;支持 POSIX 权限的系统会限制为当前用户读写,Agent 必须告知用户。用户要求不保存时,Agent 对每个 Header 执行 \`${COMMAND_NAME} config unset header HEADER\` 和 \`${COMMAND_NAME} config set header-env HEADER ENV_VAR\`,并让实际值只存在于后续 CLI 进程的环境变量中。
173
+
174
+ 用户配置若有 \`autoApprove\`,Agent 将其原始 JSON 数组设置为后续 CLI 进程的 \`${ENV.autoApprove}\`。它只标记本地工具目录,不会发送给 MCP,也不替代高影响操作的明确授权。额外或未来新增字段不是错误:此说明不是字段白名单,Agent 应保留其参考意义,并仅在当前 \`describe\` 已定义映射时才配置;不能自行臆造映射或删除字段。
175
+
176
+ 逐项配置完成后,Agent 显式执行 \`${COMMAND_NAME} refresh --output json\`,再读取 \`${COMMAND_NAME} tools list --output json\`,按当前 schema 使用 \`tools show\` 和 \`run\`。整个过程只能使用 CLI,不能直连原始配置中的 MCP URL。
177
+
178
+ ## 1. 阅读本地契约
179
+
180
+ \`${COMMAND_NAME} describe --output json\`
181
+
182
+ 该命令仅在本地执行,不会连接 MCP。JSON 响应说明规范命令、错误协议、环境变量、超时规则和安全约束。
183
+
184
+ ## 2. 读取缓存工具,必要时显式刷新
185
+
186
+ \`${COMMAND_NAME} tools list --output json\`
187
+
188
+ 该命令读取已激活的本地目录。若返回 \`ARTIFACT_MISSING\`,执行:
189
+
190
+ \`${COMMAND_NAME} refresh --output json\`
191
+
192
+ 仅在明确需要实时 schema 检查时使用 \`tools list --refresh\`。如果本地目录超过 7 天未检查,\`tools list\` 和 \`tools show\` 会提示刷新建议,但不会自动联网。
193
+
194
+ ## 3. 调用前读取一个工具
195
+
196
+ \`${COMMAND_NAME} tools show NAME --output json\`
197
+
198
+ \`NAME\` 可以是带下划线的 MCP 工具名,也可以是带连字符的生成 command。响应包含精确的 \`inputSchema\` 和 \`--raw\` 调用模板。复杂 JSON 既可以内联传 \`--raw '<json>'\`,也可以传 \`--raw @INPUT.json\`,或用 \`cat INPUT.json | ... --raw -\` 从标准输入读取。
199
+
200
+ ## 4. 阅读工作流 Skill
201
+
202
+ \`${COMMAND_NAME} skills show feiguazhitou-mcp-cli\`
203
+
204
+ 该 Skill 说明本地客户端设置、凭据、刷新规则、敏感数据处理和诊断步骤,不固定 MCP 工具清单。
205
+
206
+ ## 5. 执行并检查结果
207
+
208
+ \`${COMMAND_NAME} run GENERATED_COMMAND --raw '<JSON matching inputSchema>' --output json\`
209
+
210
+ 默认超时为 \`${DEFAULT_TIMEOUT_MS}\`ms。需要其他等待上限时,执行 \`${COMMAND_NAME} config set timeout MILLISECONDS\`;新值会在下一次 \`run\` 中直接生效,无需 refresh。环境变量只影响当前进程;需要长期使用时,使用 \`config set timeout\` 保存该值。artifact 会保留生成时的默认超时,\`artifact.currentTimeoutMatches: false\` 只表示默认值不同;\`run\` 始终使用当前超时。需要保留原 MCP 客户端批准元数据时,将 \`${ENV.autoApprove}\` 设为 MCP 原始工具名或生成 command 名的 JSON 数组;匹配的目录项会显示 \`autoApproved: true\`。工具调用仅发送一次;第三方错误和超时错误不会被重试或由启动器改写。MCP 标准 \`isError:true\`、飞瓜 \`ok:false\` 或非零 \`BaseResp.StatusCode\` 时,原 MCP 输出保持不变,但进程以退出码 1 结束。
211
+ `;
212
+ }
213
+ return `# ${COMMAND_NAME} Command Guide
214
+
215
+ Use this CLI as a discovery-first interface for one local Feiguazhitou MCP connection. Generated tools are not hard-coded into the launcher.
216
+
217
+ ## Mandatory Transport Boundary
218
+
219
+ Agents, scripts, and other callers must not connect to the local MCP endpoint directly or invoke tools through another MCP client. Every tool call must use
220
+ \`${COMMAND_NAME} run COMMAND ...\`. The CLI connects to MCP internally; this restriction does not affect the CLI itself.
221
+
222
+ ## Serial Invocation Requirement
223
+
224
+ Use the local Feiguazhitou MCP as a single session. Do not run \`run\`, \`refresh\`, or \`doctor\` concurrently; wait for each MCP-connecting command to finish before starting the next one. The CLI does not queue concurrent calls automatically.
225
+
226
+ ## Initialize from a Standard MCP JSON Document
227
+
228
+ An \`mcpServers\` JSON document that a user provides in a conversation exists only for the Agent to understand and configure the CLI one setting at a time. The CLI neither reads nor parses the complete JSON document, and it does not map fields for the Agent. The Agent first runs \`${COMMAND_NAME} describe --output json\`, then uses the current contract and the user-selected server to configure each setting. If multiple servers are present and the target is unclear, ask instead of guessing.
229
+
230
+ When the current CLI needs an endpoint, the Agent identifies the corresponding address in the selected server and runs:
231
+
232
+ \`${COMMAND_NAME} config set endpoint URL\`
233
+
234
+ For every Header in the user configuration, unless the user opted out of persistence, the Agent runs \`${COMMAND_NAME} config set header HEADER --value-stdin\` one Header at a time. Supply the Header value only through standard input, never as a command-line argument. The command saves it in a local unencrypted credential file; systems with POSIX permissions restrict it to the current user, and the Agent must tell the user. When the user opts out, for each Header run \`${COMMAND_NAME} config unset header HEADER\` and \`${COMMAND_NAME} config set header-env HEADER ENV_VAR\`, and keep the actual value only in the environment of later CLI processes.
235
+
236
+ When the user configuration includes \`autoApprove\`, the Agent places its raw JSON array in \`${ENV.autoApprove}\` for later CLI processes. It only annotates the local tool catalog, is never sent to MCP, and does not replace explicit authorization for high-impact actions. Additional or future fields are not errors: this guide is not a field allowlist. Preserve them as reference information and configure them only when the current \`describe\` contract defines a mapping; never invent a mapping or discard a field.
237
+
238
+ After individual configuration is complete, the Agent explicitly runs \`${COMMAND_NAME} refresh --output json\`, then reads \`${COMMAND_NAME} tools list --output json\` and uses \`tools show\` and \`run\` against the current schema. The whole workflow remains CLI-only; never connect directly to the source MCP URL.
239
+
240
+ ## 1. Read the local contract
241
+
242
+ \`${COMMAND_NAME} describe --output json\`
243
+
244
+ This command is local-only and does not contact MCP. Its JSON response identifies the canonical commands, error protocol, environment variable names, timeout rules, and safety constraints.
245
+
246
+ ## 2. Read cached tools, then refresh explicitly when needed
247
+
248
+ \`${COMMAND_NAME} tools list --output json\`
249
+
250
+ This reads the activated local catalog without contacting MCP. When it returns \`ARTIFACT_MISSING\`, run:
251
+
252
+ \`${COMMAND_NAME} refresh --output json\`
253
+
254
+ Use \`tools list --refresh\` only when a live schema check is deliberately required. When the local catalog has not been checked for over 7 days, \`tools list\` and \`tools show\` show a refresh hint but never connect automatically.
255
+
256
+ ## 3. Read one tool before invoking it
257
+
258
+ \`${COMMAND_NAME} tools show NAME --output json\`
259
+
260
+ \`NAME\` can be the MCP tool name with underscores or the generated command with hyphens. The response includes the exact \`inputSchema\` and a \`--raw\` invocation template. Complex JSON can be inline with \`--raw '<json>'\`, read with \`--raw @INPUT.json\`, or provided through \`cat INPUT.json | ... --raw -\`.
261
+
262
+ ## 4. Read the workflow Skill
263
+
264
+ \`${COMMAND_NAME} skills show feiguazhitou-mcp-cli\`
265
+
266
+ The Skill explains local-client setup, credentials, refresh rules, sensitive-data handling, and diagnostic steps without fixing the MCP tool list.
267
+
268
+ ## 5. Execute and inspect results
269
+
270
+ \`${COMMAND_NAME} run GENERATED_COMMAND --raw '<JSON matching inputSchema>' --output json\`
271
+
272
+ The default timeout is \`${DEFAULT_TIMEOUT_MS}\`ms. To use a different limit, run \`${COMMAND_NAME} config set timeout MILLISECONDS\`; the new value takes effect on the next \`run\` without refresh. Set \`${ENV.timeout}\` to an integer from \`1\` to \`${MAX_TIMEOUT_MS}\` when a different MCP timeout is needed; the environment variable applies only to the current process. An \`artifact.currentTimeoutMatches: false\` value only means the generation-time default differs; \`run\` always uses the current timeout. Set \`${ENV.autoApprove}\` to a JSON array of raw MCP tool names or generated command names when an orchestrator needs the original MCP client approval metadata; matching catalog entries expose \`autoApproved: true\`. Tool calls are sent once; third-party errors and timeout errors are returned without retry or launcher-side rewriting. MCP \`isError:true\`, Feiguazhitou \`ok:false\`, and non-zero \`BaseResp.StatusCode\` preserve MCP output but end the process with exit code 1.
273
+ `;
274
+ }
275
+ export function describeMarkdown() {
276
+ return guideMarkdown();
277
+ }
278
+ //# sourceMappingURL=agent-guide.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-guide.js","sourceRoot":"","sources":["../src/agent-guide.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,cAAc,EACd,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AACpE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,SAAS,eAAe;IACtB,MAAM,gBAAgB,GAAG,cAAc,EAAE,KAAK,IAAI;QAChD,CAAC,CAAC,CAAC,eAAe,EAAE,aAAa,EAAE,mBAAmB,CAAC;QACvD,CAAC,CAAC,CAAC,sBAAsB,EAAE,qBAAqB,EAAE,8BAA8B,CAAC,CAAC;IACpF,OAAO;QACL,QAAQ,EAAE,iBAAiB;QAC3B,eAAe,EAAE,yBAAyB;QAC1C,IAAI,EAAE,CAAC,CAAC,0BAA0B,EAAE,uEAAuE,CAAC;QAC5G,kBAAkB,EAAE;YAClB,QAAQ,EAAE,EAAE;YACZ,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAA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;;;;oGAQoF,YAAY;;;;IAI5G,YAAY;;6CAE6B,YAAY,mKAAmK,YAAY,qCAAqC,YAAY;;2DAE9N,GAAG,CAAC,WAAW;;uBAEnD,YAAY,kCAAkC,YAAY;;;;IAI7E,YAAY;;;;;;IAMZ,YAAY;;;;IAIZ,YAAY;;;;;;IAMZ,YAAY;;;;;;IAMZ,YAAY;;;;;;IAMZ,YAAY;;UAEN,kBAAkB,uBAAuB,YAAY,2OAA2O,GAAG,CAAC,WAAW;CACxT,CAAC;IACA,CAAC;IACD,OAAO,KAAK,YAAY;;;;;;;IAOtB,YAAY;;;;;;;;4RAQ4Q,YAAY;;;;IAIpS,YAAY;;yGAEyF,YAAY,uWAAuW,YAAY,uCAAuC,YAAY;;iGAE1b,GAAG,CAAC,WAAW;;0EAEtC,YAAY,0CAA0C,YAAY;;;;IAIxI,YAAY;;;;;;IAMZ,YAAY;;;;IAIZ,YAAY;;;;;;IAMZ,YAAY;;;;;;IAMZ,YAAY;;;;;;IAMZ,YAAY;;2BAEW,kBAAkB,yCAAyC,YAAY,6GAA6G,GAAG,CAAC,OAAO,oCAAoC,cAAc,8PAA8P,GAAG,CAAC,WAAW;CACxhB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,30 @@
1
+ export const CLI_ERROR_PROTOCOL = "feiguazhitou-mcp-cli.error/v1";
2
+ export const CLI_ERROR_PROTOCOL_VERSION = 1;
3
+ export class CliError extends Error {
4
+ code;
5
+ remediation;
6
+ details;
7
+ constructor(code, message, remediation, details) {
8
+ super(message);
9
+ this.code = code;
10
+ this.remediation = remediation;
11
+ this.details = details;
12
+ this.name = "CliError";
13
+ }
14
+ }
15
+ export function errorDocument(error) {
16
+ const cliError = error instanceof CliError
17
+ ? error
18
+ : new CliError("COMMAND_FAILED", error instanceof Error ? error.message : String(error));
19
+ return {
20
+ protocol: CLI_ERROR_PROTOCOL,
21
+ protocolVersion: CLI_ERROR_PROTOCOL_VERSION,
22
+ error: {
23
+ code: cliError.code,
24
+ message: cliError.message,
25
+ ...(cliError.remediation ? { remediation: cliError.remediation } : {}),
26
+ ...(cliError.details ? { details: cliError.details } : {}),
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=cli-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-error.js","sourceRoot":"","sources":["../src/cli-error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAClE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAU5C,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEf;IAEA;IACA;IAJlB,YACkB,IAAkB,EAClC,OAAe,EACC,WAAoB,EACpB,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QALC,SAAI,GAAJ,IAAI,CAAc;QAElB,gBAAW,GAAX,WAAW,CAAS;QACpB,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,QAAQ,GAAG,KAAK,YAAY,QAAQ;QACxC,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,QAAQ,CAAC,gBAAgB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3F,OAAO;QACL,QAAQ,EAAE,kBAAkB;QAC5B,eAAe,EAAE,0BAA0B;QAC3C,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC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