@clawdao/limschain-agent 0.5.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.
- package/.env.example +41 -0
- package/CHANGELOG.md +223 -0
- package/Dockerfile +50 -0
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/bin/lims-mcp.mjs +101 -0
- package/bin/lims.mjs +1639 -0
- package/docs/MARKETPLACE-GUIDELINES.md +99 -0
- package/docs/clawdao-mcp-listing.md +308 -0
- package/docs/clawdao-mcp-setup.md +294 -0
- package/docs/ddn-hub-postType-issue.md +54 -0
- package/docs/deploy-http.md +192 -0
- package/docs/install-mcp.md +268 -0
- package/docs/limschain-migration-and-readme-backfill.md +212 -0
- package/docs/marketplace-readmes/clawdao-video-factory.md +49 -0
- package/docs/node-free-install.md +196 -0
- package/docs/release-notes/v1.0.30-short.md +63 -0
- package/docs/site-design-studio-api.md +162 -0
- package/lib/articles.mjs +397 -0
- package/lib/client.mjs +588 -0
- package/lib/courses.mjs +169 -0
- package/lib/dao.mjs +195 -0
- package/lib/env.mjs +32 -0
- package/lib/feedback.mjs +68 -0
- package/lib/http-server.mjs +257 -0
- package/lib/marketplace-readme-path.mjs +17 -0
- package/lib/marketplace.mjs +273 -0
- package/lib/materials.mjs +260 -0
- package/lib/mcp-server.mjs +334 -0
- package/lib/site.mjs +471 -0
- package/lib/versions.mjs +904 -0
- package/mcp-listing.http.json +25 -0
- package/mcp-listing.json +34 -0
- package/package.json +77 -0
- package/scripts/build-binary.mjs +104 -0
- package/scripts/build-site-dashboard.mjs +52 -0
- package/scripts/collect-site-articles.mjs +432 -0
- package/scripts/export-ddn-env.mjs +107 -0
- package/scripts/fetch-article-stats.mjs +212 -0
- package/scripts/pack-and-verify.mjs +111 -0
- package/scripts/publisher.mjs +255 -0
- package/scripts/sync-marketplace-readme.mjs +380 -0
- package/scripts/tool-set.mjs +48 -0
- package/scripts/verify-binary.mjs +115 -0
- package/scripts/verify-clawdao-bridge.mjs +41 -0
- package/scripts/verify-e2e.mjs +176 -0
- package/scripts/verify-http-mcp.mjs +94 -0
- package/scripts/verify-listing-sync.mjs +90 -0
- package/scripts/verify-marketplace-readme.mjs +266 -0
- package/scripts/verify-mcp-handshake.mjs +98 -0
- package/scripts/verify-news-publish.mjs +257 -0
- package/scripts/verify-npx-install.mjs +171 -0
- package/scripts/verify-site-dashboard.mjs +87 -0
- package/scripts/verify-site-layout.mjs +194 -0
- package/tests/client-auth.test.mjs +159 -0
- package/tests/dao-profile.test.mjs +126 -0
- package/tests/marketplace-readme-path.test.mjs +16 -0
- package/tests/mcp-server.test.mjs +187 -0
- package/tests/member-submission.test.mjs +150 -0
- package/tests/official-listing.test.mjs +52 -0
- package/tests/smoke.mjs +262 -0
- package/tests/sync-marketplace-readme.test.mjs +50 -0
- package/tests/tool-set.test.mjs +54 -0
- package/tests/versions-sync-dryrun.test.mjs +315 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 亿检链素材库(materials)模块
|
|
3
|
+
*
|
|
4
|
+
* 封装亿检链 DDN Hub 的素材上传接口(`POST /api/v1/material/files/upload`),
|
|
5
|
+
* 供 CLI `lims upload` 子命令、`scripts/publisher.mjs` 通用发布器以及未来
|
|
6
|
+
* 课程 / 应用市场 / 反馈 等模块复用。
|
|
7
|
+
*
|
|
8
|
+
* 接口契约(probe_upload9.mjs / scripts/publisher.mjs:134 已验证):
|
|
9
|
+
* - 请求:multipart/form-data
|
|
10
|
+
* daoId: <uuid> (当前 DAO,必填)
|
|
11
|
+
* type: image|video|file (默认 image)
|
|
12
|
+
* file: <binary> (必填,字段名固定为 file)
|
|
13
|
+
* - 响应:{ status, msg, data: { url, filename, size, ... } }
|
|
14
|
+
* status === 0 表示成功;data.url 是可公开访问的 CDN URL
|
|
15
|
+
*
|
|
16
|
+
* 设计原则:
|
|
17
|
+
* - 与其他 Manager 保持一致(构造接收 LimsClient,方法返回 {ok,...})
|
|
18
|
+
* - 上传是 I/O 密集操作,构造函数不读取文件
|
|
19
|
+
* - 不重复 fetch 同一文件:uploadBatch() 用绝对路径做去重
|
|
20
|
+
* - 失败时返回标准错误结构(不抛异常),便于 CLI 统一展示
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { existsSync, statSync, readFileSync } from 'fs';
|
|
24
|
+
import { resolve, basename, extname, isAbsolute } from 'path';
|
|
25
|
+
import { LimsClient } from './client.mjs';
|
|
26
|
+
|
|
27
|
+
export const MATERIAL_TYPES = ['image', 'video', 'file'];
|
|
28
|
+
export const MATERIAL_TYPE_LABELS = {
|
|
29
|
+
image: '图片',
|
|
30
|
+
video: '视频',
|
|
31
|
+
file: '文件',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** 兜底 MIME 推断(Node 18+ 内置 MIME 映射不完整时使用) */
|
|
35
|
+
const inferMime = (filePath) => {
|
|
36
|
+
const ext = extname(filePath).slice(1).toLowerCase();
|
|
37
|
+
if (!ext) return 'application/octet-stream';
|
|
38
|
+
const map = {
|
|
39
|
+
png: 'image/png',
|
|
40
|
+
jpg: 'image/jpeg',
|
|
41
|
+
jpeg: 'image/jpeg',
|
|
42
|
+
gif: 'image/gif',
|
|
43
|
+
webp: 'image/webp',
|
|
44
|
+
svg: 'image/svg+xml',
|
|
45
|
+
bmp: 'image/bmp',
|
|
46
|
+
avif: 'image/avif',
|
|
47
|
+
mp4: 'video/mp4',
|
|
48
|
+
mov: 'video/quicktime',
|
|
49
|
+
webm: 'video/webm',
|
|
50
|
+
pdf: 'application/pdf',
|
|
51
|
+
txt: 'text/plain',
|
|
52
|
+
md: 'text/markdown',
|
|
53
|
+
json: 'application/json',
|
|
54
|
+
};
|
|
55
|
+
return map[ext] || `application/${ext}`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export class MaterialManager {
|
|
59
|
+
#client;
|
|
60
|
+
|
|
61
|
+
constructor(clientOrConfig) {
|
|
62
|
+
this.#client = clientOrConfig instanceof LimsClient
|
|
63
|
+
? clientOrConfig
|
|
64
|
+
: new LimsClient(clientOrConfig);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 健康检查:当前 DAO 是否可调用上传接口(只验证配置) */
|
|
68
|
+
health() {
|
|
69
|
+
const cfg = this.#client.getRuntimeSnapshot();
|
|
70
|
+
const missing = [];
|
|
71
|
+
if (!cfg.baseUrlValid) missing.push('baseUrl 无效');
|
|
72
|
+
if (!cfg.hasAuthToken) missing.push('缺少 DDN_HUB_AUTH_TOKEN');
|
|
73
|
+
if (!cfg.hasDaoId) missing.push('缺少 DDN_HUB_DAO_ID');
|
|
74
|
+
return {
|
|
75
|
+
ok: missing.length === 0,
|
|
76
|
+
message: missing.length === 0 ? 'ready' : missing.join(';'),
|
|
77
|
+
config: cfg,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 上传单个本地文件到亿检链素材库
|
|
83
|
+
*
|
|
84
|
+
* @param {string} filePath 本地文件绝对路径或相对 cwd 路径
|
|
85
|
+
* @param {object} [opts]
|
|
86
|
+
* @param {string} [opts.type='image'] image / video / file
|
|
87
|
+
* @param {string} [opts.daoId] 覆盖默认 DAO(高级用法)
|
|
88
|
+
* @param {string} [opts.filename] 重命名上传后的文件名(默认 basename(filePath))
|
|
89
|
+
* @returns {Promise<{ok:boolean, url?:string, data?:object, message?:string, statusCode?:number}>}
|
|
90
|
+
*/
|
|
91
|
+
async upload(filePath, opts = {}) {
|
|
92
|
+
const absPath = isAbsolute(filePath) ? filePath : resolve(process.cwd(), filePath);
|
|
93
|
+
|
|
94
|
+
if (!existsSync(absPath)) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
message: `文件不存在: ${absPath}`,
|
|
98
|
+
error: { kind: 'not_found', message: `文件不存在: ${absPath}` },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const size = statSync(absPath).size;
|
|
102
|
+
if (size === 0) {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
message: `文件为空: ${absPath}`,
|
|
106
|
+
error: { kind: 'invalid_input', message: `文件为空: ${absPath}` },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const type = opts.type || 'image';
|
|
111
|
+
if (!MATERIAL_TYPES.includes(type)) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
message: `不支持的素材类型: ${type}(允许:${MATERIAL_TYPES.join(', ')})`,
|
|
115
|
+
error: { kind: 'invalid_input', message: 'type 取值非法' },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const daoId = opts.daoId || process.env.DDN_HUB_DAO_ID;
|
|
120
|
+
if (!daoId) {
|
|
121
|
+
return {
|
|
122
|
+
ok: false,
|
|
123
|
+
message: '缺少 DAO ID(设置 DDN_HUB_DAO_ID 或传 --dao-id)',
|
|
124
|
+
error: { kind: 'config_error', message: '缺少 DAO ID' },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const cfg = this.#client.getConfig();
|
|
129
|
+
if (!cfg.authToken) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
message: '缺少 DDN_HUB_AUTH_TOKEN',
|
|
133
|
+
error: { kind: 'config_error', message: '缺少 auth token' },
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const filename = opts.filename || basename(absPath);
|
|
138
|
+
|
|
139
|
+
// 用 Blob 包装(与 probe_upload9.mjs / publisher.mjs 已验证的实现一致)
|
|
140
|
+
const fileBuf = readFileSync(absPath);
|
|
141
|
+
const blob = new Blob([fileBuf], { type: inferMime(absPath) });
|
|
142
|
+
const fd = new FormData();
|
|
143
|
+
fd.append('daoId', daoId);
|
|
144
|
+
fd.append('type', type);
|
|
145
|
+
fd.append('file', blob, filename);
|
|
146
|
+
|
|
147
|
+
const url = new URL('/api/v1/material/files/upload', cfg.baseUrl).toString();
|
|
148
|
+
let res;
|
|
149
|
+
try {
|
|
150
|
+
res = await fetch(url, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: `Bearer ${cfg.authToken}`,
|
|
154
|
+
'X-Dao-Id': daoId,
|
|
155
|
+
'x-dao-id': daoId,
|
|
156
|
+
'User-Agent': '@lims/lims-agent/0.1.0',
|
|
157
|
+
},
|
|
158
|
+
body: fd,
|
|
159
|
+
});
|
|
160
|
+
} catch (err) {
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
message: `网络错误: ${err instanceof Error ? err.message : String(err)}`,
|
|
164
|
+
error: { kind: 'network_error', message: '网络请求失败' },
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 解析响应(可能 JSON 也可能 text)
|
|
169
|
+
const text = await res.text();
|
|
170
|
+
let body = null;
|
|
171
|
+
try { body = text ? JSON.parse(text) : null; } catch { /* 非 JSON */ }
|
|
172
|
+
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
return {
|
|
175
|
+
ok: false,
|
|
176
|
+
statusCode: res.status,
|
|
177
|
+
message: body?.msg || body?.message || `上传失败,HTTP ${res.status}`,
|
|
178
|
+
data: body?.data || null,
|
|
179
|
+
error: { kind: 'http_error', message: body?.msg || `HTTP ${res.status}`, statusCode: res.status },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 业务错误:status === 1 表示后端业务错误(与 LimsClient 约定一致)
|
|
184
|
+
if (body && typeof body === 'object' && body.status === 1) {
|
|
185
|
+
return {
|
|
186
|
+
ok: false,
|
|
187
|
+
statusCode: res.status,
|
|
188
|
+
message: body.msg || body.message || '上传失败',
|
|
189
|
+
data: body.data || null,
|
|
190
|
+
error: { kind: 'business_error', message: body.msg || '业务错误', statusCode: res.status },
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const dataUrl = body?.data?.url || body?.data?.fileUrl || body?.data?.path;
|
|
195
|
+
if (!dataUrl) {
|
|
196
|
+
return {
|
|
197
|
+
ok: false,
|
|
198
|
+
statusCode: res.status,
|
|
199
|
+
message: '上传成功但响应中未返回 URL',
|
|
200
|
+
data: body?.data,
|
|
201
|
+
error: { kind: 'parse_error', message: '响应缺少 url 字段' },
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
ok: true,
|
|
207
|
+
url: dataUrl,
|
|
208
|
+
filename,
|
|
209
|
+
size,
|
|
210
|
+
type,
|
|
211
|
+
data: body.data,
|
|
212
|
+
message: '上传成功',
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 批量上传本地文件列表,自动去重(同一绝对路径只上传一次)
|
|
218
|
+
*
|
|
219
|
+
* @param {string[]} filePaths 本地路径数组(绝对路径或相对 cwd)
|
|
220
|
+
* @param {object} [opts] 同 upload() 的 opts
|
|
221
|
+
* @returns {Promise<{
|
|
222
|
+
* ok: boolean,
|
|
223
|
+
* map: Map<string, string>, // 绝对路径 → CDN URL(成功)
|
|
224
|
+
* failures: Array<{path:string, message:string}>,
|
|
225
|
+
* message: string,
|
|
226
|
+
* }>}
|
|
227
|
+
*/
|
|
228
|
+
async uploadBatch(filePaths, opts = {}) {
|
|
229
|
+
const map = new Map();
|
|
230
|
+
const failures = [];
|
|
231
|
+
|
|
232
|
+
// 去重但保留顺序
|
|
233
|
+
const seen = new Set();
|
|
234
|
+
const unique = [];
|
|
235
|
+
for (const p of filePaths) {
|
|
236
|
+
const abs = isAbsolute(p) ? p : resolve(process.cwd(), p);
|
|
237
|
+
if (seen.has(abs)) continue;
|
|
238
|
+
seen.add(abs);
|
|
239
|
+
unique.push(abs);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
for (const abs of unique) {
|
|
243
|
+
const r = await this.upload(abs, opts);
|
|
244
|
+
if (r.ok && r.url) {
|
|
245
|
+
map.set(abs, r.url);
|
|
246
|
+
} else {
|
|
247
|
+
failures.push({ path: abs, message: r.message || '未知错误' });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
ok: failures.length === 0,
|
|
253
|
+
map,
|
|
254
|
+
failures,
|
|
255
|
+
message: failures.length === 0
|
|
256
|
+
? `全部 ${map.size} 个文件上传成功`
|
|
257
|
+
: `${map.size} 成功 / ${failures.length} 失败`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 亿检链 MCP server(stdio)
|
|
3
|
+
*
|
|
4
|
+
* 设计原则:
|
|
5
|
+
* - lib/ 是唯一业务事实源,这里只做「工具注册 + 入参 schema + 结果结构化」
|
|
6
|
+
* - 不复制任何 API 调用逻辑;Manager 的返回对象原样透传为 structuredContent
|
|
7
|
+
* - 写操作默认不执行:必须显式 confirm=true,防止模型误触发发布/上架
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
|
|
11
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
|
|
14
|
+
import { LimsClient } from './client.mjs';
|
|
15
|
+
import { ArticleManager, POST_TYPES } from './articles.mjs';
|
|
16
|
+
import { MarketplaceManager, ASSET_TYPES } from './marketplace.mjs';
|
|
17
|
+
import { SiteManager } from './site.mjs';
|
|
18
|
+
import { DaoManager } from './dao.mjs';
|
|
19
|
+
import { VersionManager } from './versions.mjs';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 包版本号 —— 从 package.json 读,避免与 npm 元数据 / CLI 输出漂移。
|
|
23
|
+
* 打包后 package.json 一定在包根(npm 总是打包它),所以读得到;
|
|
24
|
+
* 万一读不到(极端裁剪场景)退回硬编码兜底,不让 MCP 起不来。
|
|
25
|
+
*
|
|
26
|
+
* ★ 编译成单文件二进制后没有 package.json 可读 ⇒ 构建脚本用
|
|
27
|
+
* `bun build --define:__LIMS_VERSION__='"x.y.z"'` 把版本号注进来。
|
|
28
|
+
*/
|
|
29
|
+
const BUILD_VERSION = typeof __LIMS_VERSION__ === 'string' ? __LIMS_VERSION__ : '';
|
|
30
|
+
|
|
31
|
+
function readPackageVersion() {
|
|
32
|
+
if (BUILD_VERSION) return BUILD_VERSION;
|
|
33
|
+
try {
|
|
34
|
+
const raw = readFileSync(new URL('../package.json', import.meta.url), 'utf-8');
|
|
35
|
+
const version = JSON.parse(raw)?.version;
|
|
36
|
+
if (typeof version === 'string' && version) return version;
|
|
37
|
+
} catch { /* 读不到就用兜底 */ }
|
|
38
|
+
return '0.5.0';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const SERVER_INFO = { name: 'lims-mcp', version: readPackageVersion() };
|
|
42
|
+
|
|
43
|
+
export const TOOL_NAMES = Object.freeze([
|
|
44
|
+
'lims_health',
|
|
45
|
+
'lims_article_list',
|
|
46
|
+
'lims_article_get',
|
|
47
|
+
// 🔧 2026-11-27(plan fix-08):列分类 —— 智能体要知道目标组织下有哪些合法 categoryId
|
|
48
|
+
'lims_category_list',
|
|
49
|
+
'lims_article_upload',
|
|
50
|
+
'lims_article_publish',
|
|
51
|
+
'lims_marketplace_list',
|
|
52
|
+
'lims_marketplace_stats',
|
|
53
|
+
'lims_marketplace_get',
|
|
54
|
+
'lims_marketplace_publish',
|
|
55
|
+
'lims_site_pages',
|
|
56
|
+
'lims_site_get',
|
|
57
|
+
'lims_site_public',
|
|
58
|
+
'lims_dao_profile',
|
|
59
|
+
'lims_version_list',
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const clean = (value) => Object.fromEntries(
|
|
63
|
+
Object.entries(value).filter(([, v]) => v !== undefined),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const toolResult = (tool, payload, { isError = false } = {}) => {
|
|
67
|
+
const structuredContent = clean({ tool, ...payload });
|
|
68
|
+
return {
|
|
69
|
+
content: [{ type: 'text', text: JSON.stringify(structuredContent, null, 2) }],
|
|
70
|
+
structuredContent,
|
|
71
|
+
...(isError ? { isError: true } : {}),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const okResult = (tool, result, extra = {}) => toolResult(tool, {
|
|
76
|
+
ok: true,
|
|
77
|
+
...clean(result || {}),
|
|
78
|
+
...extra,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const failResult = (tool, result) => toolResult(tool, {
|
|
82
|
+
ok: false,
|
|
83
|
+
...clean(result || {}),
|
|
84
|
+
}, { isError: true });
|
|
85
|
+
|
|
86
|
+
const exceptionResult = (tool, error) => toolResult(tool, {
|
|
87
|
+
ok: false,
|
|
88
|
+
error: { kind: 'tool_exception', message: error?.message || String(error) },
|
|
89
|
+
}, { isError: true });
|
|
90
|
+
|
|
91
|
+
/** 写操作的确认闸:未显式 confirm=true 时只回显预览,不碰 API */
|
|
92
|
+
const confirmationResult = (tool, args) => toolResult(tool, {
|
|
93
|
+
ok: true,
|
|
94
|
+
requiresConfirmation: true,
|
|
95
|
+
message: '这是写操作预览。确认无误后,用相同参数重新调用并设置 confirm=true 才会真正执行。',
|
|
96
|
+
preview: clean(args),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const withGuard = (tool, handler) => async (args) => {
|
|
100
|
+
try {
|
|
101
|
+
return await handler(args);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return exceptionResult(tool, error);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const CONFIRM_SCHEMA = z.boolean().default(false).describe(
|
|
108
|
+
'必须显式设为 true 才会执行写操作;默认 false 只返回预览。',
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export const createLimsMcpServer = ({ client, managers = {} } = {}) => {
|
|
112
|
+
const limsClient = client instanceof LimsClient ? client : new LimsClient(client || {});
|
|
113
|
+
const server = new McpServer(SERVER_INFO);
|
|
114
|
+
|
|
115
|
+
const articles = managers.articles || new ArticleManager(limsClient);
|
|
116
|
+
const marketplace = managers.marketplace || new MarketplaceManager(limsClient);
|
|
117
|
+
const site = managers.site || new SiteManager(limsClient);
|
|
118
|
+
const dao = managers.dao || new DaoManager(limsClient);
|
|
119
|
+
const versions = managers.versions || new VersionManager(limsClient);
|
|
120
|
+
|
|
121
|
+
const call = (tool, fn) => withGuard(tool, async (args) => {
|
|
122
|
+
const result = await fn(args);
|
|
123
|
+
return result?.ok === false ? failResult(tool, result) : okResult(tool, result);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// ===== 运行时 =====
|
|
127
|
+
server.registerTool('lims_health', {
|
|
128
|
+
title: '亿检链运行状态',
|
|
129
|
+
description: '查看当前 MCP 运行时配置(不含 token 明文),可选探测 API 连通性。',
|
|
130
|
+
inputSchema: {
|
|
131
|
+
probe: z.boolean().default(false).describe('是否实际请求 API 健康检查端点。'),
|
|
132
|
+
},
|
|
133
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
134
|
+
}, call('lims_health', async ({ probe }) => {
|
|
135
|
+
const runtime = limsClient.getRuntimeSnapshot();
|
|
136
|
+
if (!probe) return { runtime, probe: null, message: '仅返回运行时快照,未发起网络请求。' };
|
|
137
|
+
const result = await limsClient.healthCheck();
|
|
138
|
+
if (!result.ok) return { ok: false, runtime, probe: result };
|
|
139
|
+
return { runtime, probe: { ok: true, message: result.message, data: result.data } };
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
// ===== 文章 =====
|
|
143
|
+
server.registerTool('lims_article_list', {
|
|
144
|
+
title: '列出文章',
|
|
145
|
+
description: '按类型/状态/关键词列出亿检链文章,返回 items 与分页信息。',
|
|
146
|
+
inputSchema: {
|
|
147
|
+
page: z.number().int().positive().default(1),
|
|
148
|
+
limit: z.number().int().min(1).max(100).default(10),
|
|
149
|
+
postType: z.enum(POST_TYPES).optional().describe('news / help / article'),
|
|
150
|
+
status: z.string().min(1).optional(),
|
|
151
|
+
search: z.string().min(1).optional(),
|
|
152
|
+
},
|
|
153
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
154
|
+
}, call('lims_article_list', (args) => articles.list(args)));
|
|
155
|
+
|
|
156
|
+
server.registerTool('lims_article_get', {
|
|
157
|
+
title: '读取文章详情',
|
|
158
|
+
description: '按文章 id 读取详情,包含正文与扩展属性。',
|
|
159
|
+
inputSchema: { postId: z.number().int().positive().describe('文章数字 id') },
|
|
160
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
161
|
+
}, call('lims_article_get', ({ postId }) => articles.get(postId)));
|
|
162
|
+
|
|
163
|
+
// 🔧 2026-11-27(plan fix-08):列分类。
|
|
164
|
+
// 没有它,智能体不知道「当前组织下有哪些合法分类 id」⇒ 只能猜 categoryId
|
|
165
|
+
// ⇒ 文章要么发错栏目、要么发不进去。
|
|
166
|
+
server.registerTool('lims_category_list', {
|
|
167
|
+
title: '列出当前组织的分类',
|
|
168
|
+
description:
|
|
169
|
+
'列出当前亿检链组织可用的内容分类(categoryId / slug / 名称 / 层级)。' +
|
|
170
|
+
'发布文章前应先调用本工具确认目标分类 id —— 不要再猜 categoryId。',
|
|
171
|
+
inputSchema: {
|
|
172
|
+
daoId: z.string().min(1).optional().describe('目标组织 id(不传 = 当前组织)'),
|
|
173
|
+
},
|
|
174
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
175
|
+
}, call('lims_category_list', async ({ daoId } = {}) => {
|
|
176
|
+
const runtime = limsClient.getRuntimeSnapshot();
|
|
177
|
+
const result = await limsClient.listCategories(daoId);
|
|
178
|
+
if (!result.ok) {
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
message: `读取分类失败: ${result.message}`,
|
|
182
|
+
runtime,
|
|
183
|
+
daoId: daoId || runtime.daoId || null,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
ok: true,
|
|
188
|
+
message: '当前组织的分类清单(发布文章时用 categoryId 指定归属分类)',
|
|
189
|
+
runtime,
|
|
190
|
+
daoId: daoId || runtime.daoId || null,
|
|
191
|
+
categories: result.data,
|
|
192
|
+
};
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
server.registerTool('lims_article_upload', {
|
|
196
|
+
title: '创建并可选发布文章',
|
|
197
|
+
description:
|
|
198
|
+
'创建文章草稿;publish=true 时创建后立即走租户侧→平台侧兜底发布。写操作,默认只预览。' +
|
|
199
|
+
'⚠️ 内容需要经审核才会对外可见;返回 pendingReview=true 表示「已提交审核、尚未公开」。',
|
|
200
|
+
inputSchema: {
|
|
201
|
+
title: z.string().min(1).max(200),
|
|
202
|
+
contentMarkdown: z.string().min(20).describe('Markdown 正文(至少 20 字符)。'),
|
|
203
|
+
description: z.string().optional(),
|
|
204
|
+
postType: z.enum(POST_TYPES).default(POST_TYPES[0]),
|
|
205
|
+
tags: z.array(z.string().min(1)).optional(),
|
|
206
|
+
coverImage: z.string().url().optional(),
|
|
207
|
+
// 🔧 2026-11-27(plan fix-08):显式目标组织 + 目标分类。
|
|
208
|
+
// 分类 id 请先用 lims_category_list 查,不要猜。
|
|
209
|
+
daoId: z.string().min(1).optional().describe('目标组织 id(不传 = 当前组织)。'),
|
|
210
|
+
categoryId: z.number().int().positive().optional().describe('归属分类 id(用 lims_category_list 查)。'),
|
|
211
|
+
publish: z.boolean().default(false).describe('是否在创建后立即发布(仍需审核通过才公开)。'),
|
|
212
|
+
confirm: CONFIRM_SCHEMA,
|
|
213
|
+
},
|
|
214
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
215
|
+
}, withGuard('lims_article_upload', async (args) => {
|
|
216
|
+
if (args.confirm !== true) return confirmationResult('lims_article_upload', args);
|
|
217
|
+
const { confirm: _confirm, ...payload } = args;
|
|
218
|
+
return okResult('lims_article_upload', await articles.upload(payload));
|
|
219
|
+
}));
|
|
220
|
+
|
|
221
|
+
server.registerTool('lims_article_publish', {
|
|
222
|
+
title: '发布文章',
|
|
223
|
+
description:
|
|
224
|
+
'发布已有文章;租户侧缺权限时自动兜底平台侧。写操作,默认只预览。' +
|
|
225
|
+
'⚠️ 不会自动替你「审核通过」——未过审的内容会被服务端挡下并回报「已提交审核,尚未公开」。',
|
|
226
|
+
inputSchema: {
|
|
227
|
+
postId: z.number().int().positive(),
|
|
228
|
+
daoId: z.string().min(1).optional().describe('目标组织 id(不传 = 当前组织)。'),
|
|
229
|
+
platform: z.boolean().default(false).describe('是否强制走平台侧审核发布。'),
|
|
230
|
+
confirm: CONFIRM_SCHEMA,
|
|
231
|
+
},
|
|
232
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
233
|
+
}, withGuard('lims_article_publish', async (args) => {
|
|
234
|
+
if (args.confirm !== true) return confirmationResult('lims_article_publish', args);
|
|
235
|
+
const { confirm: _confirm, ...payload } = args;
|
|
236
|
+
const result = await articles.publish(payload.postId, {
|
|
237
|
+
platform: payload.platform,
|
|
238
|
+
daoId: payload.daoId,
|
|
239
|
+
});
|
|
240
|
+
// 🔧 2026-11-27(plan fix-08):发布**失败**(含「待审核,未公开」)必须**如实**标成失败。
|
|
241
|
+
// 原来这里无条件 okResult(...) ⇒ 「没发出去」会被报成「成功」,
|
|
242
|
+
// 调用方(智能体/用户)据此以为文章已经公开 —— 事故链上的一环。
|
|
243
|
+
return result?.ok === false ? failResult('lims_article_publish', result) : okResult('lims_article_publish', result);
|
|
244
|
+
}));
|
|
245
|
+
|
|
246
|
+
// ===== 应用市场 =====
|
|
247
|
+
server.registerTool('lims_marketplace_list', {
|
|
248
|
+
title: '浏览应用市场',
|
|
249
|
+
description: '公开浏览市场资产,可按类型/关键词/精选筛选。',
|
|
250
|
+
inputSchema: {
|
|
251
|
+
type: z.enum(ASSET_TYPES).optional(),
|
|
252
|
+
keyword: z.string().min(1).optional(),
|
|
253
|
+
isFeatured: z.boolean().optional(),
|
|
254
|
+
page: z.number().int().positive().default(1),
|
|
255
|
+
pageSize: z.number().int().min(1).max(100).default(20),
|
|
256
|
+
},
|
|
257
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
258
|
+
}, call('lims_marketplace_list', (args) => marketplace.list(args)));
|
|
259
|
+
|
|
260
|
+
server.registerTool('lims_marketplace_stats', {
|
|
261
|
+
title: '应用市场统计',
|
|
262
|
+
description: '按资产类型与状态聚合统计(管理端,需鉴权)。',
|
|
263
|
+
inputSchema: {},
|
|
264
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
265
|
+
}, call('lims_marketplace_stats', () => marketplace.stats()));
|
|
266
|
+
|
|
267
|
+
server.registerTool('lims_marketplace_get', {
|
|
268
|
+
title: '读取资产详情',
|
|
269
|
+
description: '按 UUID 读取应用市场资产详情。',
|
|
270
|
+
inputSchema: { uuid: z.string().min(1) },
|
|
271
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
272
|
+
}, call('lims_marketplace_get', ({ uuid }) => marketplace.get(uuid)));
|
|
273
|
+
|
|
274
|
+
server.registerTool('lims_marketplace_publish', {
|
|
275
|
+
title: '上架市场资产',
|
|
276
|
+
description: '把资产状态改为 active(上架)。写操作,默认只预览。',
|
|
277
|
+
inputSchema: {
|
|
278
|
+
uuid: z.string().min(1),
|
|
279
|
+
confirm: CONFIRM_SCHEMA,
|
|
280
|
+
},
|
|
281
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
282
|
+
}, withGuard('lims_marketplace_publish', async (args) => {
|
|
283
|
+
if (args.confirm !== true) return confirmationResult('lims_marketplace_publish', args);
|
|
284
|
+
return okResult('lims_marketplace_publish', await marketplace.updateStatus(args.uuid, 'active'));
|
|
285
|
+
}));
|
|
286
|
+
|
|
287
|
+
// ===== 站点设计 =====
|
|
288
|
+
server.registerTool('lims_site_pages', {
|
|
289
|
+
title: '列出站点页面',
|
|
290
|
+
description: '列出当前 DAO 站点的所有页面与发布状态。',
|
|
291
|
+
inputSchema: {},
|
|
292
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
293
|
+
}, call('lims_site_pages', () => site.listPages()));
|
|
294
|
+
|
|
295
|
+
server.registerTool('lims_site_get', {
|
|
296
|
+
title: '读取页面区块',
|
|
297
|
+
description: '读取管理端页面区块(优先草稿版本),用于编辑前查看现状。',
|
|
298
|
+
inputSchema: { slug: z.string().min(1).describe('页面 slug,如 home / concept') },
|
|
299
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
300
|
+
}, call('lims_site_get', ({ slug }) => site.getPage(slug)));
|
|
301
|
+
|
|
302
|
+
server.registerTool('lims_site_public', {
|
|
303
|
+
title: '回读公开端页面',
|
|
304
|
+
description: '读取公开端已发布页面内容,用于发布后校验。无需鉴权。',
|
|
305
|
+
inputSchema: {
|
|
306
|
+
slug: z.string().min(1),
|
|
307
|
+
domain: z.string().min(1).optional(),
|
|
308
|
+
},
|
|
309
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
310
|
+
}, call('lims_site_public', ({ slug, domain }) => site.publicGetPage(slug, domain)));
|
|
311
|
+
|
|
312
|
+
// ===== DAO 档案 =====
|
|
313
|
+
server.registerTool('lims_dao_profile', {
|
|
314
|
+
title: '读取 DAO 档案',
|
|
315
|
+
description: '读取当前 DAO 的档案字段(简介/详细介绍等),自动脱敏 appSecret/appKey。',
|
|
316
|
+
inputSchema: {},
|
|
317
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
318
|
+
}, call('lims_dao_profile', () => dao.getProfile()));
|
|
319
|
+
|
|
320
|
+
// ===== 产品版本 =====
|
|
321
|
+
server.registerTool('lims_version_list', {
|
|
322
|
+
title: '列出产品版本',
|
|
323
|
+
description: '列出产品版本,可按 productKey 与状态筛选。',
|
|
324
|
+
inputSchema: {
|
|
325
|
+
productKey: z.string().min(1).optional().describe('如 clawdao'),
|
|
326
|
+
status: z.string().min(1).optional(),
|
|
327
|
+
page: z.number().int().positive().default(1),
|
|
328
|
+
pageSize: z.number().int().min(1).max(100).default(20),
|
|
329
|
+
},
|
|
330
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
331
|
+
}, call('lims_version_list', (args) => versions.list(args)));
|
|
332
|
+
|
|
333
|
+
return { server, client: limsClient, runtime: limsClient.getRuntimeSnapshot() };
|
|
334
|
+
};
|