@infimind-next/ai-hive-mcp 0.3.1 → 0.3.3

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.
package/README.md CHANGED
@@ -11,28 +11,41 @@
11
11
  "mcpServers": {
12
12
  "ai-hive": {
13
13
  "command": "npx",
14
- "args": ["-y", "@infimind-next/ai-hive-mcp@0.3.0", "--key", "<APIKEY>"]
14
+ "args": ["-y", "@infimind-next/ai-hive-mcp@0.3.3", "--key", "<APIKEY>"]
15
15
  }
16
16
  }
17
17
  }
18
18
  ```
19
19
 
20
- 要求 Node.js >= 20.19.0。本包通过标准 MCP stdio 与客户端通信,仅保证与支持 MCP 的客户端配合使用。
20
+ 要求 Node.js >= 20.19.0。默认请求超时为 300 秒,可通过 `--timeout-ms` 或 `AI_HIVE_MCP_TIMEOUT_MS` 覆盖;无效值回退为 300 秒。WorkBuddy Connector 的启动与认证命令保持引用 `@latest`,Connector 和 Skills 版本仍为 1.2.0。
21
+
22
+ 本包通过标准 MCP stdio 与客户端通信,仅保证与支持 MCP 的客户端配合使用。
21
23
 
22
24
  ## 工具
23
25
 
24
- - `get_user_info`:查询当前用户和余额
26
+ - `get_user_info`:查询当前用户和普通蜂蜜余额
27
+
28
+ 专属蜂蜜由服务端按实际模型自动选择抵扣,无需新增调用参数。不能仅凭普通蜂蜜余额为 0 拒绝模型调用;只有实际调用返回余额不足时,才使用 `rechargeUrl` 引导充值并重试。
29
+
25
30
  - `list_models`:按 TEXT、IMAGE 或 VIDEO 查询可用模型与公开价格
26
31
  - `get_model`:查询单个模型的参数 schema、媒体要求、计费因素和调用示例
27
32
  - `upload_media_from_path`:上传本地图片、视频或音频,返回 mediaId
28
33
  - `chat_text`:文本对话
29
34
  - `generate_image`:图片预检或正式生成
30
35
  - `generate_video`:视频预检或正式生成
36
+ - `get_material_mode`:查询认证资格和网页授权入口(可选)
37
+ - `quote_video_materials`:获取素材报价(可选)
31
38
  - `get_generation_task`:查询生成任务进度和结果
32
39
 
33
40
  ### 认证素材模式
34
41
 
35
- 0.3.1 增加可选的 `get_material_mode`(查询资格与网页授权入口)、`quote_video_materials`(冻结素材并报价),以及 `generate_video` 的 `materialMode` / `materialQuoteId` 字段。这些工具不是生成前置要求;旧版 0.3.0 也可直接使用认证模型。实际发布版本以 npm registry 为准。用户必须登录网页明确授权,MCP 不能代签;确认报价后按认证版模型单价按生成时长计费,认证服务费已内嵌其中,不再另收素材服务费。
42
+ 已发布的 0.3.1 提供可选认证工具,其调用契约支持认证版接收普通素材,由服务端按模型 ID 自动识别并校验资格、准备素材,不要求新增参数或先调用报价工具;实际可用性以所连接服务端的响应为准。`materialMode`、`materialQuoteId` 与 `quote_video_materials` 均为可选兼容能力。先用 `dryRun: true` 预检资格与费用;预检不执行供应商内容审核。资格不足或需要授权时,展示返回的操作链接,或引导查看[认证资格指南](https://ai-hive.iclip.cn/certified-materials#guide)。用户本人在网页授权,MCP 不能代签;保留用户指定模型,费用变化时重新确认。费用以所选模型的当前报价为准。
43
+
44
+ ## 0.3.2 活动与公告通知
45
+
46
+ 支持服务端提供的独立充值活动通知。首段文本继续是原业务 JSON,后续文本包含活动摘要、截止时间、充值入口与档位;Agent 按握手中的展示规则简短转达,尊重拒绝促销和严格输出要求。
47
+
48
+ 客户端自动使用可选查询参数请求通知,不增加工具必填参数,不改计费请求或自动重试次数。连接旧服务端且没有通知时正常返回业务结果。旧的 0.3.0/0.3.1 可继续使用新服务端,但不能保证旧 Agent 主动展示活动。支持管理员现有公告策略及无截止时间的公告;发布记录与实测范围见 [0.3.2 记录](../../docs/release/mcp-0.3.2-runbook.md)。
36
49
 
37
50
  ## 调用流程
38
51
 
@@ -51,7 +64,6 @@
51
64
  - 正式生成提示价格已更新:保持业务参数和原 `clientRequestId` 不变,重新预检获取最新 `pricingSnapshot` 后重试。
52
65
  - 返回 `REQUEST_OUTCOME_UNKNOWN`:停止自动重试,联系管理员核查。
53
66
 
54
-
55
67
  ### 认证版的用户路径
56
68
 
57
69
  用户提供普通素材即可,后台自动处理认证。使用对应认证模型与当前价格快照,先 dryRun 预检资格、素材和费用;通过后沿用标准版提交格式,认证字段和专用报价工具都可省略。收到任务 ID 后只查询原任务。
@@ -61,3 +73,18 @@
61
73
  更新信息仅在用户询问或与当前任务有关时介绍,不向用户转述内部参数、错误码、报价与重试机制。客户端可选升级提示默认静默,仅开启 `--verbose` 时输出维护诊断。技术维护记录见仓库 `docs/openapi/technical-changelog.md`。
62
74
 
63
75
  `recoveryAction` 是给调用端的恢复指引,不要逐字转成用户待办。响应中断用原 `clientRequestId` 和相同参数恢复;明确失败后再次生成,或改变报价/输入时,使用新请求标识。结果未知时先核查,不自动重建付费任务。
76
+
77
+ 当前客户端版本为 0.3.2,已于 2026-10-08 发布。发布物、兼容验证与服务端验收边界见 [0.3.2 发布记录](../../docs/release/mcp-0.3.2-runbook.md)。
78
+
79
+ ### 0.3.2:通知协商与直接上传
80
+
81
+ 0.3.1 保留旧充值活动返回。下面的公告扩展与直接上传工具已包含在 0.3.2 中,需要所连接服务端支持;客户端发布不代表生产服务已部署。
82
+
83
+ - `create_media_upload`:直接创建上传地址;`complete_media_upload`:直接确认上传完成。两者可在结果中返回通知。
84
+ - 支持通知的查询工具固定声明 `readOnlyHint=false`,因为服务端配置可启用返回状态写入。通知保留条件、截止时间和链接,结合对话转述,同一对话避免机械重复;实际展示由宿主决定。
85
+ - REST 请求级 `X-AI-Hive-Announcements: 1` 启用新的公告扩展;账户 POST 不要求该头。已发布的 0.3.1 不发送新请求头,仍可通过账户 GET 与原有付费请求接收旧充值活动,无需升级客户端或新增参数。SDK 直接工具请求协商,内部价格快照和自动上传初始化关闭;`upload_media_from_path` 展示完整上传完成结果。
86
+ - 正式付费通知请求必须有合法 `clientRequestId`,重放与恢复不重复通知,dryRun 无通知。这些规则已通过本地协议验证;生产服务与真实宿主展示仍需独立验收。
87
+
88
+ 兼容模式(COMPAT)下,账户 GET 和 POST 常驻返回进行中的旧充值活动,不占用模型调用的每日活动通知次数。原有付费请求仍按用户每天首次成功调用返回活动;重放、恢复与 dryRun 不重复通知。管理员启用通知管理(MANAGED)后按入口设置返回;旧客户端保留 `activePromotion` 结构,功能公告通过支持新扩展的客户端返回。
89
+
90
+ 0.3.2 中,CLI login/status 的凭证检查使用账户 GET 并明确发送 `X-AI-Hive-Announcements: 0`,完整验证凭证后仅返回账户核心字段、`activePromotion: null`,不写通知台账、共享次数或最短间隔状态。SDK 的 POST 404/405 后默认 GET 回退仍返回兼容活动。
@@ -2,6 +2,9 @@ import type { BearerTokenProvider } from "./auth-token-provider.js";
2
2
  import { type McpClientInfo } from "./client-info.js";
3
3
  import { type UpdateNotifier } from "./update-notifier.js";
4
4
  type FetchImpl = typeof fetch;
5
+ export type AnnouncementOptions = {
6
+ announcements?: boolean;
7
+ };
5
8
  type AiHiveApiClientInput = {
6
9
  endpoint: string;
7
10
  tokenProvider: BearerTokenProvider;
@@ -42,19 +45,19 @@ export declare class AiHiveApiClient {
42
45
  private send;
43
46
  private readResponse;
44
47
  getUserInfo(): Promise<unknown>;
45
- getMaterialMode(): Promise<unknown>;
46
- quoteVideoMaterials(input: unknown): Promise<unknown>;
47
- listModels(input: Record<string, unknown>): Promise<unknown>;
48
- getModel(publicModelId: string, routingMode?: string): Promise<unknown>;
49
- createMediaUpload(input: unknown): Promise<unknown>;
50
- completeMediaUpload(mediaId: string): Promise<unknown>;
51
- chatText(input: unknown): Promise<unknown>;
52
- generateImage(input: unknown): Promise<unknown>;
53
- generateVideo(input: unknown): Promise<unknown>;
48
+ getMaterialMode(options?: AnnouncementOptions): Promise<unknown>;
49
+ quoteVideoMaterials(input: unknown, options?: AnnouncementOptions): Promise<unknown>;
50
+ listModels(input: Record<string, unknown>, options?: AnnouncementOptions): Promise<unknown>;
51
+ getModel(publicModelId: string, routingMode?: string, options?: AnnouncementOptions): Promise<unknown>;
52
+ createMediaUpload(input: unknown, options?: AnnouncementOptions): Promise<unknown>;
53
+ completeMediaUpload(mediaId: string, options?: AnnouncementOptions): Promise<unknown>;
54
+ chatText(input: unknown, options?: AnnouncementOptions): Promise<unknown>;
55
+ generateImage(input: unknown, options?: AnnouncementOptions): Promise<unknown>;
56
+ generateVideo(input: unknown, options?: AnnouncementOptions): Promise<unknown>;
54
57
  private requestGeneration;
55
58
  getGenerationTask(input: {
56
59
  taskId: string;
57
- }): Promise<unknown>;
60
+ }, options?: AnnouncementOptions): Promise<unknown>;
58
61
  putUpload(input: {
59
62
  url: string;
60
63
  method: "PUT";
@@ -1,5 +1,10 @@
1
1
  import { encodeMcpClientInfo, MCP_CLIENT_INFO_HEADER, } from "./client-info.js";
2
2
  import { LATEST_CLIENT_VERSION_HEADER, } from "./update-notifier.js";
3
+ function announcementHeaders(options) {
4
+ return options?.announcements === true
5
+ ? { "X-AI-Hive-Announcements": "1" }
6
+ : {};
7
+ }
3
8
  export class AiHiveApiError extends Error {
4
9
  status;
5
10
  details;
@@ -187,19 +192,34 @@ export class AiHiveApiClient {
187
192
  }
188
193
  return body;
189
194
  }
190
- getUserInfo() {
191
- return this.request("/mcp/user-info");
195
+ async getUserInfo() {
196
+ try {
197
+ return await this.request("/mcp/user-info?include=user-notices", {
198
+ method: "POST",
199
+ body: "{}",
200
+ });
201
+ }
202
+ catch (error) {
203
+ if (error instanceof AiHiveApiError &&
204
+ (error.status === 404 || error.status === 405)) {
205
+ return this.request("/mcp/user-info?include=user-notices");
206
+ }
207
+ throw error;
208
+ }
192
209
  }
193
- getMaterialMode() {
194
- return this.request("/mcp/material-mode");
210
+ getMaterialMode(options) {
211
+ return this.request("/mcp/material-mode", {
212
+ headers: announcementHeaders(options),
213
+ });
195
214
  }
196
- quoteVideoMaterials(input) {
215
+ quoteVideoMaterials(input, options) {
197
216
  return this.request("/mcp/generation/video/material-quote", {
198
217
  method: "POST",
199
218
  body: JSON.stringify(input),
219
+ headers: announcementHeaders(options),
200
220
  });
201
221
  }
202
- async listModels(input) {
222
+ async listModels(input, options) {
203
223
  const query = new URLSearchParams();
204
224
  if (typeof input.modelType === "string") {
205
225
  query.set("modelType", input.modelType);
@@ -208,16 +228,16 @@ export class AiHiveApiClient {
208
228
  query.set("detail", input.detail);
209
229
  }
210
230
  const serialized = query.toString();
211
- return redactInternalPricing(await this.request(`/mcp/models${serialized ? `?${serialized}` : ""}`));
231
+ return redactInternalPricing(await this.request(`/mcp/models${serialized ? `?${serialized}` : ""}`, { headers: announcementHeaders(options) }));
212
232
  }
213
233
  // getModel 与 listModels 的 detail 参数依赖服务端新部署; 旧服务端会 404 或被
214
234
  // strict 入参校验拒绝, 所以 npm 0.3.0 必须在服务端升级之后发布.
215
- async getModel(publicModelId, routingMode) {
235
+ async getModel(publicModelId, routingMode, options) {
216
236
  const query = routingMode
217
237
  ? `?${new URLSearchParams({ routingMode }).toString()}`
218
238
  : "";
219
239
  try {
220
- return redactInternalPricing(await this.request(`/mcp/models/${encodeURIComponent(publicModelId)}${query}`));
240
+ return redactInternalPricing(await this.request(`/mcp/models/${encodeURIComponent(publicModelId)}${query}`, { headers: announcementHeaders(options) }));
221
241
  }
222
242
  catch (error) {
223
243
  if (error instanceof AiHiveApiError && error.status === 404) {
@@ -226,22 +246,25 @@ export class AiHiveApiClient {
226
246
  throw error;
227
247
  }
228
248
  }
229
- createMediaUpload(input) {
249
+ createMediaUpload(input, options) {
230
250
  return this.request("/mcp/media/upload-token", {
231
251
  method: "POST",
232
252
  body: JSON.stringify(input),
253
+ headers: announcementHeaders(options),
233
254
  });
234
255
  }
235
- completeMediaUpload(mediaId) {
256
+ completeMediaUpload(mediaId, options) {
236
257
  return this.request(`/mcp/media/${encodeURIComponent(mediaId)}/complete`, {
237
258
  method: "POST",
259
+ headers: announcementHeaders(options),
238
260
  });
239
261
  }
240
- async chatText(input) {
262
+ async chatText(input, options) {
241
263
  try {
242
- return await this.request("/mcp/chat/text", {
264
+ return await this.request("/mcp/chat/text?include=user-notices", {
243
265
  method: "POST",
244
266
  body: JSON.stringify(input),
267
+ headers: announcementHeaders(options),
245
268
  });
246
269
  }
247
270
  catch (error) {
@@ -251,17 +274,18 @@ export class AiHiveApiClient {
251
274
  throw error;
252
275
  }
253
276
  }
254
- generateImage(input) {
255
- return this.requestGeneration("/mcp/generation/image", input);
277
+ generateImage(input, options) {
278
+ return this.requestGeneration("/mcp/generation/image", input, options);
256
279
  }
257
- generateVideo(input) {
258
- return this.requestGeneration("/mcp/generation/video", input);
280
+ generateVideo(input, options) {
281
+ return this.requestGeneration("/mcp/generation/video", input, options);
259
282
  }
260
- async requestGeneration(path, input) {
283
+ async requestGeneration(path, input, options) {
261
284
  try {
262
- return await this.request(path, {
285
+ return await this.request(`${path}?include=user-notices`, {
263
286
  method: "POST",
264
287
  body: JSON.stringify(input),
288
+ headers: announcementHeaders(options),
265
289
  });
266
290
  }
267
291
  catch (error) {
@@ -279,8 +303,8 @@ export class AiHiveApiClient {
279
303
  throw error;
280
304
  }
281
305
  }
282
- getGenerationTask(input) {
283
- return this.request(`/mcp/generation/tasks/${encodeURIComponent(input.taskId)}`);
306
+ getGenerationTask(input, options) {
307
+ return this.request(`/mcp/generation/tasks/${encodeURIComponent(input.taskId)}?include=user-notices`, { headers: announcementHeaders(options) });
284
308
  }
285
309
  async putUpload(input) {
286
310
  await this.withTimeout(async (signal) => {
package/dist/cli.js CHANGED
@@ -256,7 +256,10 @@ async function requestUserInfo(endpoint, token, deadlineAt) {
256
256
  const timeoutMs = remainingMs(deadlineAt);
257
257
  return withDeadline(fetch(`${endpoint.replace(/\/+$/, "")}/mcp/user-info`, {
258
258
  method: "GET",
259
- headers: { Authorization: `Bearer ${token}` },
259
+ headers: {
260
+ Authorization: `Bearer ${token}`,
261
+ "X-AI-Hive-Announcements": "0",
262
+ },
260
263
  signal: controller.signal,
261
264
  }), timeoutMs, () => controller.abort());
262
265
  }
@@ -115,7 +115,7 @@ export async function uploadMediaFromPath(api, rawInput) {
115
115
  filename,
116
116
  contentType,
117
117
  sizeBytes: stats.size,
118
- }));
118
+ }, { announcements: false }));
119
119
  const body = await openAsBlob(input.path, { type: contentType });
120
120
  await api.putUpload({
121
121
  url: upload.upload.url,
@@ -123,5 +123,5 @@ export async function uploadMediaFromPath(api, rawInput) {
123
123
  headers: upload.upload.headers,
124
124
  body,
125
125
  });
126
- return api.completeMediaUpload(upload.mediaId);
126
+ return api.completeMediaUpload(upload.mediaId, { announcements: true });
127
127
  }
package/dist/schemas.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare const mcpCreateMediaUploadOutputSchema: z.ZodObject<{
20
20
  expiresAt: z.ZodString;
21
21
  }, "strict", z.ZodTypeAny, {
22
22
  mimeType: string;
23
+ expiresAt: string;
23
24
  mediaId: string;
24
25
  mediaType: "IMAGE" | "VIDEO" | "AUDIO" | "DOCUMENT";
25
26
  sizeBytes: number;
@@ -28,9 +29,9 @@ export declare const mcpCreateMediaUploadOutputSchema: z.ZodObject<{
28
29
  url: string;
29
30
  headers: Record<string, string>;
30
31
  };
31
- expiresAt: string;
32
32
  }, {
33
33
  mimeType: string;
34
+ expiresAt: string;
34
35
  mediaId: string;
35
36
  mediaType: "IMAGE" | "VIDEO" | "AUDIO" | "DOCUMENT";
36
37
  sizeBytes: number;
@@ -39,7 +40,6 @@ export declare const mcpCreateMediaUploadOutputSchema: z.ZodObject<{
39
40
  url: string;
40
41
  headers: Record<string, string>;
41
42
  };
42
- expiresAt: string;
43
43
  }>;
44
44
  export declare const mcpUploadMediaFromPathInputSchema: z.ZodObject<{
45
45
  path: z.ZodEffects<z.ZodString, string, string>;
@@ -80,7 +80,7 @@ export declare const chatTextShape: {
80
80
  }>, "many">;
81
81
  thinkingEnabled: z.ZodOptional<z.ZodBoolean>;
82
82
  clientRequestId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
83
- pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, "many">, z.ZodString, z.ZodNull]>>;
83
+ pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, z.ZodArray<z.ZodNullable<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>, "many">, z.ZodString, z.ZodNull]>>;
84
84
  };
85
85
  export declare const generateImageShape: {
86
86
  publicModelId: z.ZodString;
@@ -91,7 +91,7 @@ export declare const generateImageShape: {
91
91
  params: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodNull]>, Record<string, unknown>, Record<string, unknown> | null>>;
92
92
  dryRun: z.ZodDefault<z.ZodBoolean>;
93
93
  clientRequestId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
94
- pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, "many">, z.ZodString, z.ZodNull]>>;
94
+ pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, z.ZodArray<z.ZodNullable<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>, "many">, z.ZodString, z.ZodNull]>>;
95
95
  };
96
96
  export declare const generateVideoShape: {
97
97
  materialMode: z.ZodOptional<z.ZodEnum<["standard", "certified"]>>;
@@ -107,7 +107,7 @@ export declare const generateVideoShape: {
107
107
  params: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodNull]>, Record<string, unknown>, Record<string, unknown> | null>>;
108
108
  dryRun: z.ZodDefault<z.ZodBoolean>;
109
109
  clientRequestId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
110
- pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, "many">, z.ZodString, z.ZodNull]>>;
110
+ pricingSnapshot: z.ZodOptional<z.ZodUnion<[z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, z.ZodArray<z.ZodNullable<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>, "many">, z.ZodString, z.ZodNull]>>;
111
111
  };
112
112
  export declare const getGenerationTaskShape: {
113
113
  taskId: z.ZodString;
package/dist/schemas.js CHANGED
@@ -10,7 +10,8 @@ const routingModeSchema = z.enum([
10
10
  "SPEED_FIRST",
11
11
  "SUCCESS_FIRST",
12
12
  ]);
13
- const pricingSnapshotSchema = z.record(z.unknown());
13
+ // 显式开放对象属性, 让宿主原样传递嵌套报价, 严格校验仍由服务端执行.
14
+ const pricingSnapshotSchema = z.object({}).passthrough();
14
15
  // 宿主常把可选数组/对象字段塞成 null, 归一到默认值避免服务端收到非法请求.
15
16
  const nullableMediaIdsSchema = z
16
17
  .union([z.array(mediaIdSchema), z.null()])
package/dist/server.d.ts CHANGED
@@ -1,22 +1,33 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
2
3
  import { z } from "zod";
3
4
  import { AiHiveApiClient } from "./api-client.js";
4
5
  import { type BearerTokenProvider } from "./auth-token-provider.js";
5
6
  import type { McpClientConfig } from "./config.js";
6
7
  import { WorkBuddyCredentialStore } from "./workbuddy-credentials.js";
7
- export declare const SERVER_VERSION = "0.3.1";
8
+ export declare const SERVER_VERSION = "0.3.3";
8
9
  declare function content(value: unknown): {
9
10
  content: {
10
11
  type: "text";
11
12
  text: string;
12
13
  }[];
14
+ structuredContent: Record<string, unknown>;
15
+ };
16
+ declare function userInfoContent(value: unknown): {
17
+ content: {
18
+ type: "text";
19
+ text: string;
20
+ }[];
21
+ structuredContent: Record<string, unknown>;
13
22
  };
14
23
  type ApiClientLike = Pick<AiHiveApiClient, "getUserInfo" | "getMaterialMode" | "quoteVideoMaterials" | "listModels" | "getModel" | "createMediaUpload" | "completeMediaUpload" | "chatText" | "generateImage" | "generateVideo" | "getGenerationTask" | "putUpload">;
15
24
  export type ToolDefinition = {
16
25
  name: string;
26
+ title?: string;
17
27
  description: string;
18
28
  schema: z.ZodRawShape;
19
- handler: (args: Record<string, unknown>) => Promise<ReturnType<typeof content>>;
29
+ annotations?: ToolAnnotations;
30
+ handler: (args: Record<string, unknown>) => Promise<ReturnType<typeof content> | ReturnType<typeof userInfoContent>>;
20
31
  };
21
32
  export declare function createToolDefinitions(client: () => ApiClientLike): ToolDefinition[];
22
33
  export type ResolvedServerAuth = {
package/dist/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { toolResultContent } from "./user-notices.js";
1
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
4
  import { chatTextShape, generateImageShape, generateVideoShape, getGenerationTaskShape, getModelShape, listModelsShape, } from "./schemas.js";
@@ -8,15 +9,29 @@ import { readMcpClientInfo } from "./client-info.js";
8
9
  import { createUpdateNotifier } from "./update-notifier.js";
9
10
  import { uploadMediaFromPath } from "./local-media.js";
10
11
  import { WorkBuddyOAuthClient } from "./workbuddy-oauth-client.js";
11
- export const SERVER_VERSION = "0.3.1";
12
+ export const SERVER_VERSION = "0.3.3";
12
13
  const DEPRECATED_ATTACHMENT_IDS_MESSAGE = "attachmentIds 已废弃,请使用 messages[].mediaIds";
13
14
  const SNAPSHOT_PARSE_FAILURE_MESSAGE = "pricingSnapshot 格式不正确,应为 list_models 返回的快照对象,也可以省略该字段由客户端自动获取";
14
15
  const SNAPSHOT_ARRAY_MISMATCH_MESSAGE = "pricingSnapshot 数组中没有匹配当前模型和 routingMode 的快照,请传入 list_models 返回的对应快照对象,或省略该字段由客户端自动获取";
15
16
  const SNAPSHOT_IDENTITY_MISMATCH_MESSAGE = "pricingSnapshot 的 publicModelId 或 routingMode 与请求不一致,请传入 list_models 返回的对应快照对象,或省略该字段由客户端自动获取";
16
17
  const MODEL_UNAVAILABLE_MESSAGE = "模型当前不可用或不支持该路由模式,请重新调用 list_models 获取最新模型信息";
18
+ // 此文案与 @ai-hive/contracts 的 USER_INFO_TOOL_* 常量保持一致; 独立发布的客户端不引入运行依赖.
19
+ const USER_INFO_TOOL_TITLE = "查看蜂巢账户信息";
20
+ const USER_INFO_TOOL_DESCRIPTION = "查看你的蜂巢账户资料、可用余额和充值入口。";
17
21
  function content(value) {
22
+ const result = Array.isArray(value)
23
+ ? { models: value }
24
+ : value;
18
25
  return {
19
- content: [{ type: "text", text: JSON.stringify(value) }],
26
+ content: toolResultContent(result),
27
+ structuredContent: result && "userNotices" in result
28
+ ? Object.fromEntries(Object.entries(result).filter(([key]) => key !== "userNotices"))
29
+ : result,
30
+ };
31
+ }
32
+ function userInfoContent(value) {
33
+ return {
34
+ ...content(value),
20
35
  };
21
36
  }
22
37
  function rejectDeprecatedAttachmentIds(args) {
@@ -47,7 +62,7 @@ async function resolvePricingSnapshot(client, modelType, args) {
47
62
  return request;
48
63
  };
49
64
  const resolveCurrentSnapshot = async () => {
50
- const models = await client().listModels({ modelType });
65
+ const models = await client().listModels({ modelType }, { announcements: false });
51
66
  const model = Array.isArray(models)
52
67
  ? models.find((item) => isPlainObject(item) && item.publicModelId === args.publicModelId)
53
68
  : undefined;
@@ -99,38 +114,40 @@ async function resolvePricingSnapshot(client, modelType, args) {
99
114
  // 数字/布尔等原始类型同样是畸形回传, 不能原样透传给付费 API.
100
115
  throw new Error(SNAPSHOT_PARSE_FAILURE_MESSAGE);
101
116
  }
102
- // 幂等键语义写在每个付费工具的描述里, 让宿主在选型阶段就能看到重试规则.
103
- const CLIENT_REQUEST_ID_NOTE = "付费调用应传入稳定 UUID 作为 clientRequestId 幂等键;仅传输中断、REQUEST_IN_PROGRESS 或刷新过期 pricingSnapshot 时复用原值和相同业务参数。余额、参数、媒体或已缓存的模型调用失败在修正后必须使用新的 clientRequestId;REQUEST_OUTCOME_UNKNOWN 必须停止自动重试并人工核查。";
104
- // 长耗时提醒同样前置到工具描述: 宿主据此设置超时, 避免"本端超时先断、
105
- // 服务端跑完仍扣费"被误读成失败扣款.
106
- const LONG_RUNNING_NOTE = "该调用同步返回,长推理模型单次可能耗时 1-3 分钟,客户端超时应设为 300 秒以上;等待超时只代表本端不再等待,服务端可能仍在生成,也可能已完成并扣费,超时后复用同一 clientRequestId 和相同业务参数重新调用即可取回首次结果,修正参数后换新值。";
107
117
  export function createToolDefinitions(client) {
108
- return [
118
+ const definitions = [
109
119
  {
110
120
  name: "get_user_info",
111
- description: "查询当前用户、余额,以及官网地址和充值入口;余额不足时引导用户打开 rechargeUrl 完成充值后重试。",
121
+ title: USER_INFO_TOOL_TITLE,
122
+ description: USER_INFO_TOOL_DESCRIPTION,
112
123
  schema: {},
113
- handler: async () => content(await client().getUserInfo()),
124
+ annotations: {
125
+ readOnlyHint: false,
126
+ destructiveHint: false,
127
+ openWorldHint: false,
128
+ },
129
+ handler: async () => userInfoContent(await client().getUserInfo()),
114
130
  },
115
131
  {
116
132
  name: "list_models",
117
- description: "按 TEXT、IMAGE 或 VIDEO 查询可用模型与公开价格。detail 为 lite 时只返回各模型各路由的售价摘要(维度、单位、计费方式、内含数量及 saleMicros),用于快速选型;detail 为 full 时返回完整公开详情。saleMicros 是客户实际结算价,两种结果都不包含内部参考成本。",
133
+ description: "按 TEXT、IMAGE 或 VIDEO 查询可用模型及价格;detail=lite 用于选型,detail=full 返回完整信息。",
118
134
  schema: listModelsShape,
119
- handler: async (args) => content(await client().listModels(args)),
135
+ annotations: { readOnlyHint: false },
136
+ handler: async (args) => content(await client().listModels(args, { announcements: true })),
120
137
  },
121
138
  {
122
139
  name: "get_model",
123
140
  description: "按 publicModelId 查询单个模型的参数 schema、媒体要求、计费因素和示例;传 routingMode 可获取线路专属契约。",
124
141
  schema: getModelShape,
142
+ annotations: { readOnlyHint: false },
125
143
  handler: async (args) => {
126
144
  const publicModelId = String(args.publicModelId);
127
- return content(typeof args.routingMode === "string"
128
- ? await client().getModel(publicModelId, args.routingMode)
129
- : await client().getModel(publicModelId));
145
+ return content(await client().getModel(publicModelId, typeof args.routingMode === "string" ? args.routingMode : undefined, { announcements: true }));
130
146
  },
131
147
  },
132
148
  {
133
149
  name: "upload_media_from_path",
150
+ annotations: { readOnlyHint: false },
134
151
  description: "上传本地图片、视频、音频或文档并返回 mediaId。",
135
152
  schema: {
136
153
  path: z.string().min(1),
@@ -139,43 +156,68 @@ export function createToolDefinitions(client) {
139
156
  },
140
157
  handler: async (args) => content(await uploadMediaFromPath(client(), args)),
141
158
  },
159
+ {
160
+ name: "create_media_upload",
161
+ description: "为媒体文件创建短期上传地址,按返回的 method 和 headers PUT 原始字节。",
162
+ schema: {
163
+ filename: z.string().min(1),
164
+ contentType: z.string().min(1),
165
+ sizeBytes: z.number().int().positive(),
166
+ },
167
+ annotations: { readOnlyHint: false },
168
+ handler: async (args) => content(await client().createMediaUpload(args, { announcements: true })),
169
+ },
170
+ {
171
+ name: "complete_media_upload",
172
+ description: "确认媒体上传完成,返回可用于模型调用的 mediaId。",
173
+ schema: { mediaId: z.string().min(1) },
174
+ annotations: { readOnlyHint: false },
175
+ handler: async (args) => content(await client().completeMediaUpload(String(args.mediaId), {
176
+ announcements: true,
177
+ })),
178
+ },
142
179
  {
143
180
  name: "chat_text",
144
- description: `使用指定模型生成文本。${LONG_RUNNING_NOTE}${CLIENT_REQUEST_ID_NOTE}`,
181
+ description: "使用指定模型生成文本,返回本次对话结果。",
145
182
  schema: chatTextShape,
183
+ annotations: { readOnlyHint: false },
146
184
  handler: async (args) => {
147
185
  rejectDeprecatedAttachmentIds(args);
148
186
  const body = await resolvePricingSnapshot(client, "TEXT", args);
149
- return content(await client().chatText(body));
187
+ return content(await client().chatText(body, { announcements: true }));
150
188
  },
151
189
  },
152
190
  {
153
191
  name: "generate_image",
154
- description: `创建图片生成任务;dryRun=true 时只校验参数、媒体和预估费用,不创建任务且可省略 pricingSnapshot 与 clientRequestId。${CLIENT_REQUEST_ID_NOTE}`,
192
+ description: "使用指定模型生成图片;dryRun=true 可先检查输入并预估费用。",
155
193
  schema: generateImageShape,
194
+ annotations: { readOnlyHint: false },
156
195
  handler: async (args) => {
157
196
  const body = await resolvePricingSnapshot(client, "IMAGE", args);
158
- return content(await client().generateImage(body));
197
+ return content(await client().generateImage(body, { announcements: true }));
159
198
  },
160
199
  },
161
200
  {
162
201
  name: "generate_video",
163
- description: `认证版接收普通素材,服务端按模型 ID 自动校验资格和准备素材。提交前先用 dryRun=true 做只读预检,不用真实付费提交试探资格。materialMode、materialQuoteId 和专用报价工具均为可选兼容能力;正式提交使用当前 pricingSnapshot 和稳定 clientRequestId。资格不足时明确说明差额或待授权事项,并在回复中展示返回的 helpUrl 或 actionUrl 为可点击链接;未返回链接时使用 https://ai-hive.iclip.cn/certified-materials#guide。保留用户指定模型,不擅自切换模型或继续付费提交。认证服务已包含在模型价格中;费用变化时重新确认。收到任务 ID 后查询原任务,不重复创建。dryRun 不创建任务、不冻结素材、不预占或扣费,也不执行供应商内容审核。${CLIENT_REQUEST_ID_NOTE}`,
202
+ description: "使用指定模型生成视频;dryRun=true 可先检查输入并预估费用。",
164
203
  schema: generateVideoShape,
