free-api-mcp-server 0.2.7 → 0.2.9

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
@@ -30,6 +30,8 @@
30
30
  | 13 | `get_video_transcribe` | 付费·视频 | 否 | 轮询视频转写(返回 text / markdown 分段 / 字数 / 实扣积分) |
31
31
 
32
32
  > 「免费」= 标准引擎、按每日免费额度计量、不扣积分;「付费」= 按积分计费(配音按字、视频按字数)。查询/轮询类工具不计费。
33
+ >
34
+ > **ASR 准度说明**:标准引擎 ASR 为 SenseVoice-Small(**自语言识别 auto**,不强制/不区分语种),对**技术术语、中英混识**及短句/数字有准度上限,这是**免费档的设计取舍(非 bug)**;需要更高识别精度的场景请改用 premium 引擎。
33
35
 
34
36
  ## 鉴权与配置
35
37
 
@@ -122,6 +124,17 @@ FREE_API_TOKEN=<你的令牌> FREE_API_BASE_URL=https://www.open-api.aiconvg.xin
122
124
  - `UPSTREAM_OVERLOAD`:上游过载(502/503 繁忙)→ 返回 `[UPSTREAM_OVERLOAD] 服务繁忙,请稍后重试(retryAfter N 秒)`,按 `retryAfter` 稍后重试。
123
125
  - `UPSTREAM_UNAVAILABLE`:上游网络不可达/暂不可用,稍后重试。
124
126
 
127
+ ## 最近变更
128
+
129
+ ### 0.2.9(2026-11-26)
130
+ - **发布修正(0.2.9)**:npm 上此前的 `0.2.8` 实为旧内容(`c04c9ad`,仅 account/voices/tts/server 等部分工具带 `outputSchema`)。本 `0.2.9` 打包 HEAD 全量修复重发——**13 个工具全部声明 `outputSchema` 并随结果返回 `structuredContent`**,OCR `conf/bbox`+`mode`、`get_account`→`ipHash` 等一并生效。
131
+ - **OCR 字段统一**:`blocks[].conf`(置信度 0–1)/ `blocks[].bbox`(四点坐标 `[[x,y],...]`),与引擎返回一致;旧文档的 `confidence` / `box` 作废。
132
+ - **OCR `mode` 三档生效**:`full` 只回 `fullText`(`blocks` 为空)、`structured` 只回 `blocks`(`fullText` 为空)、`auto` 两者都回;在 BFF `/v1/ocr` 层过滤,REST 与 MCP 一致。
133
+ - **多 content 块取值约定**:只读 `content[0]`(纯 JSON)或 `structuredContent`,**不要**拼接多个 content 块(游客试用时第二块是「剩余次数」提示)。本版起每个工具都随结果返回 `structuredContent`(与 `content[0].text` 同源)。
134
+ - **`get_account` 游客视图**:`personal.ip` 改为 `personal.ipHash`(客户端 IP 的 sha256 前 12 位),不再回传明文或网段。
135
+ - **`outputSchema` 全覆盖**:13 个工具全部声明 `outputSchema`,便于客户端结构化解析与平台审核。
136
+ - **ASR 免费档准度说明**:标准引擎 ASR 为 SenseVoice-Small(**自语言识别 auto**,不强制/不区分语种),对**技术术语、中英混识**及短句/数字有准度上限,这是**免费档的设计取舍(非 bug)**;对精度要求高的场景请改用 premium 引擎。
137
+
125
138
  ## 许可
126
139
 
127
140
  MIT,见 [LICENSE](LICENSE)。
package/package.json CHANGED
@@ -1,17 +1,37 @@
1
1
  {
2
2
  "name": "free-api-mcp-server",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "mcpName": "io.github.aiconvg/free-api-mcp",
5
5
  "type": "module",
6
6
  "description": "MCP server exposing the free TTS/ASR/OCR open API (voices, tts, asr, ocr, account, dubbing, video) over stdio and Streamable HTTP",
7
7
  "license": "MIT",
8
8
  "author": "aiconvg",
9
- "keywords": ["mcp", "model-context-protocol", "modelcontextprotocol", "tts", "asr", "ocr", "text-to-speech", "speech-to-text", "dubbing", "video-transcription", "ai"],
9
+ "keywords": [
10
+ "mcp",
11
+ "model-context-protocol",
12
+ "modelcontextprotocol",
13
+ "tts",
14
+ "asr",
15
+ "ocr",
16
+ "text-to-speech",
17
+ "speech-to-text",
18
+ "dubbing",
19
+ "video-transcription",
20
+ "ai"
21
+ ],
10
22
  "homepage": "https://www.free-api.aiconvg.xin",
11
- "repository": { "type": "git", "url": "git+https://github.com/aiconvg/free-api-mcp-server.git" },
12
- "bugs": { "url": "https://github.com/aiconvg/free-api-mcp-server/issues" },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/aiconvg/free-api-mcp-server.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/aiconvg/free-api-mcp-server/issues"
29
+ },
13
30
  "main": "src/index.js",
