Skip to content

Commit 74cd9f9

Browse files
committed
2 parents 49e8dac + 0667c41 commit 74cd9f9

File tree

5 files changed

+103
-19
lines changed

5 files changed

+103
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ build
22
node_modules
33
modules
44
index.js
5-
index.d.ts
5+
index.d.ts

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.70",
3+
"version": "1.1.71",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Codebolt { // Extend EventEmitter
9292
debug = debug;
9393
tokenizer = tokenizer;
9494
chatSummary=chatSummary;
95-
codeboltMCP = codeboltMCP;
95+
MCP = codeboltMCP;
9696
}
9797

9898
export default new Codebolt();

src/modules/chat.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let eventEmitter = new CustomEventEmitter()
1414
* Chat module to interact with the WebSocket server.
1515
*/
1616
const cbchat = {
17-
1817
/**
1918
* Retrieves the chat history from the server.
2019
* @returns {Promise<ChatMessage[]>} A promise that resolves with an array of ChatMessage objects representing the chat history.
@@ -32,7 +31,6 @@ const cbchat = {
3231
})
3332
})
3433
},
35-
3634
/**
3735
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
3836
* @returns {EventEmitter} The event emitter used for emitting custom events.
@@ -53,7 +51,6 @@ const cbchat = {
5351
});
5452
return eventEmitter;
5553
},
56-
5754
/**
5855
* Sends a message through the WebSocket connection.
5956
* @param {string} message - The message to be sent.
@@ -66,7 +63,6 @@ const cbchat = {
6663
payload
6764
}));
6865
},
69-
7066
/**
7167
* Waits for a reply to a sent message.
7268
* @param {string} message - The message for which a reply is expected.
@@ -86,7 +82,6 @@ const cbchat = {
8682
});
8783
});
8884
},
89-
9085
/**
9186
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
9287
* @returns An object containing the event emitter and a stopProcess method.
@@ -143,7 +138,6 @@ const cbchat = {
143138
"type": "processFinished"
144139
}));
145140
},
146-
147141
/**
148142
* Sends a confirmation request to the server with two options: Yes or No.
149143
* @returns {Promise<string>} A promise that resolves with the server's response.
@@ -165,6 +159,23 @@ const cbchat = {
165159
});
166160
});
167161
},
162+
askQuestion: (question: string, buttons: string[] = [],withFeedback:boolean=false): Promise<string> => {
163+
return new Promise((resolve, reject) => {
164+
cbws.getWebsocket.send(JSON.stringify({
165+
"type": "confirmationRequest",
166+
"message": question,
167+
buttons: buttons,
168+
withFeedback
169+
170+
}));
171+
cbws.getWebsocket.on('message', (data: string) => {
172+
const response = JSON.parse(data);
173+
if (response.type === "confirmationResponse" || response.type === "feedbackResponse" ) {
174+
resolve(response); // Resolve the Promise with the server's response
175+
}
176+
});
177+
});
178+
},
168179
/**
169180
* Sends a notification event to the server.
170181
* @param {string} notificationMessage - The message to be sent in the notification.

src/modules/mcp.ts

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import cbws from './websocket';
22
const codeboltMCP = {
3-
getMcpList: (): Promise<any> => {
3+
4+
executeTool: ( toolName: string, params: any,mcpServer?: string,): Promise<any> => {
45
return new Promise((resolve, reject) => {
56
cbws.getWebsocket.send(JSON.stringify({
67
"type": "mcpEvent",
7-
"action": "getMcpList"
8+
"action": "executeTool",
9+
"toolName": toolName,
10+
"params": params
811
}));
912
cbws.getWebsocket.on('message', (data: string) => {
1013
try {
1114
const response = JSON.parse(data);
12-
if (response.type === "getMcpListResponse") {
15+
if (response.type === "executeToolResponse") {
1316
resolve(response.data);
1417
} else {
1518
reject(new Error("Unexpected response type"));
@@ -23,19 +26,17 @@ const codeboltMCP = {
2326
});
2427
});
2528
},
26-
executeTool: (mcpServer: string, toolName: string, params: any): Promise<any> => {
29+
getMcpTools: (tools: string[]): Promise<any> => {
2730
return new Promise((resolve, reject) => {
2831
cbws.getWebsocket.send(JSON.stringify({
2932
"type": "mcpEvent",
30-
"action": "executeTool",
31-
"mcpServer": mcpServer,
32-
"toolName": toolName,
33-
"params": params
33+
"action": "getMcpTools",
34+
"tools": tools
3435
}));
3536
cbws.getWebsocket.on('message', (data: string) => {
3637
try {
3738
const response = JSON.parse(data);
38-
if (response.type === "executeToolResponse" && response.toolName === toolName) {
39+
if (response.type === "getMcpToolsResponse") {
3940
resolve(response.data);
4041
} else {
4142
reject(new Error("Unexpected response type"));
@@ -48,7 +49,79 @@ const codeboltMCP = {
4849
reject(error);
4950
});
5051
});
51-
}
52+
53+
},
54+
getAllMCPTools: (mpcName: string): Promise<any> => {
55+
return new Promise((resolve, reject) => {
56+
cbws.getWebsocket.send(JSON.stringify({
57+
"type": "mcpEvent",
58+
"action": "getAllMCPTools",
59+
"mpcName": mpcName
60+
}));
61+
cbws.getWebsocket.on('message', (data: string) => {
62+
try {
63+
const response = JSON.parse(data);
64+
if (response.type === "getAllMCPToolsResponse") {
65+
resolve(response.data);
66+
} else {
67+
reject(new Error("Unexpected response type"));
68+
}
69+
} catch (error) {
70+
reject(new Error("Failed to parse response"));
71+
}
72+
});
73+
cbws.getWebsocket.on('error', (error: Error) => {
74+
reject(error);
75+
});
76+
});
77+
},
78+
getMCPTool: (name: string): Promise<any> => {
79+
return new Promise((resolve, reject) => {
80+
cbws.getWebsocket.send(JSON.stringify({
81+
"type": "mcpEvent",
82+
"action": "getMCPTool",
83+
"mcpName": name
84+
}));
85+
cbws.getWebsocket.on('message', (data: string) => {
86+
try {
87+
const response = JSON.parse(data);
88+
if (response.type === "getMCPToolResponse") {
89+
resolve(response.data);
90+
} else {
91+
reject(new Error("Unexpected response type"));
92+
}
93+
} catch (error) {
94+
reject(new Error("Failed to parse response"));
95+
}
96+
});
97+
cbws.getWebsocket.on('error', (error: Error) => {
98+
reject(error);
99+
});
100+
});
101+
},
102+
getEnabledMCPS: (): Promise<any> => {
103+
return new Promise((resolve, reject) => {
104+
cbws.getWebsocket.send(JSON.stringify({
105+
"type": "mcpEvent",
106+
"action": "getEnabledMCPS"
107+
}));
108+
cbws.getWebsocket.on('message', (data: string) => {
109+
try {
110+
const response = JSON.parse(data);
111+
if (response.type === "getEnabledMCPSResponse") {
112+
resolve(response.data);
113+
} else {
114+
reject(new Error("Unexpected response type"));
115+
}
116+
} catch (error) {
117+
reject(new Error("Failed to parse response"));
118+
}
119+
});
120+
cbws.getWebsocket.on('error', (error: Error) => {
121+
reject(error);
122+
});
123+
});
124+
},
52125
}
53126

54127
export default codeboltMCP;

0 commit comments

Comments
 (0)