free-api-mcp-server 0.2.5 → 0.2.7

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
@@ -7,7 +7,7 @@
7
7
  ## 特性
8
8
 
9
9
  - 运行于 Node.js,STDIO 协议(`npx -y free-api-mcp-server` 即可拉起);托管到云函数(如魔搭 / 阿里云函数计算)后会自动转 SSE 并带平台鉴权。
10
- - **游客默认可用(免注册)**:不填令牌也能直接试用(每实例 / 每 IP 每北京日 TTS 30 / ASR 15 / OCR 15 次);填 `FREE_API_TOKEN` 解锁完整额度与高阶能力。
10
+ - **游客模式(免注册)**:**远程** `/mcp`(Streamable HTTP)客户端不填令牌即游客可用——服务端持内置试用令牌,每 IP 每北京日 TTS 30 / ASR 15 / OCR 15 次;**本地** `npx` 公开包**不内置**游客令牌,需自备 `FREE_API_TOKEN`(自建部署时也可配 `TRIAL_LICENSE_TOKEN[_FILE]`),否则启动报错退出。填 `FREE_API_TOKEN` 解锁完整额度与高阶能力。
11
11
  - **每个用户填自己的许可证令牌**(`FREE_API_TOKEN`),计费/额度归属各自账户,互不影响。
12
12
  - 共 **13 个工具**(7 个免费能力 + 6 个付费能力)。
13
13
 
@@ -33,9 +33,10 @@
33
33
 
34
34
  ## 鉴权与配置
35
35
 
36
- ### 游客试用(免注册,默认可用)
37
- 不填任何令牌时自动进入游客模式(stdio 走内置游客试用令牌 `TRIAL_LICENSE_TOKEN[_FILE]`,HTTP 走内置试用令牌),开箱即用:
38
- - 每 IP(远程)/ 每实例(stdio)**每北京日**:`text_to_speech` 30 次、`speech_to_text` 15 次、`ocr_image` 15 次;
36
+ ### 游客试用(免注册)
37
+ - **远程(托管 `/mcp`)**:客户端不填任何令牌即自动进入游客模式(服务端持内置试用令牌),免令牌即用,按公网 IP 计数。
38
+ - **本地(公开 npm 包)**:**不内置**游客试用令牌(fail-closed);stdio 必须自备 `FREE_API_TOKEN`,或自建部署时提供 `TRIAL_LICENSE_TOKEN`(或 `TRIAL_LICENSE_TOKEN_FILE`)才能以游客身份试用,否则进程启动即 fatal 退出,按本机实例计数。
39
+ - 每 IP(远程)/ 每实例(stdio)**每北京日**:`text_to_speech` 30 次、`speech_to_text` 15 次、`ocr_image` 15 次(次日北京 00:00 恢复);
39
40
  - 游客只放 `list_voices`、`get_account` + 上述 3 个能力;`submit_asr_job`(长音频异步)、配音、视频**不开放**(堵旁路);
40
41
  - 真正可靠的全局限额由上游 02 游客专用令牌兜底,客户端计数仅作二级软限。
41
42
 
@@ -115,9 +116,11 @@ FREE_API_TOKEN=<你的令牌> FREE_API_BASE_URL=https://www.open-api.aiconvg.xin
115
116
 
116
117
  ## 错误码
117
118
 
118
- - `AUTH_REQUIRED`:令牌缺失/无效 → 引导注册。
119
- - `INVALID_PARAM`:入参校验失败(本地拦截,不触上游)。
120
- - `UPSTREAM_UNAVAILABLE`:上游网络不可达,稍后重试。
119
+ - `AUTH_REQUIRED`:令牌缺失/无效 → 引导注册(附注册入口与 `FREE_API_TOKEN` 配置示例)。
120
+ - `INVALID_PARAM`:入参校验失败(本地拦截,不触上游;按工具给出针对性提示)。
121
+ - `QUOTA_EXCEEDED`:当日额度用尽 → 响应带 `resetAt`。游客按北京日界**次日 00:00** 恢复;注册用户按北京时间 **08:00** 重置。注册免费账号或购买当日额度包可继续。
122
+ - `UPSTREAM_OVERLOAD`:上游过载(502/503 繁忙)→ 返回 `[UPSTREAM_OVERLOAD] 服务繁忙,请稍后重试(retryAfter N 秒)`,按 `retryAfter` 稍后重试。
123
+ - `UPSTREAM_UNAVAILABLE`:上游网络不可达/暂不可用,稍后重试。
121
124
 
122
125
  ## 许可
123
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "free-api-mcp-server",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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",
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.5",
5
+ "version": "0.2.7",
6
6
  "packages": [
7
7
  {
8
8
  "registryType": "npm",
9
9
  "identifier": "free-api-mcp-server",
10
- "version": "0.2.5",
10
+ "version": "0.2.7",
11
11
  "transport": {
12
12
  "type": "stdio"
13
13
  }
package/src/lib/errors.js CHANGED
@@ -36,6 +36,19 @@ export function invalidParamHint(toolName) {
36
36
 
37
37
  export function errorToMcpContent(err, { toolName } = {}) {
38
38
  if (err instanceof UpstreamError) {
39
+ // 502/503(网关/上游繁忙,或上游返回空体被解析成 INTERNAL_ERROR):统一「服务繁忙,请稍后重试」,
40
+ // retryAfter 按上游给的透出。避免把裸 502/503 当 INTERNAL_ERROR 直出、客户端不知怎么办。
41
+ const isBusy = err.httpStatus === 502 || err.httpStatus === 503
42
+ || err.code === 'UPSTREAM_UNAVAILABLE' || err.code === 'UPSTREAM_OVERLOAD';
43
+ if (isBusy) {
44
+ const code = (err.code === 'UPSTREAM_UNAVAILABLE' || err.code === 'UPSTREAM_OVERLOAD')
45
+ ? err.code
46
+ : (err.httpStatus === 502 ? 'UPSTREAM_OVERLOAD' : 'UPSTREAM_UNAVAILABLE');
47
+ const lines = [`[${code}] 服务繁忙,请稍后重试` + (err.retryAfter != null ? `(retryAfter ${err.retryAfter} 秒)` : '')];
48
+ if (err.retryAfter != null) lines.push(`retryAfter: ${err.retryAfter}s`);
49
+ if (err.requestId) lines.push(`requestId: ${err.requestId}`);
50
+ return { isError: true, content: [{ type: 'text', text: lines.join('\n') }] };
51
+ }
39
52
  const hint = err.code === 'INVALID_PARAM' ? invalidParamHint(toolName) : (HINTS[err.code] || '');
40
53
  const lines = [`[${err.code}] ${err.message}`, '', hint].filter(Boolean);
41
54
  if (err.retryAfter != null) lines.push(`retryAfter: ${err.retryAfter}s`);