@codebolt/codeboltjs 1.1.91 → 1.1.94
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/index.d.ts +15 -8
- package/index.js +3 -3
- package/modules/agentlib/agent.d.ts +1 -0
- package/modules/agentlib/agent.js +68 -6
- package/modules/agentlib/usermessage.d.ts +1 -1
- package/modules/agentlib/usermessage.js +4 -4
- package/modules/chat.js +2 -1
- package/modules/mcp.d.ts +1 -0
- package/modules/mcp.js +24 -0
- package/modules/toolBox.bkp.d.ts +262 -0
- package/modules/toolBox.bkp.js +721 -0
- package/modules/toolBox.d.ts +36 -17
- package/modules/toolBox.js +62 -21
- package/modules/tools.d.ts +16 -0
- package/modules/tools.js +197 -0
- package/package.json +3 -2
- package/src/index.ts +3 -3
- package/src/modules/agentlib/agent.ts +83 -11
- package/src/modules/agentlib/usermessage.ts +5 -5
- package/src/modules/chat.ts +2 -1
- package/src/modules/toolBox.bkp.ts +1165 -0
- package/src/modules/toolBox.ts +108 -66
- package/src/modules/tools.ts +187 -0
- package/src/modules/mcp.ts +0 -117
package/src/modules/toolBox.ts
CHANGED
|
@@ -22,23 +22,24 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
22
22
|
import { z } from "zod";
|
|
23
23
|
import { setTimeout as delay } from "timers/promises";
|
|
24
24
|
import { readFile } from "fs/promises";
|
|
25
|
-
|
|
26
|
-
// type FileTypeModule = typeof import('file-type');
|
|
25
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
27
26
|
import { StrictEventEmitter } from "strict-event-emitter-types";
|
|
28
27
|
import { EventEmitter } from "events";
|
|
29
28
|
import Fuse from "fuse.js";
|
|
30
|
-
|
|
29
|
+
import { startSSEServer } from "mcp-proxy";
|
|
31
30
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
32
31
|
import parseURITemplate from "uri-templates";
|
|
32
|
+
import http from "http";
|
|
33
|
+
import { fetch } from "undici";
|
|
33
34
|
import { loadEsm } from "load-esm";
|
|
34
35
|
|
|
35
36
|
export type SSEServer = {
|
|
36
37
|
close: () => Promise<void>;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
type FastMCPEvents = {
|
|
40
|
-
connect: (event: { session: FastMCPSession }) => void;
|
|
41
|
-
disconnect: (event: { session: FastMCPSession }) => void;
|
|
40
|
+
type FastMCPEvents<T extends FastMCPSessionAuth> = {
|
|
41
|
+
connect: (event: { session: FastMCPSession<T> }) => void;
|
|
42
|
+
disconnect: (event: { session: FastMCPSession<T> }) => void;
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
type FastMCPSessionEvents = {
|
|
@@ -71,6 +72,7 @@ export const imageContent = async (
|
|
|
71
72
|
"Invalid input: Provide a valid 'url', 'path', or 'buffer'",
|
|
72
73
|
);
|
|
73
74
|
}
|
|
75
|
+
|
|
74
76
|
const { fileTypeFromBuffer } = await loadEsm('file-type');
|
|
75
77
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
76
78
|
console.log(mimeType);
|
|
@@ -108,7 +110,7 @@ export class UnexpectedStateError extends FastMCPError {
|
|
|
108
110
|
/**
|
|
109
111
|
* An error that is meant to be surfaced to the user.
|
|
110
112
|
*/
|
|
111
|
-
export class UserError extends UnexpectedStateError {
|
|
113
|
+
export class UserError extends UnexpectedStateError {}
|
|
112
114
|
|
|
113
115
|
type ToolParameters = z.ZodTypeAny;
|
|
114
116
|
|
|
@@ -130,7 +132,8 @@ type Progress = {
|
|
|
130
132
|
total?: number;
|
|
131
133
|
};
|
|
132
134
|
|
|
133
|
-
type Context = {
|
|
135
|
+
type Context<T extends FastMCPSessionAuth> = {
|
|
136
|
+
session: T | undefined;
|
|
134
137
|
reportProgress: (progress: Progress) => Promise<void>;
|
|
135
138
|
log: {
|
|
136
139
|
debug: (message: string, data?: SerializableValue) => void;
|
|
@@ -218,23 +221,23 @@ const CompletionZodSchema = z.object({
|
|
|
218
221
|
hasMore: z.optional(z.boolean()),
|
|
219
222
|
}) satisfies z.ZodType<Completion>;
|
|
220
223
|
|
|
221
|
-
type Tool<Params extends ToolParameters = ToolParameters> = {
|
|
224
|
+
type Tool<T extends FastMCPSessionAuth, Params extends ToolParameters = ToolParameters> = {
|
|
222
225
|
name: string;
|
|
223
226
|
description?: string;
|
|
224
227
|
parameters?: Params;
|
|
225
228
|
execute: (
|
|
226
229
|
args: z.infer<Params>,
|
|
227
|
-
context: Context
|
|
230
|
+
context: Context<T>,
|
|
228
231
|
) => Promise<string | ContentResult | TextContent | ImageContent>;
|
|
229
232
|
};
|
|
230
233
|
|
|
231
234
|
type ResourceResult =
|
|
232
235
|
| {
|
|
233
|
-
|
|
234
|
-
|
|
236
|
+
text: string;
|
|
237
|
+
}
|
|
235
238
|
| {
|
|
236
|
-
|
|
237
|
-
|
|
239
|
+
blob: string;
|
|
240
|
+
};
|
|
238
241
|
|
|
239
242
|
type InputResourceTemplateArgument = Readonly<{
|
|
240
243
|
name: string;
|
|
@@ -304,8 +307,8 @@ type PromptArgumentsToObject<T extends { name: string; required?: boolean }[]> =
|
|
|
304
307
|
T[number],
|
|
305
308
|
{ name: K }
|
|
306
309
|
>["required"] extends true
|
|
307
|
-
|
|
308
|
-
|
|
310
|
+
? string
|
|
311
|
+
: string | undefined;
|
|
309
312
|
};
|
|
310
313
|
|
|
311
314
|
type InputPrompt<
|
|
@@ -337,9 +340,10 @@ type Prompt<
|
|
|
337
340
|
name: string;
|
|
338
341
|
};
|
|
339
342
|
|
|
340
|
-
type ServerOptions = {
|
|
343
|
+
type ServerOptions<T extends FastMCPSessionAuth> = {
|
|
341
344
|
name: string;
|
|
342
345
|
version: `${number}.${number}.${number}`;
|
|
346
|
+
authenticate?: Authenticate<T>;
|
|
343
347
|
};
|
|
344
348
|
|
|
345
349
|
type LoggingLevel =
|
|
@@ -353,10 +357,10 @@ type LoggingLevel =
|
|
|
353
357
|
| "emergency";
|
|
354
358
|
|
|
355
359
|
const FastMCPSessionEventEmitterBase: {
|
|
356
|
-
new(): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
|
|
360
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
|
|
357
361
|
} = EventEmitter;
|
|
358
362
|
|
|
359
|
-
class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
|
|
363
|
+
class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {}
|
|
360
364
|
|
|
361
365
|
type SamplingResponse = {
|
|
362
366
|
model: string;
|
|
@@ -365,7 +369,9 @@ type SamplingResponse = {
|
|
|
365
369
|
content: TextContent | ImageContent;
|
|
366
370
|
};
|
|
367
371
|
|
|
368
|
-
|
|
372
|
+
type FastMCPSessionAuth = Record<string, unknown> | undefined;
|
|
373
|
+
|
|
374
|
+
export class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends FastMCPSessionEventEmitter {
|
|
369
375
|
#capabilities: ServerCapabilities = {};
|
|
370
376
|
#clientCapabilities?: ClientCapabilities;
|
|
371
377
|
#loggingLevel: LoggingLevel = "info";
|
|
@@ -374,8 +380,10 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
374
380
|
#resourceTemplates: ResourceTemplate[] = [];
|
|
375
381
|
#roots: Root[] = [];
|
|
376
382
|
#server: Server;
|
|
383
|
+
#auth: T | undefined;
|
|
377
384
|
|
|
378
385
|
constructor({
|
|
386
|
+
auth,
|
|
379
387
|
name,
|
|
380
388
|
version,
|
|
381
389
|
tools,
|
|
@@ -383,15 +391,18 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
383
391
|
resourcesTemplates,
|
|
384
392
|
prompts,
|
|
385
393
|
}: {
|
|
394
|
+
auth?: T;
|
|
386
395
|
name: string;
|
|
387
396
|
version: string;
|
|
388
|
-
tools: Tool[];
|
|
397
|
+
tools: Tool<T>[];
|
|
389
398
|
resources: Resource[];
|
|
390
399
|
resourcesTemplates: InputResourceTemplate[];
|
|
391
400
|
prompts: Prompt[];
|
|
392
401
|
}) {
|
|
393
402
|
super();
|
|
394
403
|
|
|
404
|
+
this.#auth = auth;
|
|
405
|
+
|
|
395
406
|
if (tools.length) {
|
|
396
407
|
this.#capabilities.tools = {};
|
|
397
408
|
}
|
|
@@ -544,6 +555,7 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
544
555
|
|
|
545
556
|
while (attempt++ < 10) {
|
|
546
557
|
const capabilities = await this.#server.getClientCapabilities();
|
|
558
|
+
console.log("capabilities", capabilities);
|
|
547
559
|
|
|
548
560
|
if (capabilities) {
|
|
549
561
|
this.#clientCapabilities = capabilities;
|
|
@@ -555,7 +567,7 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
555
567
|
}
|
|
556
568
|
|
|
557
569
|
if (!this.#clientCapabilities) {
|
|
558
|
-
|
|
570
|
+
console.warn('[warning] toolBox could not infer client capabilities')
|
|
559
571
|
}
|
|
560
572
|
|
|
561
573
|
if (this.#clientCapabilities?.roots) {
|
|
@@ -584,7 +596,11 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
584
596
|
clearInterval(this.#pingInterval);
|
|
585
597
|
}
|
|
586
598
|
|
|
587
|
-
|
|
599
|
+
try {
|
|
600
|
+
await this.#server.close();
|
|
601
|
+
} catch (error) {
|
|
602
|
+
console.error("[MCP Error]", "could not close server", error);
|
|
603
|
+
}
|
|
588
604
|
}
|
|
589
605
|
|
|
590
606
|
private setupErrorHandling() {
|
|
@@ -693,7 +709,7 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
693
709
|
});
|
|
694
710
|
}
|
|
695
711
|
|
|
696
|
-
private setupToolHandlers(tools: Tool[]) {
|
|
712
|
+
private setupToolHandlers(tools: Tool<T>[]) {
|
|
697
713
|
this.#server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
698
714
|
return {
|
|
699
715
|
tools: tools.map((tool) => {
|
|
@@ -790,6 +806,7 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
790
806
|
const maybeStringResult = await tool.execute(args, {
|
|
791
807
|
reportProgress,
|
|
792
808
|
log,
|
|
809
|
+
session: this.#auth,
|
|
793
810
|
});
|
|
794
811
|
|
|
795
812
|
if (typeof maybeStringResult === "string") {
|
|
@@ -1003,35 +1020,39 @@ export class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
1003
1020
|
}
|
|
1004
1021
|
|
|
1005
1022
|
const FastMCPEventEmitterBase: {
|
|
1006
|
-
new(): StrictEventEmitter<EventEmitter, FastMCPEvents
|
|
1023
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPEvents<FastMCPSessionAuth>>;
|
|
1007
1024
|
} = EventEmitter;
|
|
1008
1025
|
|
|
1009
|
-
class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
1026
|
+
class FastMCPEventEmitter extends FastMCPEventEmitterBase {}
|
|
1010
1027
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1028
|
+
type Authenticate<T> = (request: http.IncomingMessage) => Promise<T>;
|
|
1029
|
+
|
|
1030
|
+
export class ToolBox<T extends Record<string, unknown> | undefined = undefined> extends FastMCPEventEmitter {
|
|
1031
|
+
#options: ServerOptions<T>;
|
|
1013
1032
|
#prompts: InputPrompt[] = [];
|
|
1014
1033
|
#resources: Resource[] = [];
|
|
1015
1034
|
#resourcesTemplates: InputResourceTemplate[] = [];
|
|
1016
|
-
#sessions: FastMCPSession[] = [];
|
|
1035
|
+
#sessions: FastMCPSession<T>[] = [];
|
|
1017
1036
|
#sseServer: SSEServer | null = null;
|
|
1018
|
-
#tools: Tool[] = [];
|
|
1037
|
+
#tools: Tool<T>[] = [];
|
|
1038
|
+
#authenticate: Authenticate<T> | undefined;
|
|
1019
1039
|
|
|
1020
|
-
constructor(public options: ServerOptions) {
|
|
1040
|
+
constructor(public options: ServerOptions<T>) {
|
|
1021
1041
|
super();
|
|
1022
1042
|
|
|
1023
1043
|
this.#options = options;
|
|
1044
|
+
this.#authenticate = options.authenticate;
|
|
1024
1045
|
}
|
|
1025
1046
|
|
|
1026
|
-
public get sessions(): FastMCPSession[] {
|
|
1047
|
+
public get sessions(): FastMCPSession<T>[] {
|
|
1027
1048
|
return this.#sessions;
|
|
1028
1049
|
}
|
|
1029
1050
|
|
|
1030
1051
|
/**
|
|
1031
1052
|
* Adds a tool to the server.
|
|
1032
1053
|
*/
|
|
1033
|
-
public addTool<Params extends ToolParameters>(tool: Tool<Params>) {
|
|
1034
|
-
this.#tools.push(tool as unknown as Tool);
|
|
1054
|
+
public addTool<Params extends ToolParameters>(tool: Tool<T, Params>) {
|
|
1055
|
+
this.#tools.push(tool as unknown as Tool<T>);
|
|
1035
1056
|
}
|
|
1036
1057
|
|
|
1037
1058
|
/**
|
|
@@ -1059,6 +1080,55 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1059
1080
|
this.#prompts.push(prompt);
|
|
1060
1081
|
}
|
|
1061
1082
|
|
|
1083
|
+
/**
|
|
1084
|
+
* Starts the server.
|
|
1085
|
+
*/
|
|
1086
|
+
public async start(
|
|
1087
|
+
options:
|
|
1088
|
+
| { transportType: "stdio" }
|
|
1089
|
+
| {
|
|
1090
|
+
transportType: "sse";
|
|
1091
|
+
sse: { endpoint: `/${string}`; port: number };
|
|
1092
|
+
} = {
|
|
1093
|
+
transportType: "stdio",
|
|
1094
|
+
},
|
|
1095
|
+
) {
|
|
1096
|
+
if (options.transportType === "stdio") {
|
|
1097
|
+
const transport = new StdioServerTransport();
|
|
1098
|
+
|
|
1099
|
+
const session = new FastMCPSession<T>({
|
|
1100
|
+
name: this.#options.name,
|
|
1101
|
+
version: this.#options.version,
|
|
1102
|
+
tools: this.#tools,
|
|
1103
|
+
resources: this.#resources,
|
|
1104
|
+
resourcesTemplates: this.#resourcesTemplates,
|
|
1105
|
+
prompts: this.#prompts,
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
await session.connect(transport);
|
|
1109
|
+
|
|
1110
|
+
this.#sessions.push(session);
|
|
1111
|
+
|
|
1112
|
+
this.emit("connect", {
|
|
1113
|
+
session,
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
} else if (options.transportType === "sse") {
|
|
1117
|
+
|
|
1118
|
+
} else {
|
|
1119
|
+
throw new Error("Invalid transport type");
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Stops the server.
|
|
1125
|
+
*/
|
|
1126
|
+
public async stop() {
|
|
1127
|
+
if (this.#sseServer) {
|
|
1128
|
+
this.#sseServer.close();
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1062
1132
|
/**
|
|
1063
1133
|
* Starts the server.
|
|
1064
1134
|
*/
|
|
@@ -1074,6 +1144,7 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1074
1144
|
) {
|
|
1075
1145
|
if (options.transportType === "stdio") {
|
|
1076
1146
|
const transport = new StdioServerTransport();
|
|
1147
|
+
// console.log("tools", this.#tools);
|
|
1077
1148
|
|
|
1078
1149
|
const session = new FastMCPSession({
|
|
1079
1150
|
name: this.#options.name,
|
|
@@ -1083,7 +1154,7 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1083
1154
|
resourcesTemplates: this.#resourcesTemplates,
|
|
1084
1155
|
prompts: this.#prompts,
|
|
1085
1156
|
});
|
|
1086
|
-
console.log("session", session);
|
|
1157
|
+
// console.log("session", session);
|
|
1087
1158
|
await session.connect(transport);
|
|
1088
1159
|
|
|
1089
1160
|
this.#sessions.push(session);
|
|
@@ -1129,36 +1200,7 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1129
1200
|
}
|
|
1130
1201
|
}
|
|
1131
1202
|
|
|
1132
|
-
|
|
1133
|
-
* Stops the server.
|
|
1134
|
-
*/
|
|
1135
|
-
public async stop() {
|
|
1136
|
-
if (this.#sseServer) {
|
|
1137
|
-
this.#sseServer.close();
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
// public async activate() {
|
|
1142
|
-
|
|
1143
|
-
// const transport = new StdioServerTransport();
|
|
1203
|
+
|
|
1144
1204
|
|
|
1145
|
-
|
|
1146
|
-
// name: this.#options.name,
|
|
1147
|
-
// version: this.#options.version,
|
|
1148
|
-
// tools: this.#tools,
|
|
1149
|
-
// resources: this.#resources,
|
|
1150
|
-
// resourcesTemplates: this.#resourcesTemplates,
|
|
1151
|
-
// prompts: this.#prompts,
|
|
1152
|
-
// });
|
|
1153
|
-
|
|
1154
|
-
// await session.connect(transport);
|
|
1155
|
-
|
|
1156
|
-
// this.#sessions.push(session);
|
|
1157
|
-
|
|
1158
|
-
// this.emit("connect", {
|
|
1159
|
-
// session,
|
|
1160
|
-
// });
|
|
1205
|
+
}
|
|
1161
1206
|
|
|
1162
|
-
// console.info(`server is running on stdio`);
|
|
1163
|
-
// }
|
|
1164
|
-
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { UserMessage } from '../utils';
|
|
2
|
+
import cbws from './websocket';
|
|
3
|
+
const codeboltMCP = {
|
|
4
|
+
getEnabledToolBoxes: (): Promise<any> => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
7
|
+
"type": "codebolttools",
|
|
8
|
+
"action": "getEnabledToolBoxes"
|
|
9
|
+
}));
|
|
10
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
11
|
+
try {
|
|
12
|
+
const response = JSON.parse(data);
|
|
13
|
+
if (response.type === "getEnabledToolBoxesResponse") {
|
|
14
|
+
resolve(response.data);
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {
|
|
17
|
+
reject(new Error("Failed to parse response"));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
getLocalToolBoxes: (): Promise<any> => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
28
|
+
"type": "codebolttools",
|
|
29
|
+
"action": "getLocalToolBoxes"
|
|
30
|
+
}));
|
|
31
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
32
|
+
try {
|
|
33
|
+
const response = JSON.parse(data);
|
|
34
|
+
if (response.type === "getLocalToolBoxesResponse") {
|
|
35
|
+
resolve(response.data);
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
reject(new Error("Failed to parse response"));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
42
|
+
reject(error);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
getMentionedToolBoxes: (userMessage: UserMessage): Promise<any> => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
resolve(userMessage.mentionedMCPs);
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
getAvailableToolBoxes: (): Promise<any> => {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
54
|
+
"type": "codebolttools",
|
|
55
|
+
"action": "getAvailableToolBoxes"
|
|
56
|
+
}));
|
|
57
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
58
|
+
try {
|
|
59
|
+
const response = JSON.parse(data);
|
|
60
|
+
if (response.type === "getAvailableToolBoxesResponse") {
|
|
61
|
+
resolve(response.data);
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(new Error("Failed to parse response"));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
68
|
+
reject(error);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
searchAvailableToolBoxes: (query: string): Promise<any> => {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
75
|
+
"type": "codebolttools",
|
|
76
|
+
"action": "searchAvailableToolBoxes",
|
|
77
|
+
"query": query
|
|
78
|
+
}));
|
|
79
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
80
|
+
try {
|
|
81
|
+
const response = JSON.parse(data);
|
|
82
|
+
if (response.type === "searchAvailableToolBoxesResponse") {
|
|
83
|
+
resolve(response.data);
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
reject(new Error("Failed to parse response"));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
listToolsFromToolBoxes: (toolBoxes: string[]): Promise<any> => {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
97
|
+
"type": "codebolttools",
|
|
98
|
+
"action": "listToolsFromToolBoxes",
|
|
99
|
+
"toolBoxes": toolBoxes
|
|
100
|
+
}));
|
|
101
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
102
|
+
try {
|
|
103
|
+
const response = JSON.parse(data);
|
|
104
|
+
if (response.type === "listToolsFromToolBoxesResponse") {
|
|
105
|
+
resolve(response.data);
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
reject(new Error("Failed to parse response"));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
112
|
+
reject(error);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
},
|
|
117
|
+
configureToolBox: (name: string, config: any): Promise<any> => {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
120
|
+
"type": "codebolttools",
|
|
121
|
+
"action": "configureToolBox",
|
|
122
|
+
"mcpName": name,
|
|
123
|
+
"config": config
|
|
124
|
+
}));
|
|
125
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
126
|
+
try {
|
|
127
|
+
const response = JSON.parse(data);
|
|
128
|
+
if (response.type === "configureToolBoxResponse") {
|
|
129
|
+
resolve(response.data);
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
reject(new Error("Failed to parse response"));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
136
|
+
reject(error);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
getTools: (tools: { toolbox: string, toolName: string }[]): Promise<any[]> => {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
143
|
+
"type": "codebolttools",
|
|
144
|
+
"action": "getTools",
|
|
145
|
+
"toolboxes": tools
|
|
146
|
+
}));
|
|
147
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
148
|
+
try {
|
|
149
|
+
const response = JSON.parse(data);
|
|
150
|
+
if (response.type === "getToolsResponse") {
|
|
151
|
+
resolve(response.data);
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
reject(new Error("Failed to parse response"));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
158
|
+
reject(error);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
executeTool: (toolbox: string, toolName: string, params: any): Promise<any> => {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
165
|
+
"type": "codebolttools",
|
|
166
|
+
"action": "executeTool",
|
|
167
|
+
"toolName": `${toolbox}--${toolName}`,
|
|
168
|
+
"params": params
|
|
169
|
+
}));
|
|
170
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
171
|
+
try {
|
|
172
|
+
const response = JSON.parse(data);
|
|
173
|
+
if (response.type === "executeToolResponse") {
|
|
174
|
+
resolve(response.data);
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
reject(new Error("Failed to parse response"));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
cbws.getWebsocket.on('error', (error: Error) => {
|
|
181
|
+
reject(error);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default codeboltMCP;
|
package/src/modules/mcp.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import cbws from './websocket';
|
|
2
|
-
const codeboltMCP = {
|
|
3
|
-
|
|
4
|
-
executeTool: ( toolName: string, params: any,mcpServer?: string,): Promise<any> => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
cbws.getWebsocket.send(JSON.stringify({
|
|
7
|
-
"type": "mcpEvent",
|
|
8
|
-
"action": "executeTool",
|
|
9
|
-
"toolName": toolName,
|
|
10
|
-
"params": params
|
|
11
|
-
}));
|
|
12
|
-
cbws.getWebsocket.on('message', (data: string) => {
|
|
13
|
-
try {
|
|
14
|
-
const response = JSON.parse(data);
|
|
15
|
-
if (response.type === "executeToolResponse") {
|
|
16
|
-
resolve(response.data);
|
|
17
|
-
}
|
|
18
|
-
} catch (error) {
|
|
19
|
-
reject(new Error("Failed to parse response"));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
cbws.getWebsocket.on('error', (error: Error) => {
|
|
23
|
-
reject(error);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
getMcpTools: (tools: string[]): Promise<any> => {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
cbws.getWebsocket.send(JSON.stringify({
|
|
30
|
-
"type": "mcpEvent",
|
|
31
|
-
"action": "getMcpTools",
|
|
32
|
-
"tools": tools
|
|
33
|
-
}));
|
|
34
|
-
cbws.getWebsocket.on('message', (data: string) => {
|
|
35
|
-
try {
|
|
36
|
-
const response = JSON.parse(data);
|
|
37
|
-
if (response.type === "getMcpToolsResponse") {
|
|
38
|
-
resolve(response.data);
|
|
39
|
-
}
|
|
40
|
-
} catch (error) {
|
|
41
|
-
reject(new Error("Failed to parse response"));
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
cbws.getWebsocket.on('error', (error: Error) => {
|
|
45
|
-
reject(error);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
getAllMCPTools: (mpcName: string): Promise<any> => {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
cbws.getWebsocket.send(JSON.stringify({
|
|
53
|
-
"type": "mcpEvent",
|
|
54
|
-
"action": "getAllMCPTools",
|
|
55
|
-
"mpcName": mpcName
|
|
56
|
-
}));
|
|
57
|
-
cbws.getWebsocket.on('message', (data: string) => {
|
|
58
|
-
try {
|
|
59
|
-
const response = JSON.parse(data);
|
|
60
|
-
if (response.type === "getAllMCPToolsResponse") {
|
|
61
|
-
resolve(response.data);
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
reject(new Error("Failed to parse response"));
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
cbws.getWebsocket.on('error', (error: Error) => {
|
|
68
|
-
reject(error);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
getMCPTool: (name: string): Promise<any> => {
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
cbws.getWebsocket.send(JSON.stringify({
|
|
75
|
-
"type": "mcpEvent",
|
|
76
|
-
"action": "getMCPTool",
|
|
77
|
-
"mcpName": name
|
|
78
|
-
}));
|
|
79
|
-
cbws.getWebsocket.on('message', (data: string) => {
|
|
80
|
-
try {
|
|
81
|
-
const response = JSON.parse(data);
|
|
82
|
-
if (response.type === "getMCPToolResponse") {
|
|
83
|
-
resolve(response.data);
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
reject(new Error("Failed to parse response"));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
cbws.getWebsocket.on('error', (error: Error) => {
|
|
90
|
-
reject(error);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
getEnabledMCPS: (): Promise<any> => {
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
cbws.getWebsocket.send(JSON.stringify({
|
|
97
|
-
"type": "mcpEvent",
|
|
98
|
-
"action": "getEnabledMCPS"
|
|
99
|
-
}));
|
|
100
|
-
cbws.getWebsocket.on('message', (data: string) => {
|
|
101
|
-
try {
|
|
102
|
-
const response = JSON.parse(data);
|
|
103
|
-
if (response.type === "getEnabledMCPSResponse") {
|
|
104
|
-
resolve(response.data);
|
|
105
|
-
}
|
|
106
|
-
} catch (error) {
|
|
107
|
-
reject(new Error("Failed to parse response"));
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
cbws.getWebsocket.on('error', (error: Error) => {
|
|
111
|
-
reject(error);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export default codeboltMCP;
|