204
+ annotations: { readOnlyHint: false },
165
205
  handler: async (args) => {
166
206
  const body = await resolvePricingSnapshot(client, "VIDEO", args);
167
- return content(await client().generateVideo(body));
207
+ return content(await client().generateVideo(body, { announcements: true }));
168
208
  },
169
209
  },
170
210
  {
171
211
  name: "get_material_mode",
212
+ annotations: { readOnlyHint: false },
172
213
  description: "查询认证版服务状态、授权与累计充值资格。已满足条件时直接继续;仅未授权时请用户本人打开 actionUrl 阅读并同意,不得代替用户授权。累计充值资格与钱包余额分别检查。",
173
214
  schema: {},
174
- handler: async () => content(await client().getMaterialMode()),
215
+ handler: async () => content(await client().getMaterialMode({ announcements: true })),
175
216
  },
176
217
  {
177
218
  name: "quote_video_materials",
178
- description: "上传普通素材后,由调用端用与生成相同的模型、参数及媒体 ID 获取报价,包含参考图片、视频、首帧和尾帧。无需用户手动认证素材。认证服务已包含在模型价格中,不另收素材费;向用户说明必要费用,费用或计费条件变化时重新确认。此工具可选,返回 id 可用作 materialQuoteId;未提供报价时服务端自动准备。显式报价过期时保留原素材重新获取。",
219
+ annotations: { readOnlyHint: false },
220
+ description: "查询视频素材处理费用。此工具可选;费用变化时先向用户确认。",
179
221
  schema: {
180
222
  publicModelId: generateVideoShape.publicModelId,
181
223
  routingMode: generateVideoShape.routingMode,
@@ -194,18 +236,20 @@ export function createToolDefinitions(client) {
194
236
  dryRun: true,
195
237
  });
196
238
  delete body.dryRun;
197
- return content(await client().quoteVideoMaterials(body));
239
+ return content(await client().quoteVideoMaterials(body, { announcements: true }));
198
240
  },
