@nocobase/ai 2.1.0-alpha.2 → 2.1.0-alpha.20
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/ai-employee-manager/index.d.ts +29 -0
- package/lib/ai-employee-manager/index.js +167 -0
- package/lib/ai-employee-manager/types.d.ts +56 -0
- package/lib/ai-employee-manager/types.js +24 -0
- package/lib/ai-manager.d.ts +8 -0
- package/lib/ai-manager.js +12 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +8 -0
- package/lib/loader/employee.d.ts +36 -0
- package/lib/loader/employee.js +207 -0
- package/lib/loader/index.d.ts +3 -0
- package/lib/loader/index.js +7 -1
- package/lib/loader/mcp.d.ts +34 -0
- package/lib/loader/mcp.js +108 -0
- package/lib/loader/skills.d.ts +42 -0
- package/lib/loader/skills.js +138 -0
- package/lib/mcp-manager/index.d.ts +43 -0
- package/lib/mcp-manager/index.js +341 -0
- package/lib/mcp-manager/types.d.ts +61 -0
- package/lib/mcp-manager/types.js +24 -0
- package/lib/mcp-tools-manager.d.ts +43 -0
- package/lib/mcp-tools-manager.js +77 -0
- package/lib/skills-manager/index.d.ts +29 -0
- package/lib/skills-manager/index.js +169 -0
- package/lib/skills-manager/types.d.ts +33 -0
- package/lib/skills-manager/types.js +24 -0
- package/lib/tools-manager/index.js +3 -0
- package/lib/tools-manager/types.d.ts +7 -1
- package/package.json +25 -7
- package/src/__tests__/ai-employees.test.ts +108 -0
- package/src/__tests__/mcp.test.ts +105 -0
- package/src/__tests__/resource/ai/ai-employees/index-employee/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/index-employee/prompt.md +1 -0
- package/src/__tests__/resource/ai/ai-employees/named-file-employee.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills/skills/analysis/SKILLS.md +6 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills-merge/index.ts +17 -0
- package/src/__tests__/resource/ai/ai-employees/with-skills-merge/skills/discovered-skill/SKILLS.md +6 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools/tools/discoveredTool.ts +23 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools-merge/index.ts +16 -0
- package/src/__tests__/resource/ai/ai-employees/with-tools-merge/tools/discoveredTool.ts +23 -0
- package/src/__tests__/resource/ai/mcp/weather.ts +25 -0
- package/src/__tests__/resource/ai/skills/data-modeling/SKILLS.md +24 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/read.ts +23 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/search/description.md +1 -0
- package/src/__tests__/resource/ai/skills/data-modeling/tools/search/index.ts +23 -0
- package/src/__tests__/resource/ai/skills/document/tools/read.ts +1 -1
- package/src/__tests__/resource/ai/skills/document/tools/search/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/desc/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group1.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group2.ts +1 -1
- package/src/__tests__/resource/ai/tools/group/group3/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/hallow/index.ts +1 -1
- package/src/__tests__/resource/ai/tools/print.ts +1 -1
- package/src/__tests__/skills.test.ts +55 -0
- package/src/__tests__/tools.test.ts +5 -3
- package/src/ai-employee-manager/index.ts +148 -0
- package/src/ai-employee-manager/types.ts +63 -0
- package/src/ai-manager.ts +12 -0
- package/src/index.ts +4 -0
- package/src/loader/employee.ts +194 -0
- package/src/loader/index.ts +3 -0
- package/src/loader/mcp.ts +101 -0
- package/src/loader/skills.ts +129 -0
- package/src/mcp-manager/index.ts +364 -0
- package/src/mcp-manager/types.ts +68 -0
- package/src/mcp-tools-manager.ts +90 -0
- package/src/skills-manager/index.ts +148 -0
- package/src/skills-manager/types.ts +38 -0
- package/src/tools-manager/index.ts +3 -0
- package/src/tools-manager/types.ts +8 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var mcp_manager_exports = {};
|
|
30
|
+
__export(mcp_manager_exports, {
|
|
31
|
+
DefaultMCPManager: () => DefaultMCPManager,
|
|
32
|
+
defineMCP: () => defineMCP
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(mcp_manager_exports);
|
|
35
|
+
var import_database = require("@nocobase/database");
|
|
36
|
+
var import_utils = require("@nocobase/utils");
|
|
37
|
+
var import_mcp_adapters = require("@langchain/mcp-adapters");
|
|
38
|
+
__reExport(mcp_manager_exports, require("./types"), module.exports);
|
|
39
|
+
const _DefaultMCPManager = class _DefaultMCPManager {
|
|
40
|
+
constructor(app) {
|
|
41
|
+
this.app = app;
|
|
42
|
+
this.provideCollectionManager = () => app.mainDataSource;
|
|
43
|
+
}
|
|
44
|
+
mcpRegistry = new import_utils.Registry();
|
|
45
|
+
provideCollectionManager;
|
|
46
|
+
mode = "memory";
|
|
47
|
+
client = null;
|
|
48
|
+
toolsMap = {};
|
|
49
|
+
toolsPermissionMap = {};
|
|
50
|
+
async init() {
|
|
51
|
+
if (this.mode === "memory") {
|
|
52
|
+
await this.persistence();
|
|
53
|
+
this.mode = "database";
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await this.rebuildClient();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
this.app.log.error("fail to init mcp clients", e);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async registerMCP(registration) {
|
|
62
|
+
if (this.mode === "memory") {
|
|
63
|
+
for (const [name, options] of Object.entries(registration)) {
|
|
64
|
+
this.mcpRegistry.register(name, this.normalizeEntry(name, options));
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
for (const [name, options] of Object.entries(registration)) {
|
|
68
|
+
await this.persistenceEntry({
|
|
69
|
+
name,
|
|
70
|
+
...this.normalizeEntry(name, options)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async getMCP(name) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
return (_b = await ((_a = this.aiMcpClientsModel) == null ? void 0 : _a.findOne({ where: { name } }))) == null ? void 0 : _b.toJSON();
|
|
78
|
+
}
|
|
79
|
+
async listMCP(filter = {}) {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const where = {};
|
|
82
|
+
if (filter.name) {
|
|
83
|
+
where["name"] = {
|
|
84
|
+
[import_database.Op.substring]: filter.name
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (filter.enabled != null) {
|
|
88
|
+
where["enabled"] = filter.enabled;
|
|
89
|
+
}
|
|
90
|
+
if (filter.transport) {
|
|
91
|
+
where["transport"] = filter.transport;
|
|
92
|
+
}
|
|
93
|
+
return ((_b = await ((_a = this.aiMcpClientsModel) == null ? void 0 : _a.findAll({ where }))) == null ? void 0 : _b.map((item) => item.toJSON())) ?? [];
|
|
94
|
+
}
|
|
95
|
+
async rebuildClient() {
|
|
96
|
+
if (this.client) {
|
|
97
|
+
try {
|
|
98
|
+
await this.client.close();
|
|
99
|
+
} catch (e) {
|
|
100
|
+
}
|
|
101
|
+
this.client = null;
|
|
102
|
+
this.toolsMap = {};
|
|
103
|
+
}
|
|
104
|
+
const entries = await this.listMCP({ enabled: true });
|
|
105
|
+
if (entries.length === 0) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const connections = {};
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
connections[entry.name] = this.buildMCPConnection(entry);
|
|
111
|
+
}
|
|
112
|
+
this.client = new import_mcp_adapters.MultiServerMCPClient(connections);
|
|
113
|
+
const toolsMap = await this.client.initializeConnections();
|
|
114
|
+
for (const [serverName, tools] of Object.entries(toolsMap)) {
|
|
115
|
+
this.toolsMap[serverName] = tools;
|
|
116
|
+
for (const tool of tools) {
|
|
117
|
+
const toolName = `mcp-${serverName}-${tool.name}`;
|
|
118
|
+
if (!(toolName in this.toolsPermissionMap)) {
|
|
119
|
+
this.toolsPermissionMap[toolName] = tool.name.startsWith("get") ? "ALLOW" : "ASK";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getClient() {
|
|
125
|
+
return this.client;
|
|
126
|
+
}
|
|
127
|
+
getMCPToolsProvider() {
|
|
128
|
+
return async (register) => {
|
|
129
|
+
for (const [serverName, tools] of Object.entries(this.toolsMap)) {
|
|
130
|
+
for (const tool of tools) {
|
|
131
|
+
const toolName = `mcp-${serverName}-${tool.name}`;
|
|
132
|
+
const toolOptions = {
|
|
133
|
+
scope: "GENERAL",
|
|
134
|
+
from: "mcp",
|
|
135
|
+
defaultPermission: this.toolsPermissionMap[toolName],
|
|
136
|
+
introduction: {
|
|
137
|
+
title: tool.name,
|
|
138
|
+
about: tool.description
|
|
139
|
+
},
|
|
140
|
+
definition: {
|
|
141
|
+
name: toolName,
|
|
142
|
+
description: tool.description || `MCP tool: ${tool.name} from ${serverName}`,
|
|
143
|
+
schema: tool.schema
|
|
144
|
+
},
|
|
145
|
+
invoke: /* @__PURE__ */ __name(async (_ctx, args) => {
|
|
146
|
+
try {
|
|
147
|
+
const result = await tool.invoke(args);
|
|
148
|
+
return result;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return {
|
|
151
|
+
status: "error",
|
|
152
|
+
content: (error == null ? void 0 : error.message) || "Tool invocation failed"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}, "invoke")
|
|
156
|
+
};
|
|
157
|
+
register.registerTools(toolOptions);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async listMCPTools() {
|
|
163
|
+
return Object.fromEntries(
|
|
164
|
+
Object.entries(this.toolsMap).map(([serverName, tools]) => [
|
|
165
|
+
serverName,
|
|
166
|
+
tools.map((tool) => {
|
|
167
|
+
const toolName = `mcp-${serverName}-${tool.name}`;
|
|
168
|
+
return {
|
|
169
|
+
name: toolName,
|
|
170
|
+
title: tool.name,
|
|
171
|
+
description: tool.description,
|
|
172
|
+
serverName,
|
|
173
|
+
permission: this.toolsPermissionMap[toolName] ?? "ASK"
|
|
174
|
+
};
|
|
175
|
+
})
|
|
176
|
+
])
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
async updateMCPToolPermission(toolName, permission) {
|
|
180
|
+
this.toolsPermissionMap[toolName] = permission;
|
|
181
|
+
}
|
|
182
|
+
async testConnection(options) {
|
|
183
|
+
const { transport } = options;
|
|
184
|
+
if (!transport) {
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
error: "Transport type is required"
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (transport === "stdio" && !options.command) {
|
|
191
|
+
return {
|
|
192
|
+
success: false,
|
|
193
|
+
error: "Command is required for stdio transport"
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if ((transport === "http" || transport === "sse") && !options.url) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
error: "URL is required for HTTP/SSE transport"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
let client = null;
|
|
203
|
+
try {
|
|
204
|
+
const connection = this.buildMCPConnection(options);
|
|
205
|
+
const serverName = "test-server";
|
|
206
|
+
client = new import_mcp_adapters.MultiServerMCPClient({
|
|
207
|
+
[serverName]: connection
|
|
208
|
+
});
|
|
209
|
+
const toolsMap = await Promise.race([
|
|
210
|
+
client.initializeConnections(),
|
|
211
|
+
new Promise(
|
|
212
|
+
(_resolve, reject) => setTimeout(() => reject(new Error("Connection timeout (60s)")), 6e4)
|
|
213
|
+
)
|
|
214
|
+
]);
|
|
215
|
+
const tools = toolsMap[serverName] || [];
|
|
216
|
+
const toolNames = tools.map((tool) => tool.name);
|
|
217
|
+
return {
|
|
218
|
+
success: true,
|
|
219
|
+
message: "Connection successful",
|
|
220
|
+
toolsCount: tools.length,
|
|
221
|
+
tools: toolNames.slice(0, 20),
|
|
222
|
+
// Limit to 20 tools for display
|
|
223
|
+
toolsTruncated: toolNames.length > 20
|
|
224
|
+
};
|
|
225
|
+
} catch (error) {
|
|
226
|
+
const errorMessage = (error == null ? void 0 : error.message) || "Failed to connect to MCP server";
|
|
227
|
+
let hint;
|
|
228
|
+
if (errorMessage.includes("EACCES") || errorMessage.includes("permission denied")) {
|
|
229
|
+
hint = "Try running: npm cache clean --force";
|
|
230
|
+
} else if (errorMessage.includes("ENOENT") || errorMessage.includes("not found")) {
|
|
231
|
+
hint = "Make sure the command exists and is accessible";
|
|
232
|
+
} else if (errorMessage.includes("timeout")) {
|
|
233
|
+
hint = "The server took too long to respond. Check if the server is running correctly.";
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: errorMessage,
|
|
238
|
+
details: hint ? `Hint: ${hint}
|
|
239
|
+
|
|
240
|
+
${(error == null ? void 0 : error.stack) || ""}` : (error == null ? void 0 : error.stack) || ""
|
|
241
|
+
};
|
|
242
|
+
} finally {
|
|
243
|
+
if (client) {
|
|
244
|
+
try {
|
|
245
|
+
await client.close();
|
|
246
|
+
} catch (e) {
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
buildMCPConnection(options) {
|
|
252
|
+
const { transport, command, args, env, url, headers, restart } = options;
|
|
253
|
+
if (transport === "stdio") {
|
|
254
|
+
const connection2 = {
|
|
255
|
+
transport: "stdio",
|
|
256
|
+
command: command || "",
|
|
257
|
+
args: args || []
|
|
258
|
+
};
|
|
259
|
+
if (env && Object.keys(env).length > 0) {
|
|
260
|
+
connection2.env = env;
|
|
261
|
+
}
|
|
262
|
+
if (restart && typeof restart === "object" && !Array.isArray(restart)) {
|
|
263
|
+
connection2.restart = restart;
|
|
264
|
+
}
|
|
265
|
+
return connection2;
|
|
266
|
+
}
|
|
267
|
+
const connection = {
|
|
268
|
+
transport: transport === "sse" ? "sse" : "http",
|
|
269
|
+
url: url || ""
|
|
270
|
+
};
|
|
271
|
+
if (headers && Object.keys(headers).length > 0) {
|
|
272
|
+
connection.headers = headers;
|
|
273
|
+
}
|
|
274
|
+
return connection;
|
|
275
|
+
}
|
|
276
|
+
async persistence() {
|
|
277
|
+
for (const entry of this.mcpRegistry.getValues()) {
|
|
278
|
+
await this.persistenceEntry(entry);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async persistenceEntry(entry) {
|
|
282
|
+
await this.sequelize.transaction(async (transaction) => {
|
|
283
|
+
const existed = await this.aiMcpClientsModel.findOne({ where: { name: entry.name }, transaction });
|
|
284
|
+
if (existed) {
|
|
285
|
+
await existed.update(
|
|
286
|
+
{
|
|
287
|
+
transport: entry.transport,
|
|
288
|
+
command: entry.command,
|
|
289
|
+
args: entry.args,
|
|
290
|
+
env: entry.env,
|
|
291
|
+
url: entry.url,
|
|
292
|
+
headers: entry.headers,
|
|
293
|
+
restart: entry.restart
|
|
294
|
+
},
|
|
295
|
+
{ transaction }
|
|
296
|
+
);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
await this.aiMcpClientsModel.create(
|
|
300
|
+
{
|
|
301
|
+
...entry
|
|
302
|
+
},
|
|
303
|
+
{ transaction }
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
normalizeEntry(name, options) {
|
|
308
|
+
return {
|
|
309
|
+
name,
|
|
310
|
+
enabled: true,
|
|
311
|
+
...options,
|
|
312
|
+
args: options.args ?? [],
|
|
313
|
+
env: options.env ?? {}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
get aiMcpClientsCollection() {
|
|
317
|
+
return this.collectionManager.getCollection("aiMcpClients");
|
|
318
|
+
}
|
|
319
|
+
get aiMcpClientsModel() {
|
|
320
|
+
var _a;
|
|
321
|
+
return (_a = this.aiMcpClientsCollection) == null ? void 0 : _a.model;
|
|
322
|
+
}
|
|
323
|
+
get sequelize() {
|
|
324
|
+
return this.collectionManager.db.sequelize;
|
|
325
|
+
}
|
|
326
|
+
get collectionManager() {
|
|
327
|
+
return this.provideCollectionManager().collectionManager;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
__name(_DefaultMCPManager, "DefaultMCPManager");
|
|
331
|
+
let DefaultMCPManager = _DefaultMCPManager;
|
|
332
|
+
function defineMCP(options) {
|
|
333
|
+
return options;
|
|
334
|
+
}
|
|
335
|
+
__name(defineMCP, "defineMCP");
|
|
336
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
337
|
+
0 && (module.exports = {
|
|
338
|
+
DefaultMCPManager,
|
|
339
|
+
defineMCP,
|
|
340
|
+
...require("./types")
|
|
341
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type { MultiServerMCPClient } from '@langchain/mcp-adapters';
|
|
10
|
+
import type { DynamicToolsProvider, Permission } from '../tools-manager/types';
|
|
11
|
+
export interface MCPManager extends MCPRegistration {
|
|
12
|
+
init(): Promise<void>;
|
|
13
|
+
getMCP(name: string): Promise<MCPEntry>;
|
|
14
|
+
listMCP(filter: MCPFilter): Promise<MCPEntry[]>;
|
|
15
|
+
testConnection(options: MCPOptions): Promise<MCPTestResult>;
|
|
16
|
+
rebuildClient(): Promise<void>;
|
|
17
|
+
getClient(): MultiServerMCPClient | null;
|
|
18
|
+
getMCPToolsProvider(): DynamicToolsProvider;
|
|
19
|
+
listMCPTools(): Promise<Record<string, MCPToolEntry[]>>;
|
|
20
|
+
updateMCPToolPermission(toolName: string, permission: Permission): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface MCPRegistration {
|
|
23
|
+
registerMCP(registration: {
|
|
24
|
+
[key: string | symbol]: MCPOptions;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export type MCPOptions = {
|
|
28
|
+
transport: MCPTransport;
|
|
29
|
+
command?: string;
|
|
30
|
+
args?: string[];
|
|
31
|
+
env?: Record<string, string>;
|
|
32
|
+
url?: string;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
restart?: Record<string, any>;
|
|
35
|
+
};
|
|
36
|
+
export type MCPEntry = MCPOptions & {
|
|
37
|
+
name: string;
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type MCPFilter = {
|
|
41
|
+
name?: string;
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
transport?: MCPTransport;
|
|
44
|
+
};
|
|
45
|
+
export type MCPTransport = 'stdio' | 'sse' | 'http';
|
|
46
|
+
export type MCPTestResult = {
|
|
47
|
+
success: boolean;
|
|
48
|
+
message?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
details?: string;
|
|
51
|
+
toolsCount?: number;
|
|
52
|
+
tools?: string[];
|
|
53
|
+
toolsTruncated?: boolean;
|
|
54
|
+
};
|
|
55
|
+
export type MCPToolEntry = {
|
|
56
|
+
name: string;
|
|
57
|
+
title: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
serverName: string;
|
|
60
|
+
permission: Permission;
|
|
61
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var types_exports = {};
|
|
24
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export type McpTool = {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
inputSchema?: any;
|
|
13
|
+
resourceName?: string;
|
|
14
|
+
actionName?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
method?: string;
|
|
17
|
+
call: (args: Record<string, any>, context?: McpToolCallContext) => Promise<any>;
|
|
18
|
+
};
|
|
19
|
+
export type McpToolCallContext = {
|
|
20
|
+
token?: string;
|
|
21
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
22
|
+
};
|
|
23
|
+
export type McpToolResultPostProcessorContext = {
|
|
24
|
+
tool: McpTool;
|
|
25
|
+
args: Record<string, any>;
|
|
26
|
+
callContext?: McpToolCallContext;
|
|
27
|
+
response?: {
|
|
28
|
+
statusCode?: number;
|
|
29
|
+
headers?: Record<string, any>;
|
|
30
|
+
body?: any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type McpToolResultPostProcessor = (result: any, context: McpToolResultPostProcessorContext) => any | Promise<any>;
|
|
34
|
+
export declare class McpToolsManager {
|
|
35
|
+
private tools;
|
|
36
|
+
private resultPostProcessors;
|
|
37
|
+
private getActionKey;
|
|
38
|
+
registerTools(tools: McpTool[]): void;
|
|
39
|
+
registerToolResultPostProcessor(resourceName: string, actionName: string, processor: McpToolResultPostProcessor): void;
|
|
40
|
+
postProcessToolResult(tool: McpTool, result: any, context: Omit<McpToolResultPostProcessorContext, 'tool'>): Promise<any>;
|
|
41
|
+
listTools(): McpTool[];
|
|
42
|
+
getTool(name: string): McpTool;
|
|
43
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var mcp_tools_manager_exports = {};
|
|
29
|
+
__export(mcp_tools_manager_exports, {
|
|
30
|
+
McpToolsManager: () => McpToolsManager
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(mcp_tools_manager_exports);
|
|
33
|
+
var import_utils = require("@nocobase/utils");
|
|
34
|
+
const _McpToolsManager = class _McpToolsManager {
|
|
35
|
+
tools = new import_utils.Registry();
|
|
36
|
+
resultPostProcessors = /* @__PURE__ */ new Map();
|
|
37
|
+
getActionKey(resourceName, actionName) {
|
|
38
|
+
return `${resourceName}:${actionName}`;
|
|
39
|
+
}
|
|
40
|
+
registerTools(tools) {
|
|
41
|
+
for (const tool of tools) {
|
|
42
|
+
this.tools.register(tool.name, tool);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
registerToolResultPostProcessor(resourceName, actionName, processor) {
|
|
46
|
+
const key = this.getActionKey(resourceName, actionName);
|
|
47
|
+
const processors = this.resultPostProcessors.get(key) || [];
|
|
48
|
+
processors.push(processor);
|
|
49
|
+
this.resultPostProcessors.set(key, processors);
|
|
50
|
+
}
|
|
51
|
+
async postProcessToolResult(tool, result, context) {
|
|
52
|
+
if (!tool.resourceName || !tool.actionName) {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
const processors = this.resultPostProcessors.get(this.getActionKey(tool.resourceName, tool.actionName)) || [];
|
|
56
|
+
let current = result;
|
|
57
|
+
for (const processor of processors) {
|
|
58
|
+
current = await processor(current, {
|
|
59
|
+
...context,
|
|
60
|
+
tool
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return current;
|
|
64
|
+
}
|
|
65
|
+
listTools() {
|
|
66
|
+
return [...this.tools.getValues()];
|
|
67
|
+
}
|
|
68
|
+
getTool(name) {
|
|
69
|
+
return this.tools.get(name);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__name(_McpToolsManager, "McpToolsManager");
|
|
73
|
+
let McpToolsManager = _McpToolsManager;
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
McpToolsManager
|
|
77
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { SkillsEntry, SkillsManager, SkillsOptions, SkillsFilter } from './types';
|
|
10
|
+
export declare class DefaultSkillsManager implements SkillsManager {
|
|
11
|
+
private readonly app;
|
|
12
|
+
private readonly skills;
|
|
13
|
+
private readonly provideCollectionManager;
|
|
14
|
+
private mode;
|
|
15
|
+
constructor(app: any);
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
getSkills(name: string[]): Promise<SkillsEntry[]>;
|
|
18
|
+
getSkills(name: string): Promise<SkillsEntry>;
|
|
19
|
+
listSkills(filter: SkillsFilter): Promise<SkillsEntry[]>;
|
|
20
|
+
registerSkills(options: SkillsOptions): Promise<void>;
|
|
21
|
+
persistence(): Promise<void>;
|
|
22
|
+
private registerSkillsInMemory;
|
|
23
|
+
registerSkillsInDatabase(options: SkillsOptions): Promise<void>;
|
|
24
|
+
private get aiSkillsCollection();
|
|
25
|
+
private get aiSkillsModel();
|
|
26
|
+
private get sequelize();
|
|
27
|
+
private get collectionManager();
|
|
28
|
+
}
|
|
29
|
+
export * from './types';
|