14
- "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "registry": "https://registry.npmjs.org"
34
+ },
15
35
  "bin": {
16
36
  "free-api-mcp": "src/index.js"
17
37
  },
package/server.json CHANGED
@@ -2,12 +2,12 @@
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-09-29/server.schema.json",
3
3
  "name": "io.github.aiconvg/free-api-mcp",
4
4
  "description": "Free API MCP server: text-to-speech, speech-to-text, ASR jobs, OCR, multi-voice dubbing and video transcription over the free open API. Per-user Bearer token; standard engine free.",
5
- "version": "0.2.7",
5
+ "version": "0.2.9",
6
6
  "packages": [
7
7
  {
8
8
  "registryType": "npm",
9
9
  "identifier": "free-api-mcp-server",
10
- "version": "0.2.7",
10
+ "version": "0.2.9",
11
11
  "transport": {
12
12
  "type": "stdio"
13
13
  }
package/src/http.js CHANGED
@@ -1,11 +1,13 @@
1
- // HTTP 传输:Streamable HTTP + /healthz。
1
+ // HTTP 传输:Streamable HTTP(仅 POST) + /healthz + /version。
2
2
  // 令牌:每次请求从 Authorization: Bearer 提取,用 AsyncLocalStorage 传给 handler(请求级隔离)。
3
3
  // 试用:无令牌 + TRIAL_LICENSE_TOKEN 已配置 → 进入试用上下文(IP 计数),
4
4
  // Redis 不可用时 fail-closed,只放行只读工具并提示注册。
5
+ // 说明:本服务只支持 POST /mcp(Streamable HTTP,JSON 响应),**不提供 SSE 推送**;
6
+ // 非 POST 的 /mcp 明确 405,/sse 明确 404,避免把 GET 塞进 transport 挂起。
5
7
  import express from 'express';
6
8
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
7
9
  import { requestContext, logger } from './context.js';
8
- import { buildServer } from './server.js';
10
+ import { buildServer, PKG_VERSION } from './server.js';
9
11
  import { initTrialStore, trialStoreAvailable } from './lib/trialStore.js';
10
12
  import { trialEnabled } from './lib/trial.js';
11
13
 
@@ -19,10 +21,12 @@ function extractBearer(req) {
19
21
  return m ? m[1].trim() : null;
20
22
  }
21
23
 
22
- // 真实客户端 IP 提取。信任边界:**只有当连接对端是本机回环**(自有反代 -> 本进程)
23
- // 时才信任反代覆写的转发头——反代用 X-Real-IP 覆盖,客户端自带的 X-Real-IP/XFF 一律被盖掉、伪造不了。
24
- // 非回环对端(理论上不应出现,端口只绑回环)一律直接用连接 IP,不信任任何头;
25
- // 优先取 X-Real-IP,取不到再回退。
24
+ // 真实客户端 IP 提取。信任边界:**只有当连接对端是本机回环**(自有 nginx 反代 127.0.0.1→8420)
25
+ // 时才信任 nginx 覆写的转发头——nginx 用 `proxy_set_header X-Real-IP $remote_addr` 覆盖,
26
+ // 客户端自带的 X-Real-IP/XFF 一律被盖掉、伪造不了。非回环对端(理论上不应出现,端口只绑回环)
27
+ // 一律直接用连接 IP,不信任任何头。
28
+ // ⚠ 两个域名 /mcp 都用 `X-Forwarded-For $proxy_add_x_forwarded_for`(无回环尾、末位是真实客户端),
29
+ // 旧逻辑「末位须为回环否则回退 socket」会把真实 IP 全塌成 127.0.0.1 一个桶,故改为 X-Real-IP 优先。
26
30
  function isLoopback(addr) {
27
31
  return addr === '127.0.0.1' || addr === '::1' || addr === '::ffff:127.0.0.1';
28
32
  }
@@ -35,7 +39,7 @@ export function clientIp(req) {
35
39
  const remote = req.socket?.remoteAddress || 'unknown';
36
40
  // 非回环对端:不信任任何转发头
37
41
  if (!isLoopback(remote)) return normalizeIp(remote) || remote;
38
- // 回环对端(自有反代):优先 X-Real-IP(上游覆写,不可伪造)
42
+ // 回环对端(自有 nginx):优先 X-Real-IP($remote_addr 覆写,不可伪造)
39
43
  const xri = req.headers['x-real-ip'];
40
44
  if (typeof xri === 'string' && xri.trim()) return normalizeIp(xri) || remote;
41
45
  // 回退:兼容旧部署——XFF 末位为回环则取倒数第二位
@@ -44,7 +48,7 @@ export function clientIp(req) {
44
48
  const parts = xff.split(',').map((s) => s.trim()).filter(Boolean);
45
49
  const last = parts[parts.length - 1];
46
50
  if (isLoopback(last)) return parts.length >= 2 ? normalizeIp(parts[parts.length - 2]) : remote;
47
- // XFF 无回环尾:末位即真实客户端
51
+ // proxy_add_x_forwarded_for 无回环尾:末位即真实客户端
48
52
  if (parts.length >= 1) return normalizeIp(parts[parts.length - 1]);
49
53
  }
50
54
  return remote;
@@ -60,11 +64,18 @@ export async function runHttp() {
60
64
  app.get('/healthz', (_req, res) => {
61
65
  res.json({
62
66
  ok: true,
67
+ name: 'free-api-mcp',
68
+ version: PKG_VERSION,
63
69
  transport: 'http',
64
70
  trial: trialEnabled() ? (trialStoreAvailable() ? 'ready' : 'degraded') : 'off',
65
71
  });
66
72
  });
67
73
 
74
+ // 版本自检(P1-6):无需工具调用即可探版本
75
+ app.get('/version', (_req, res) => {
76
+ res.json({ name: 'free-api-mcp', version: PKG_VERSION, transport: 'http' });
77
+ });
78
+
68
79
  // Origin 白名单(SDK 只在 DNS rebinding 校验里做 Host,Origin 需自行把关)
69
80
  app.use('/mcp', (req, res, next) => {
70
81
  const origin = req.headers.origin;
@@ -74,7 +85,8 @@ export async function runHttp() {
74
85
  next();
75
86
  });
76
87
 
77
- app.all('/mcp', (req, res) => {
88
+ // 仅 POST /mcp 进入 transport(Streamable HTTP,无会话态,每请求一个传输实例)
89
+ app.post('/mcp', (req, res) => {
78
90
  const token = extractBearer(req);
79
91
  // 无令牌:试用启用且存储可用 → 试用上下文;否则放行让 handler 抛 AUTH_REQUIRED(引导注册)
80
92
  let trialCtx = null;
@@ -84,7 +96,6 @@ export async function runHttp() {
84
96
  } // Redis 不可用:fail-closed,不计费工具会被闸门拦下引导注册
85
97
  }
86
98
  requestContext.run({ token, trial: trialCtx, clientIp: clientIp(req) }, async () => {
87
- // 每请求一个传输实例(无会话态,最简且并发安全)
88
99
  const transport = new StreamableHTTPServerTransport({
89
100
  sessionIdGenerator: undefined,
90
101
  enableJsonResponse: true,
@@ -102,10 +113,22 @@ export async function runHttp() {
102
113
  });
103
114
  });
104
115
 
116
+ // 非 POST 的 /mcp:明确 405(不再把 GET 塞进 transport 挂起 15s)
117
+ app.all('/mcp', (req, res) => {
118
+ res.set('Allow', 'POST').status(405)
119
+ .json({ error: 'Method Not Allowed: /mcp 仅支持 POST(Streamable HTTP,JSON 响应)' });
120
+ });
121
+
122
+ // 本服务不提供 SSE 推送:/sse 明确 404,避免被当作事件流
123
+ app.all('/sse', (req, res) => {
124
+ res.status(404)
125
+ .json({ error: 'Not Found: 本服务不提供 SSE/事件流;请用 POST /mcp(Streamable HTTP)' });
126
+ });
127
+
105
128
  await new Promise((resolve, reject) => {
106
- // 只监听回环:托管端点仅经反代对外,避免端口直接暴露公网
129
+ // 只监听回环:托管端点仅经 nginx 反代对外,避免端口直接暴露公网
107
130
  const srv = app.listen(PORT, '127.0.0.1', () => {
108
- logger.info('http.started', { port: PORT, origins: ALLOWED_ORIGINS.length || 'any' });
131
+ logger.info('http.started', { port: PORT, origins: ALLOWED_ORIGINS.length || 'any', version: PKG_VERSION });
109
132
  resolve();
110
133
  });
111
134
  srv.on('error', reject);
@@ -1,7 +1,7 @@
1
1
  import { getRequestToken, getRequestTrial, getRequestClientIp, logger } from '../context.js';
2
2
  import { trialToken } from './trial.js';
3
3
 
4
- // 上游错误 envelope 见 openapi 契约 components.schemas.Error:
4
+ // 上游错误 envelope 见 16 号仓主契约 components.schemas.Error:
5
5
  // { code, message, requestId, retryAfter?, resetAt?, quota? }
6
6
  export class UpstreamError extends Error {
7
7
  constructor(payload, httpStatus) {
@@ -65,3 +65,17 @@ export function rollbackLocal(ticket) {
65
65
  logger.warn('trial.local_rollback_error', { err: String(e?.message || e) });
66
66
  }
67
67
  }
68
+
69
+ // 只读:取本实例当个北京日各可试能力已用次数(stdio 游客 get_account 个人视图用)。
70
+ // 返回 { <tool>: { used, limit, remaining } }。
71
+ export function getLocalUsage() {
72
+ const limits = localLimits();
73
+ const db = load();
74
+ const out = {};
75
+ for (const tool of Object.keys(limits)) {
76
+ const used = Number(db[tool] || 0);
77
+ const limit = limits[tool];
78
+ out[tool] = { used, limit, remaining: Math.max(0, limit - used) };
79
+ }
80
+ return out;
81
+ }
@@ -81,6 +81,23 @@ export async function consumeTrial(ip, tool, limits) {
81
81
  }
82
82
  }
83
83
 
84
+ // 只读:取某 IP 当个北京日各可试能力已用次数(不扣减、不建键),供 get_account 展示个人额度视图。
85
+ // 返回 { <tool>: { used, limit, remaining } };存储不可用时按 0 计(fail-open,仅展示用)。
86
+ export async function getTrialUsage(ip, limits) {
87
+ const out = {};
88
+ const day = beijingDayKey();
89
+ const h = ipHash(ip);
90
+ for (const tool of Object.keys(limits)) {
91
+ const limit = Number(limits[tool]) || 0;
92
+ let used = 0;
93
+ if (trialStoreAvailable()) {
94
+ try { const v = await client.get(`trial:use:${h}:${day}:${tool}`); used = v != null ? Number(v) : 0; } catch { /* 展示用,读失败按 0 */ }
95
+ }
96
+ out[tool] = { used, limit, remaining: Math.max(0, limit - used) };
97
+ }
98
+ return out;
99
+ }
100
+
84
101
  // 上游调用失败时回滚本次扣减(额度在后端本就"失败不扣",MCP 试用计数保持同口径)
85
102
  export async function rollbackTrial(token) {
86
103
  if (!trialStoreAvailable() || !token) return;
package/src/server.js CHANGED
@@ -23,7 +23,7 @@ import { fileURLToPath } from 'node:url';
23
23
 
24
24
  // 版本单一事实源:以 package.json.version 为准,避免运行时 Server 版本与包版本漂移
25
25
  // (此前此处写死 '0.2.0',与 package.json/server.json 的 0.1.0 不一致)。
26
- const PKG_VERSION = JSON.parse(
26
+ export const PKG_VERSION = JSON.parse(
27
27
  readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
28
28
  ).version;
29
29
 
@@ -79,6 +79,7 @@ export function buildServer() {
79
79
  title: t.title,
80
80
  description: t.description,
81
81
  inputSchema: t.inputSchema,
82
+ ...(t.outputSchema ? { outputSchema: t.outputSchema } : {}),
82
83
  annotations: TOOL_ANNOTATIONS[t.name],
83
84
  })),
84
85
  }));
@@ -156,14 +157,19 @@ export function buildServer() {
156
157
  try {
157
158
  const result = await tool.handler(parsed.data);
158
159
  logger.info('tool.call', { tool: name, ms: Date.now() - started, ok: true });
159
- let text = JSON.stringify(result, null, 2);
160
- if (trialTicket) {
161
- text += `\n\n${trialRemainingNote(name, trialTicket.remaining, trialTicket.limits)}`;
160
+ // P0-1:content[0].text 只放纯 JSON(保证客户端 json.loads 能过)。
161
+ // 游客剩余次数/注册引导改放「第二个 content block」(audience=assistant),不混入机器可解析的 JSON。
162
+ const content = [{ type: 'text', text: JSON.stringify(result, null, 2) }];
163
+ const notes = [];
164
+ if (trialTicket) notes.push(trialRemainingNote(name, trialTicket.remaining, trialTicket.limits));
165
+ if (localTicket) notes.push(trialRemainingNote(name, localTicket.remaining, localTicket.limits));
166
+ if (notes.length) {
167
+ content.push({ type: 'text', text: notes.join('\n'), annotations: { audience: ['assistant'] } });
162
168
  }
163
- if (localTicket) {
164
- text += `\n\n${trialRemainingNote(name, localTicket.remaining, localTicket.limits)}`;
165
- }
166
- return { content: [{ type: 'text', text }] };
169
+ const out = { content };
170
+ // P1-6:声明了 outputSchema 的工具,额外回结构化结果(与 content[0].text 的纯 JSON 同源)
171
+ if (tool.outputSchema && result && typeof result === 'object') out.structuredContent = result;
172
+ return out;
167
173
  } catch (err) {
168
174
  logger.warn('tool.call', {
169
175
  tool: name,
@@ -1,15 +1,71 @@
1
1
  import { z } from 'zod';
2
+ import { createHash } from 'node:crypto';
2
3
  import { api } from '../lib/apiClient.js';
4
+ import { getRequestTrial, isGuestMode } from '../context.js';
5
+ import { GUEST_LIMITS, nextBeijingResetAt } from '../lib/guestGate.js';
6
+ import { getTrialUsage } from '../lib/trialStore.js';
7
+ import { getLocalUsage } from '../lib/localCounter.js';
8
+
9
+ // P2-6:personal.ip 原只掩最后一段(113.88.12.*),仍暴露出口网段/归属地线索。
10
+ // 改为不可逆哈希(sha256 前 12 hex),只用于「同一 IP 复用」自证,不泄露任何网段信息。
11
+ function hashIp(ip) {
12
+ const s = String(ip || '');
13
+ if (!s) return null;
14
+ return 'sha256:' + createHash('sha256').update(s).digest('hex').slice(0, 12);
15
+ }
16
+
17
+ // P0-2:游客/trial 上下文追加「本 IP / 本实例」的个人额度视图(30/15/15,北京 00:00 重置)。
18
+ // 注册令牌路径不追加(personal=null),行为与旧版一致。
19
+ async function buildPersonalView() {
20
+ const trial = getRequestTrial();
21
+ const guest = !!trial?.active || isGuestMode();
22
+ if (!guest) return null;
23
+ let usage; let scope; let ip = null;
24
+ if (trial?.active) {
25
+ usage = await getTrialUsage(trial.ip, GUEST_LIMITS);
26
+ scope = 'ip'; ip = hashIp(trial.ip);
27
+ } else {
28
+ usage = getLocalUsage();
29
+ scope = 'local-instance';
30
+ }
31
+ const capabilities = {};
32
+ let exhausted = false;
33
+ for (const tool of Object.keys(GUEST_LIMITS)) {
34
+ const u = usage[tool] || { used: 0, limit: GUEST_LIMITS[tool], remaining: GUEST_LIMITS[tool] };
35
+ capabilities[tool] = { used: u.used, limit: u.limit, remaining: u.remaining };
36
+ if (u.remaining <= 0) exhausted = true;
37
+ }
38
+ return {
39
+ scope,
40
+ ...(ip ? { ipHash: ip } : {}),
41
+ resetAt: nextBeijingResetAt(),
42
+ capabilities,
43
+ exhausted,
44
+ note: `游客个人额度视图(${scope === 'ip' ? '本 IP' : '本实例'},MCP 计数,北京日 00:00 重置);上游 quota 为共享游客池口径(app.limit 实测约 3600–4000),二者不同维,勿混用。`,
45
+ ...(exhausted ? { hint: '本 IP 已用尽,可注册或更换网络:https://www.free-api.aiconvg.xin' } : {}),
46
+ };
47
+ }
3
48
 
4
49
  export const getAccountTool = {
5
50
  name: 'get_account',
6
51
  title: '查询额度与账户状态',
7
52
  description:
8
53
  '查询当前令牌的应用档位(free/paid)、各能力当日额度用量(tts/asr/ocr 的 used/limit/remaining)、' +
9
- '额度重置时间与许可证有效期。只读,不消耗额度。',
54
+ '额度重置时间与许可证有效期。只读,不消耗额度。游客模式下额外返回 personal 字段(本 IP/本实例的个人 30/15/15 用量与北京 00:00 重置)。',
10
55
  inputSchema: { type: 'object', properties: {} },
56
+ outputSchema: {
57
+ type: 'object', additionalProperties: true,
58
+ properties: {
59
+ requestId: { type: 'string' },
60
+ app: { type: 'object', additionalProperties: true },
61
+ quota: { type: 'object', additionalProperties: true },
62
+ personal: { type: 'object', additionalProperties: true, description: '游客个人额度视图(仅 guest/trial 返回);ipHash=客户端 IP 的 sha256 前 12 位,不回传明文/网段' },
63
+ },
64
+ },
11
65
  zodSchema: z.object({}),
12
66
  async handler() {
13
- return api.getAccount();
67
+ const base = await api.getAccount();
68
+ const personal = await buildPersonalView();
69
+ return personal ? { ...base, personal } : base;
14
70
  },
15
71
  };
@@ -15,6 +15,21 @@ export const asrGetTool = {
15
15
  taskId: { type: 'string', description: 'submit_asr_job 返回的任务 ID' },
16
16
  },
17
17
  },
18
+ outputSchema: {
19
+ type: 'object', additionalProperties: true,
20
+ properties: {
21
+ requestId: { type: 'string' },
22
+ taskId: { type: 'string' },
23
+ status: { type: 'string', enum: ['queued', 'running', 'done', 'failed'] },
24
+ text: { type: 'string', description: 'status=done 时返回' },
25
+ duration: { type: 'number', nullable: true },
26
+ segments_done: { type: 'integer', description: '轮询进度' },
27
+ processed_s: { type: 'number', description: '已处理秒数' },
28
+ segments: { type: 'array', items: { type: 'object', additionalProperties: true } },
29
+ engine: { type: 'string' },
30
+ error: { type: 'string', description: 'status=failed 时返回,额度已自动返还' },
31
+ },
32
+ },
18
33
  zodSchema: z.object({ taskId: z.string().min(1, 'taskId 必填') }),
19
34
  async handler(args) {
20
35
  return api.asrGet(args.taskId);
@@ -16,6 +16,16 @@ export const asrSubmitTool = {
16
16
  lang: { type: 'string', description: '语种,auto 自动判定(默认)' },
17
17
  },
18
18
  },
19
+ outputSchema: {
20
+ type: 'object', additionalProperties: true,
21
+ properties: {
22
+ requestId: { type: 'string' },
23
+ taskId: { type: 'string' },
24
+ status: { type: 'string', enum: ['queued', 'running'] },
25
+ duration: { type: 'number', nullable: true },
26
+ quota: { type: 'object', additionalProperties: true },
27
+ },
28
+ },
19
29
  zodSchema: z.object({
20
30
  audioUrl: z.string().url('audioUrl 必须是 http(s) 公网 URL'),
21
31
  lang: z.string().optional(),
@@ -17,6 +17,21 @@ export const asrSyncTool = {
17
17
  engine: { type: 'string', enum: ['standard', 'premium'], description: '引擎:默认 standard(免费);premium 需付费档,商业模型按积分计费' },
18
18
  },
19
19
  },
20
+ outputSchema: {
21
+ type: 'object', additionalProperties: true,
22
+ properties: {
23
+ requestId: { type: 'string' },
24
+ text: { type: 'string' },
25
+ duration: { type: 'number' },
26
+ segments: {
27
+ type: 'array',
28
+ items: { type: 'object', properties: { start: { type: 'number' }, end: { type: 'number' }, text: { type: 'string' } } },
29
+ },
30
+ engine: { type: 'string' },
31
+ language: { type: 'string', nullable: true },
32
+ quota: { type: 'object', additionalProperties: true },
33
+ },
34
+ },
20
35
  zodSchema: z.object({
21
36
  audioUrl: z.string().url('audioUrl 必须是 http(s) 公网 URL'),
22
37
  lang: z.string().optional(),
@@ -13,6 +13,15 @@ export const dubbingVoicesTool = {
13
13
  '返回每个音色的 id、性别、语言、单价 creditsPerChar(免费音色为 0)。' +
14
14
  '提交配音前先从这里选音色 id;不计费。',
15
15
  inputSchema: { type: 'object', properties: {} },
16
+ outputSchema: {
17
+ type: 'object', additionalProperties: true,
18
+ properties: {
19
+ requestId: { type: 'string' },
20
+ data: {
21
+ description: '上游音色目录(可能是数组或 {voices:[...]} 对象);每项含 id/voice、gender、language、creditsPerChar(免费音色=0)',
22
+ },
23
+ },
24
+ },
16
25
  zodSchema: z.object({}).optional(),
17
26
  async handler() {
18
27
  return api.dubbingVoices();
@@ -46,6 +55,18 @@ export const dubbingSubmitTool = {
46
55
  },
47
56
  },
48
57
  },
58
+ outputSchema: {
59
+ type: 'object', additionalProperties: true,
60
+ properties: {
61
+ requestId: { type: 'string' },
62
+ taskId: { type: 'string', description: '大任务异步(HTTP 202)返回,用 get_dubbing_task 轮询' },
63
+ status: { type: 'string' },
64
+ audioUrl: { type: 'string', description: '小任务同步完成(HTTP 200)时返回' },
65
+ srtUrl: { type: 'string', description: '字幕 SRT(同步完成时返回)' },
66
+ creditCost: { type: 'number', description: '202=预估冻结;200=实扣' },
67
+ message: { type: 'string' },
68
+ },
69
+ },
49
70
  zodSchema: z.object({
50
71
  segments: z.array(z.object({
51
72
  voice: z.string().min(1, 'voice 必填'),
@@ -69,6 +90,20 @@ export const dubbingGetTool = {
69
90
  required: ['taskId'],
70
91
  properties: { taskId: { type: 'string', description: 'dubbing_submit 异步返回的任务 ID' } },
71
92
  },
93
+ outputSchema: {
94
+ type: 'object', additionalProperties: true,
95
+ properties: {
96
+ requestId: { type: 'string' },
97
+ taskId: { type: 'string' },
98
+ status: { type: 'string', enum: ['queued', 'running', 'succeeded', 'partial', 'failed', 'cancelled', 'canceled'] },
99
+ audioUrl: { type: 'string' },
100
+ srtUrl: { type: 'string' },
101
+ chargedCredits: { type: 'number', description: '终态实扣积分' },
102
+ segments: { type: 'array', items: { type: 'object', additionalProperties: true } },
103
+ error: { type: 'string' },
104
+ message: { type: 'string' },
105
+ },
106
+ },
72
107
  zodSchema: z.object({ taskId: z.string().min(1, 'taskId 必填') }),
73
108
  async handler(args) {
74
109
  return api.dubbingGet(args.taskId);
@@ -86,6 +121,13 @@ export const dubbingCancelTool = {
86
121
  required: ['taskId'],
87
122
  properties: { taskId: { type: 'string', description: 'dubbing_submit 异步返回的任务 ID' } },
88
123
  },
124
+ outputSchema: {
125
+ type: 'object', additionalProperties: true,
126
+ properties: {
127
+ requestId: { type: 'string' },
128
+ data: { description: '上游取消结果(含 cancelled/status 等)' },
129
+ },
130
+ },
89
131
  zodSchema: z.object({ taskId: z.string().min(1, 'taskId 必填') }),
90
132
  async handler(args) {
91
133
  return api.dubbingCancel(args.taskId);
package/src/tools/ocr.js CHANGED
@@ -5,15 +5,38 @@ export const ocrTool = {
5
5
  name: 'ocr_image',
6
6
  title: '图片文字识别',
7
7
  description:
8
- '识别单张图片(png/jpg/webp,≤ 8MB)中的文字,返回 fullText 与分块(含置信度/坐标)。' +
8
+ '识别单张图片(png/jpg/webp,≤ 8MB)中的文字,返回 fullText 与分块(含置信度 conf/坐标 bbox)。' +
9
9
  '计费工具(占 1 次当日 OCR 额度,失败不扣)。imageUrl 必须是公网可访问 URL;' +
10
- '本地文件路径无法使用。mode=full 只出全文,structured 出带坐标分块。',
10
+ '本地文件路径无法使用。mode=full 只出全文(blocks 为空),structured 只出带 conf/bbox 的分块(fullText 为空),auto 两者都出。' +
11
+ '结果取值:读 content[0](纯 JSON)或 structuredContent,不要把多个 content 块拼接。',
11
12
  inputSchema: {
12
13
  type: 'object',
13
14
  required: ['imageUrl'],
14
15
  properties: {
15
16
  imageUrl: { type: 'string', description: '图片公网 URL,≤ 8MB' },
16
- mode: { type: 'string', enum: ['auto', 'full', 'structured'], description: '默认 auto' },
17
+ mode: { type: 'string', enum: ['auto', 'full', 'structured'], description: '默认 auto(两者都出);full 只全文;structured 只分块' },
18
+ },
19
+ },
20
+ outputSchema: {
21
+ type: 'object', additionalProperties: true,
22
+ properties: {
23
+ requestId: { type: 'string' },
24
+ fullText: { type: 'string', description: '整图拼接全文;mode=structured 时为空串' },
25
+ blocks: {
26
+ type: 'array',
27
+ description: '分块结果;mode=full 时为空数组。每块含 text/conf/bbox',
28
+ items: {
29
+ type: 'object',
30
+ properties: {
31
+ text: { type: 'string' },
32
+ conf: { type: 'number', description: '置信度 0–1' },
33
+ bbox: { type: 'array', description: '四点坐标 [[x,y],...]', items: { type: 'array', items: { type: 'number' } } },
34
+ },
35
+ },
36
+ },
37
+ engine: { type: 'string' },
38
+ mode: { type: 'string', enum: ['auto', 'full', 'structured'] },
39
+ quota: { type: 'object', additionalProperties: true },
17
40
  },
18
41
  },
19
42
  zodSchema: z.object({
package/src/tools/tts.js CHANGED
@@ -20,10 +20,18 @@ export const ttsTool = {
20
20
  engine: { type: 'string', enum: ['standard', 'premium'], description: '引擎:默认 standard(免费);premium 需付费档,按积分计费' },
21
21
  },
22
22
  },
23
+ outputSchema: {
24
+ type: 'object', additionalProperties: true,
25
+ properties: {
26
+ requestId: { type: 'string' },
27
+ audioUrl: { type: 'string' },
28
+ },
29
+ },
23
30
  zodSchema: z.object({
24
- text: z.string().min(1, 'text 不能为空').max(300, 'text 超过 300 字符上限,请分段多次调用'),
25
- voice: z.string().min(1, 'voice 必填(用 list_voices 查询)'),
26
- speed: z.number().min(0.5).max(2.0).optional(),
31
+ // P1-5:zod 消息不再复述「≤300」数字,避免与 invalidParamHint 重复;具体上限只在 hint 出现一次。
32
+ text: z.string().min(1, '不能为空').max(300, '超过长度上限,请分段多次调用'),
33
+ voice: z.string().min(1, '必填(用 list_voices 查询)'),
34
+ speed: z.number().min(0.5, '不得小于 0.5').max(2.0, '不得大于 2.0').optional(),
27
35
  format: z.enum(['wav']).optional(),
28
36
  engine: z.enum(['standard', 'premium']).optional(),
29
37
  }),
@@ -21,6 +21,16 @@ export const videoSubmitTool = {
21
21
  url: { type: 'string', description: '视频链接(平台分享短链或完整链接,也可传整段分享文案,服务端自动提取)' },
22
22
  },
23
23
  },
24
+ outputSchema: {
25
+ type: 'object', additionalProperties: true,
26
+ properties: {
27
+ requestId: { type: 'string' },
28
+ taskId: { type: 'string' },
29
+ status: { type: 'string' },
30
+ credits: { type: 'number', description: '提交时冻结的预估积分' },
31
+ message: { type: 'string' },
32
+ },
33
+ },
24
34
  zodSchema: z.object({
25
35
  url: z.string().min(8, 'url 必填').max(600, 'url 过长(如为分享文案请只保留链接所在文案 ≤600 字符)'),
26
36
  }),
@@ -41,6 +51,20 @@ export const videoGetTool = {
41
51
  required: ['taskId'],
42
52
  properties: { taskId: { type: 'string', description: 'submit_video_transcribe 返回的任务 ID' } },
43
53
  },
54
+ outputSchema: {
55
+ type: 'object', additionalProperties: true,
56
+ properties: {
57
+ requestId: { type: 'string' },
58
+ taskId: { type: 'string' },
59
+ status: { type: 'string', enum: ['queued', 'downloading', 'transcribing', 'correcting', 'done', 'failed'] },
60
+ text: { type: 'string', description: 'status=done 返回的转写稿' },
61
+ markdown: { type: 'string', description: 'markdown 分段稿' },
62
+ chars: { type: 'integer', description: '字数' },
63
+ credits: { type: 'number', description: '实扣积分' },
64
+ error: { type: 'string', description: 'status=failed 时返回,冻结已全额解冻' },
65
+ message: { type: 'string' },
66
+ },
67
+ },
44
68
  zodSchema: z.object({ taskId: z.string().min(1, 'taskId 必填') }),
45
69
  async handler(args) {
46
70
  return api.videoGet(args.taskId);
@@ -1,20 +1,44 @@
1
1
  import { z } from 'zod';
2
2
  import { api } from '../lib/apiClient.js';
3
3
 
4
+ function normLang(s) { return String(s || '').trim().toLowerCase().replace(/-/g, '_'); }
5
+
4
6
  export const listVoicesTool = {
5
7
  name: 'list_voices',
6
8
  title: '列出可用音色',
7
9
  description:
8
10
  '获取 TTS 可用音色列表(仅免费开源音色,不计额度)。调用 text_to_speech 前必须先从这里拿 voice 参数,' +
9
- '直接猜测音色名会返回 VOICE_NOT_ALLOWED。',
11
+ '直接猜测音色名会返回 VOICE_NOT_ALLOWED。不传 lang 返回全部;传 lang 按语言前缀过滤(zh→zh_CN、en→en_US…;matcha/fanchen 归 zh_CN)。',
10
12
  inputSchema: {
11
13
  type: 'object',
12
14
  properties: {
13
- lang: { type: 'string', description: '按语言筛选,如 zh / en / ja,默认 zh' },
15
+ lang: { type: 'string', description: '按语言筛选(前缀匹配),如 zh / en / ja;不传则返回全部音色' },
16
+ },
17
+ },
18
+ outputSchema: {
19
+ type: 'object', additionalProperties: true,
20
+ properties: {
21
+ requestId: { type: 'string' },
22
+ count: { type: 'number' },
23
+ voices: { type: 'array', items: { type: 'object', additionalProperties: true } },
14
24
  },
15
25
  },
16
26
  zodSchema: z.object({ lang: z.string().optional() }),
17
27
  async handler(args) {
18
- return api.listVoices(args?.lang);
28
+ const res = await api.listVoices(); // { requestId, voices:[{voice,name,lang,format,engine}], count, note }
29
+ const q = normLang(args?.lang);
30
+ if (!q) return res;
31
+ const all = Array.isArray(res?.voices) ? res.voices : [];
32
+ const voices = all.filter((v) => {
33
+ const l = normLang(v?.lang);
34
+ return l === q || l.split('_')[0] === q || l.startsWith(q + '_');
35
+ });
36
+ return {
37
+ ...res,
38
+ voices,
39
+ count: voices.length,
40
+ lang: args.lang,
41
+ note: `${res?.note ? res.note + ';' : ''}已按 lang=${args.lang} 过滤(前缀匹配)`,
42
+ };
19
43
  },
20
44
  };