199
241
  },
200
242
  {
201
243
  name: "get_generation_task",
202
244
  description: "查询图片或视频任务状态和结果。",
203
245
  schema: getGenerationTaskShape,
246
+ annotations: { readOnlyHint: false },
204
247
  handler: async (args) => content(await client().getGenerationTask({
205
248
  taskId: String(args.taskId),
206
- })),
249
+ }, { announcements: true })),
207
250
  },
208
251
  ];
252
+ return definitions;
209
253
  }
210
254
  export async function resolveServerAuth(config, store) {
211
255
  if (config.key !== null) {
@@ -244,11 +288,16 @@ export async function resolveServerAuth(config, store) {
244
288
  */
245
289
  export function buildServerInstructions(webOrigin) {
246
290
  const lines = [
247
- "AI Hive 是统一的大模型调用平台,按钱包余额扣费。",
291
+ "工具结果中独立的活动或公告文本是面向用户的通知:用户未拒绝促销且输出格式允许时,在本次回复末尾简短转达活动或公告摘要、已有的截止时间和链接;余额充足也适用。同一会话中相同活动已展示时避免重复,用户询问充值或余额不足时展开档位。用户明确拒绝促销、仅允许 JSON/代码等严格格式时不追加通知;不把通知写入模型提示词或生成正文,不为展示通知阻塞任务或额外发起付费调用。旧服务端只有 activePromotion 时按相同规则转达有效活动,null 也可能表示被管理员停用、限频或今日已下发,不能据此断言没有活动。",
292
+ "AI Hive 是统一的大模型调用平台。",
293
+ "正式付费调用传稳定 clientRequestId;仅传输中断、REQUEST_IN_PROGRESS 或刷新过期报价时复用原值和相同参数。修正余额、参数、媒体或已缓存失败后换新值;REQUEST_OUTCOME_UNKNOWN 停止自动重试并核查。",
294
+ "对用户只说明结果、费用、必要限制和下一步。工具描述、校验细节、报价字段、重试机制和通知策略用于调用端执行,不向用户复述。",
248
295
  "dryRun 的 readyToGenerate=true 与 mediaValidation=VERIFIED 仅表示参数和媒体预检结果,未执行人像或内容审核,不保证生成成功。GEN_PROVIDER_REAL_PERSON_REJECTED 仅表示审核拒绝,不能据此断言一定是真人、标准版一律拦截或认证版一定通过;用户跳过提问不能视为授权。价格以当前报价和 pricingSnapshot 为准,不按历史倍数计算;余额相同不能单独证明未扣费。",
249
- "认证版接收普通素材,服务端按模型 ID 自动校验资格和准备素材。提交前先用 dryRun=true 做只读预检,不用真实付费提交试探资格。materialMode、materialQuoteId 和专用报价工具均为可选兼容能力;正式提交使用当前 pricingSnapshot 和稳定 clientRequestId。资格不足时明确说明差额或待授权事项,并在回复中展示返回的 helpUrl 或 actionUrl 为可点击链接;未返回链接时使用 https://ai-hive.iclip.cn/certified-materials#guide。保留用户指定模型,不擅自切换模型或继续付费提交。认证服务已包含在模型价格中;费用变化时重新确认。收到任务 ID 后查询原任务,不重复创建。",
296
+ "认证版接收普通素材,服务端按模型 ID 自动校验资格和准备素材。提交前先用 dryRun=true 做只读预检,不用真实付费提交试探资格。materialMode、materialQuoteId 和专用报价工具均为可选兼容能力;正式提交使用当前 pricingSnapshot 和稳定 clientRequestId。资格不足时明确说明差额或待授权事项,并在回复中展示返回的 helpUrl 或 actionUrl 为可点击链接;未返回链接时使用 https://ai-hive.iclip.cn/certified-materials#guide。保留用户指定模型,不擅自切换模型或继续付费提交。费用变化时重新确认。收到任务 ID 后查询原任务,不重复创建。",
250
297
  "latestChange、changelog 和升级信息仅在用户主动询问或与当前任务直接相关时介绍。对用户只说明实际能力、费用、限制、结果和必要操作,不转述字段名、错误码、报价 ID、幂等机制、版本适配或内部排查过程;技术字段和 recoveryAction 供调用端处理,不能替代用户操作说明。用户明确排查接入问题时可以解释所需技术细节。",
251
- "先用 get_user_info 查询余额;返回里带官网地址和充值入口,余额不足时引导用户打开 rechargeUrl 充值后重试。",
298
+ "可用 get_user_info 查询蜂蜜余额、官网地址和充值入口。按 get_user_info 返回的 rechargeGuide 说明账户支付方式,不主动介绍账户未拥有的额度。不能仅凭钱包余额为 0 拒绝调用。只有实际调用返回余额不足时,才引导用户打开 rechargeUrl 充值后重试。",
299
+ "先用 list_models(detail=lite) 选型,再用 get_model 读取所选模型契约。上传前可省略媒体做 dryRun:缺素材不等于参数错误,估价为空时不得当作 0 元或上限。用户接受方案后上传,再带真实媒体预检;同参数同费用不重复确认,费用或条件变化才再确认。正式调用原样回传最后一次预检的 pricingSnapshot,金额保留字符串;仅 materialQuoteId 可自动准备,不能据此省略 pricingSnapshot。",
300
+ "充值提醒只依据本次返回的 activePromotion;有值时用 title、headline 和 promoTiers 转达本场「限时特惠 · 充值加赠」,金额沿用服务端结果,使用「距本场结束」说明 endsAt,并提供 rechargeUrl 的「立即充值」入口。模型调用返回 null 时不追加活动提醒;get_user_info 返回 null 时不推断具体原因。缓存或幂等重放中的 endsAt 已过期时,先重新查询 get_user_info,以新结果为准,不沿用旧截止时间或推算后续活动。",
252
301
  "调用 chat_text、generate_image、generate_video 前,用 get_model 确认参数契约;正式调用必须传稳定的 clientRequestId 幂等键,修正参数后换新值。",
253
302
  "chat_text 同步返回,长推理模型单次可能耗时 1-3 分钟,客户端超时应设为 300 秒以上;等待超时只代表本端不再等待,服务端可能仍在生成,也可能已完成并扣费,超时后复用同一 clientRequestId 和相同业务参数重新调用即可取回首次结果,修正参数后换新值。",
254
303
  ];
@@ -273,7 +322,7 @@ export function createServer(input) {
273
322
  updateNotifier,
274
323
  });
275
324
  for (const tool of createToolDefinitions(client)) {
276
- server.tool(tool.name, tool.description, tool.schema, async (args) => {
325
+ const handler = async (args) => {
277
326
  try {
278
327
  return await tool.handler(args);
279
328
  }
@@ -288,7 +337,18 @@ export function createServer(input) {
288
337
  };
289
338
  throw error;
290
339
  }
291
- });
340
+ };
341
+ if (tool.annotations) {
342
+ server.registerTool(tool.name, {
343
+ title: tool.title,
344
+ description: tool.description,
345
+ inputSchema: tool.schema,
346
+ annotations: tool.annotations,
347
+ }, handler);
348
+ }
349
+ else {
350
+ server.tool(tool.name, tool.description, tool.schema, handler);
351
+ }
292
352
  }
293
353
  return server;
294
354
  }
@@ -0,0 +1,4 @@
1
+ export declare function toolResultContent(value: unknown): {
2
+ type: "text";
3
+ text: string;
4
+ }[];
@@ -0,0 +1,52 @@
1
+ import { z } from "zod";
2
+ // 独立 npm 包不能依赖私有 workspace, 与 contracts 的通知文本通过跨包用例校验.
3
+ const noticeSchema = z.object({
4
+ id: z.string().min(1),
5
+ revision: z.string().min(1),
6
+ kind: z.enum(["RECHARGE_PROMOTION", "ANNOUNCEMENT"]),
7
+ title: z.string().min(1),
8
+ message: z.string().min(1),
9
+ details: z.string(),
10
+ expiresAt: z.string().datetime({ offset: true }).nullable(),
11
+ action: z
12
+ .object({
13
+ label: z.string().min(1),
14
+ url: z
15
+ .string()
16
+ .url()
17
+ .refine((url) => /^https?:\/\//.test(url)),
18
+ })
19
+ .optional(),
20
+ });
21
+ export function toolResultContent(value) {
22
+ if (!value ||
23
+ typeof value !== "object" ||
24
+ Array.isArray(value) ||
25
+ !("userNotices" in value)) {
26
+ return [{ type: "text", text: JSON.stringify(value) }];
27
+ }
28
+ const { userNotices, ...businessResult } = value;
29
+ const notices = Array.isArray(userNotices)
30
+ ? userNotices.flatMap((raw) => {
31
+ const parsed = noticeSchema.safeParse(raw);
32
+ return parsed.success &&
33
+ (parsed.data.expiresAt === null ||
34
+ new Date(parsed.data.expiresAt).getTime() > Date.now())
35
+ ? [parsed.data]
36
+ : [];
37
+ })
38
+ : [];
39
+ return [
40
+ { type: "text", text: JSON.stringify(businessResult) },
41
+ ...notices.map((notice) => ({
42
+ type: "text",
43
+ text: [
44
+ `${notice.title}:${notice.message}`,
45
+ ...(notice.action
46
+ ? [`${notice.action.label}:${notice.action.url}`]
47
+ : []),
48
+ ...(notice.details ? [`充值档位:\n${notice.details}`] : []),
49
+ ].join("\n"),
50
+ })),
51
+ ];
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infimind-next/ai-hive-mcp",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {