kbs-upload-mcp 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/index.mjs +21 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -48,6 +48,23 @@ async function serviceApi(path, init = {}) {
48
48
  return payload;
49
49
  }
50
50
 
51
+ // 服务端返回的 downloadUrl 是 path(/api/kb/documents/download/...),
52
+ // 这里递归补全为 AI_SERVICE_BASE 下的完整链接,用户拿到即可直接打开
53
+ function absolutizeDownloadUrl(data) {
54
+ if (Array.isArray(data)) return data.map(absolutizeDownloadUrl);
55
+ if (data && typeof data === "object") {
56
+ return Object.fromEntries(
57
+ Object.entries(data).map(([k, v]) => [
58
+ k,
59
+ k === "downloadUrl" && typeof v === "string" && v.startsWith("/")
60
+ ? `${AI_SERVICE_BASE}${v}`
61
+ : absolutizeDownloadUrl(v),
62
+ ])
63
+ );
64
+ }
65
+ return data;
66
+ }
67
+
51
68
  // ── 三个工具实现 ─────────────────────────────────────────────────────
52
69
  async function kbListProjects() {
53
70
  return serviceApi("/api/skt/kb/projects");
@@ -59,7 +76,8 @@ async function kbSearch(args) {
59
76
  if (args.conditions?.[k]) sp.set(k, String(args.conditions[k]));
60
77
  }
61
78
  if (args.limit) sp.set("limit", String(args.limit));
62
- return serviceApi(`/api/skt/kb/search?${sp}`);
79
+ const payload = await serviceApi(`/api/skt/kb/search?${sp}`);
80
+ return absolutizeDownloadUrl(payload);
63
81
  }
64
82
 
65
83
  async function kbUpload(args) {
@@ -88,7 +106,7 @@ async function kbUpload(args) {
88
106
  if (!resp.ok) {
89
107
  throw new Error(`ai-service ${resp.status}: ${payload.error || JSON.stringify(payload)}`);
90
108
  }
91
- return { ...payload, uploadVia: "service-relay" };
109
+ return { ...absolutizeDownloadUrl(payload), uploadVia: "service-relay" };
92
110
  }
93
111
 
94
112
  // ── MCP stdio 服务(换行分隔 JSON-RPC 2.0)───────────────────────────
@@ -168,7 +186,7 @@ function handleMessage(line) {
168
186
  rpcResult(id, {
169
187
  protocolVersion: params?.protocolVersion ?? "2025-06-18",
170
188
  capabilities: { tools: {} },
171
- serverInfo: { name: "kbs-upload-mcp", version: "0.1.0" },
189
+ serverInfo: { name: "kbs-upload-mcp", version: "0.2.1" },
172
190
  });
173
191
  } else if (method === "notifications/initialized" || method?.startsWith("notifications/")) {
174
192
  // 通知无需应答
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kbs-upload-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "知识库(KB)MCP:上传技术文档、检索文档、获取项目分组清单(经 ai-service 中转直传私有桶,无需 NOS 凭据)",
5
5
  "type": "module",
6
6
  "bin": {