@codebolt/codeboltjs 1.1.92 → 1.1.95
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 +2 -2
- package/modules/agentlib/agent.js +92 -16
- package/modules/agentlib/usermessage.d.ts +11 -1
- package/modules/agentlib/usermessage.js +8 -4
- 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 +111 -23
- package/src/modules/agentlib/usermessage.ts +23 -10
- 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/index.d.ts
CHANGED
|
@@ -237,14 +237,21 @@ declare class Codebolt {
|
|
|
237
237
|
content: string;
|
|
238
238
|
}[]>;
|
|
239
239
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
tools: {
|
|
241
|
+
getEnabledToolBoxes: () => Promise<any>;
|
|
242
|
+
getLocalToolBoxes: () => Promise<any>;
|
|
243
|
+
getMentionedToolBoxes: (userMessage: import("./utils").UserMessage) => Promise<any>;
|
|
244
|
+
getAvailableToolBoxes: () => Promise<any>;
|
|
245
|
+
searchAvailableToolBoxes: (query: string) => Promise<any>;
|
|
246
|
+
listToolsFromToolBoxes: (toolBoxes: string[]) => Promise<any>;
|
|
247
|
+
configureToolBox: (name: string, config: any) => Promise<any>;
|
|
248
|
+
getTools: (tools: {
|
|
249
|
+
toolbox: string;
|
|
250
|
+
toolName: string;
|
|
251
|
+
}[]) => Promise<any[]>;
|
|
252
|
+
executeTool: (toolbox: string, toolName: string, params: any) => Promise<any>;
|
|
253
|
+
};
|
|
254
|
+
agent: {
|
|
248
255
|
findAgent: (task: string, maxResult: number | undefined, agents: never[] | undefined, agentLocaltion: import("./modules/agent").AgentLocation | undefined, getFrom: import("./modules/agent").FilterUsing.USE_VECTOR_DB) => Promise<any>;
|
|
249
256
|
startAgent: (agentId: string, task: string) => Promise<any>;
|
|
250
257
|
getAgentsList: (type?: import("./modules/agent").Agents) => Promise<any>;
|
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const debug_1 = __importDefault(require("./modules/debug"));
|
|
|
27
27
|
const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
|
|
28
28
|
const ws_1 = __importDefault(require("ws"));
|
|
29
29
|
const history_1 = require("./modules/history");
|
|
30
|
-
const
|
|
30
|
+
const tools_1 = __importDefault(require("./modules/tools"));
|
|
31
31
|
const agent_1 = __importDefault(require("./modules/agent"));
|
|
32
32
|
/**
|
|
33
33
|
* @class Codebolt
|
|
@@ -62,8 +62,8 @@ class Codebolt {
|
|
|
62
62
|
this.debug = debug_1.default;
|
|
63
63
|
this.tokenizer = tokenizer_1.default;
|
|
64
64
|
this.chatSummary = history_1.chatSummary;
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
65
|
+
this.tools = tools_1.default;
|
|
66
|
+
this.agent = agent_1.default;
|
|
67
67
|
websocket_1.default.initializeWebSocket();
|
|
68
68
|
this.websocket = websocket_1.default.getWebsocket;
|
|
69
69
|
}
|
|
@@ -2,12 +2,12 @@ import { SystemPrompt } from "./systemprompt";
|
|
|
2
2
|
import { TaskInstruction } from "./taskInstruction";
|
|
3
3
|
declare class Agent {
|
|
4
4
|
private tools;
|
|
5
|
-
private subAgents;
|
|
6
5
|
private apiConversationHistory;
|
|
7
6
|
private maxRun;
|
|
8
7
|
private systemPrompt;
|
|
9
8
|
private userMessage;
|
|
10
|
-
|
|
9
|
+
private nextUserMessage;
|
|
10
|
+
constructor(tools: any, systemPrompt: SystemPrompt, maxRun?: number);
|
|
11
11
|
run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
|
|
12
12
|
success: boolean;
|
|
13
13
|
error: string | null;
|
|
@@ -5,32 +5,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Agent = void 0;
|
|
7
7
|
const chat_1 = __importDefault(require("./../chat"));
|
|
8
|
-
const
|
|
8
|
+
const tools_1 = __importDefault(require("./../tools"));
|
|
9
9
|
const llm_1 = __importDefault(require("./../llm"));
|
|
10
10
|
const agent_1 = __importDefault(require("./../agent"));
|
|
11
11
|
class Agent {
|
|
12
|
-
constructor(tools = [], systemPrompt, maxRun = 0
|
|
12
|
+
constructor(tools = [], systemPrompt, maxRun = 0) {
|
|
13
13
|
this.tools = tools;
|
|
14
14
|
this.userMessage = [];
|
|
15
15
|
this.apiConversationHistory = [];
|
|
16
16
|
this.maxRun = maxRun;
|
|
17
17
|
this.systemPrompt = systemPrompt;
|
|
18
|
-
this.subAgents = subAgents;
|
|
19
|
-
this.subAgents = subAgents.map(subagent => {
|
|
20
|
-
subagent.function.name = `subagent--${subagent.function.name}`;
|
|
21
|
-
return subagent;
|
|
22
|
-
});
|
|
23
|
-
this.tools = this.tools.concat(subAgents.map(subagent => ({
|
|
24
|
-
...subagent
|
|
25
|
-
})));
|
|
26
18
|
}
|
|
27
19
|
async run(task, successCondition = () => true) {
|
|
28
20
|
var _a, _b;
|
|
29
21
|
let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
|
|
30
22
|
this.tools = [
|
|
31
23
|
...this.tools,
|
|
32
|
-
...mentaionedMCPSTool
|
|
24
|
+
...mentaionedMCPSTool,
|
|
33
25
|
];
|
|
26
|
+
let mentionedAgents = await task.userMessage.getMentionedAgents();
|
|
27
|
+
// Transform agents into tool format
|
|
28
|
+
const agentTools = mentionedAgents.map(agent => {
|
|
29
|
+
return {
|
|
30
|
+
type: "function",
|
|
31
|
+
function: {
|
|
32
|
+
name: `subagent--${agent.unique_id}`,
|
|
33
|
+
description: agent.longDescription || agent.description,
|
|
34
|
+
parameters: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: {
|
|
37
|
+
task: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "The task to be executed by the tool."
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
required: ["task"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
this.tools = this.tools.concat(agentTools);
|
|
34
48
|
let completed = false;
|
|
35
49
|
let userMessages = await task.toPrompt();
|
|
36
50
|
this.apiConversationHistory.push({ role: "user", content: userMessages });
|
|
@@ -75,7 +89,18 @@ class Agent {
|
|
|
75
89
|
console.log("got sub agent resonse result", agentResponse);
|
|
76
90
|
const [didUserReject, result] = [false, "tool result is successful"];
|
|
77
91
|
console.log("got sub agent resonse result", didUserReject, result);
|
|
78
|
-
|
|
92
|
+
let toolResult = this.getToolResult(toolUseId, result);
|
|
93
|
+
toolResults.push({
|
|
94
|
+
role: "tool",
|
|
95
|
+
tool_call_id: toolResult.tool_call_id,
|
|
96
|
+
content: toolResult.content,
|
|
97
|
+
});
|
|
98
|
+
if (toolResult.userMessage) {
|
|
99
|
+
this.nextUserMessage = {
|
|
100
|
+
role: "user",
|
|
101
|
+
content: toolResult.userMessage
|
|
102
|
+
};
|
|
103
|
+
}
|
|
79
104
|
if (didUserReject) {
|
|
80
105
|
userRejectedToolUse = true;
|
|
81
106
|
}
|
|
@@ -84,7 +109,19 @@ class Agent {
|
|
|
84
109
|
console.log("calling tool with params", toolName, toolInput);
|
|
85
110
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
86
111
|
console.log("tool result", result);
|
|
87
|
-
toolResults.push(this.getToolResult(toolUseId, result));
|
|
112
|
+
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
113
|
+
let toolResult = this.getToolResult(toolUseId, result);
|
|
114
|
+
toolResults.push({
|
|
115
|
+
role: "tool",
|
|
116
|
+
tool_call_id: toolResult.tool_call_id,
|
|
117
|
+
content: toolResult.content,
|
|
118
|
+
});
|
|
119
|
+
if (toolResult.userMessage) {
|
|
120
|
+
this.nextUserMessage = {
|
|
121
|
+
role: "user",
|
|
122
|
+
content: toolResult.userMessage
|
|
123
|
+
};
|
|
124
|
+
}
|
|
88
125
|
if (didUserReject) {
|
|
89
126
|
userRejectedToolUse = true;
|
|
90
127
|
}
|
|
@@ -92,7 +129,18 @@ class Agent {
|
|
|
92
129
|
}
|
|
93
130
|
}
|
|
94
131
|
else {
|
|
95
|
-
|
|
132
|
+
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.");
|
|
133
|
+
toolResults.push({
|
|
134
|
+
role: "tool",
|
|
135
|
+
tool_call_id: toolResult.tool_call_id,
|
|
136
|
+
content: toolResult.content,
|
|
137
|
+
});
|
|
138
|
+
if (toolResult.userMessage) {
|
|
139
|
+
this.nextUserMessage = {
|
|
140
|
+
role: "user",
|
|
141
|
+
content: toolResult.userMessage
|
|
142
|
+
};
|
|
143
|
+
}
|
|
96
144
|
}
|
|
97
145
|
}
|
|
98
146
|
}
|
|
@@ -102,9 +150,23 @@ class Agent {
|
|
|
102
150
|
completed = true;
|
|
103
151
|
result = "The user is satisfied with the result.";
|
|
104
152
|
}
|
|
105
|
-
|
|
153
|
+
let toolResult = this.getToolResult(taskCompletedBlock.id, result);
|
|
154
|
+
toolResults.push({
|
|
155
|
+
role: "tool",
|
|
156
|
+
tool_call_id: toolResult.tool_call_id,
|
|
157
|
+
content: toolResult.content,
|
|
158
|
+
});
|
|
159
|
+
if (toolResult.userMessage) {
|
|
160
|
+
this.nextUserMessage = {
|
|
161
|
+
role: "user",
|
|
162
|
+
content: toolResult.userMessage
|
|
163
|
+
};
|
|
164
|
+
}
|
|
106
165
|
}
|
|
107
166
|
this.apiConversationHistory.push(...toolResults);
|
|
167
|
+
if (this.nextUserMessage) {
|
|
168
|
+
this.apiConversationHistory.push(this.nextUserMessage);
|
|
169
|
+
}
|
|
108
170
|
let nextUserMessage = toolResults;
|
|
109
171
|
if (toolResults.length === 0) {
|
|
110
172
|
nextUserMessage = [{
|
|
@@ -160,7 +222,9 @@ class Agent {
|
|
|
160
222
|
}
|
|
161
223
|
}
|
|
162
224
|
async executeTool(toolName, toolInput) {
|
|
163
|
-
|
|
225
|
+
//codebolttools--readfile
|
|
226
|
+
const [toolboxName, actualToolName] = toolName.split('--');
|
|
227
|
+
return tools_1.default.executeTool(toolboxName, actualToolName, toolInput);
|
|
164
228
|
}
|
|
165
229
|
async startSubAgent(agentName, params) {
|
|
166
230
|
return agent_1.default.startAgent(agentName, params.task);
|
|
@@ -173,10 +237,22 @@ class Agent {
|
|
|
173
237
|
};
|
|
174
238
|
}
|
|
175
239
|
getToolResult(tool_call_id, content) {
|
|
240
|
+
let userMessage = undefined;
|
|
241
|
+
try {
|
|
242
|
+
let parsed = JSON.parse(content);
|
|
243
|
+
if (parsed.payload && parsed.payload.content) {
|
|
244
|
+
content = `The browser action has been executed. The screenshot have been captured for your analysis. The tool response is provided in the next user message`;
|
|
245
|
+
// this.apiConversationHistory.push()
|
|
246
|
+
userMessage = parsed.payload.content;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
}
|
|
176
251
|
return {
|
|
177
252
|
role: "tool",
|
|
178
253
|
tool_call_id,
|
|
179
254
|
content,
|
|
255
|
+
userMessage
|
|
180
256
|
};
|
|
181
257
|
}
|
|
182
258
|
// Placeholder for error fallback method
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
interface agent {
|
|
2
|
+
description: string;
|
|
3
|
+
title: string;
|
|
4
|
+
id: number;
|
|
5
|
+
agent_id: string;
|
|
6
|
+
unique_id: string;
|
|
7
|
+
longDescription: string;
|
|
8
|
+
}
|
|
1
9
|
interface Message {
|
|
2
10
|
userMessage: string;
|
|
3
11
|
mentionedFiles?: string[];
|
|
4
12
|
mentionedMCPs: string[];
|
|
13
|
+
mentionedAgents: agent[];
|
|
5
14
|
}
|
|
6
15
|
export interface UserMessageContent {
|
|
7
16
|
type: string;
|
|
@@ -11,10 +20,11 @@ declare class UserMessage {
|
|
|
11
20
|
message: Message;
|
|
12
21
|
promptOverride: boolean;
|
|
13
22
|
userMessages: UserMessageContent[];
|
|
14
|
-
|
|
23
|
+
mentionedMCPs: string[];
|
|
15
24
|
constructor(message: Message, promptOverride?: boolean);
|
|
16
25
|
getFiles(): void;
|
|
17
26
|
toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean): Promise<UserMessageContent[]>;
|
|
27
|
+
getMentionedAgents(): agent[];
|
|
18
28
|
getMentionedMcps(): string[];
|
|
19
29
|
getMentionedMcpsTools(): Promise<any>;
|
|
20
30
|
private getEnvironmentDetail;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.UserMessage = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("./../fs"));
|
|
8
8
|
const project_1 = __importDefault(require("./../project"));
|
|
9
|
-
const
|
|
9
|
+
const tools_1 = __importDefault(require("./../tools"));
|
|
10
10
|
class UserMessage {
|
|
11
11
|
constructor(message, promptOverride = false) {
|
|
12
12
|
this.getEnvironmentDetail = async (cwd) => {
|
|
@@ -21,7 +21,7 @@ class UserMessage {
|
|
|
21
21
|
this.message = message;
|
|
22
22
|
this.promptOverride = promptOverride;
|
|
23
23
|
this.userMessages = [];
|
|
24
|
-
this.
|
|
24
|
+
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
25
25
|
}
|
|
26
26
|
getFiles() {
|
|
27
27
|
// Implementation to be added
|
|
@@ -54,12 +54,16 @@ class UserMessage {
|
|
|
54
54
|
}
|
|
55
55
|
return this.userMessages;
|
|
56
56
|
}
|
|
57
|
+
getMentionedAgents() {
|
|
58
|
+
//TODO : get config in tool format if neede
|
|
59
|
+
return this.message.mentionedAgents || [];
|
|
60
|
+
}
|
|
57
61
|
getMentionedMcps() {
|
|
58
62
|
return this.message.mentionedMCPs || [];
|
|
59
63
|
}
|
|
60
64
|
async getMentionedMcpsTools() {
|
|
61
|
-
if (this.
|
|
62
|
-
let tools = await
|
|
65
|
+
if (this.mentionedMCPs.length > 0) {
|
|
66
|
+
let tools = await tools_1.default.listToolsFromToolBoxes(this.mentionedMCPs);
|
|
63
67
|
return tools;
|
|
64
68
|
}
|
|
65
69
|
else {
|
package/modules/mcp.d.ts
CHANGED
package/modules/mcp.js
CHANGED
|
@@ -120,5 +120,29 @@ const codeboltMCP = {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
},
|
|
123
|
+
configureMCPTool: (name, config) => {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
126
|
+
"type": "mcpEvent",
|
|
127
|
+
"action": "configureMCPTool",
|
|
128
|
+
"mcpName": name,
|
|
129
|
+
"config": config
|
|
130
|
+
}));
|
|
131
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
132
|
+
try {
|
|
133
|
+
const response = JSON.parse(data);
|
|
134
|
+
if (response.type === "configureMCPToolResponse") {
|
|
135
|
+
resolve(response.data);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
reject(new Error("Failed to parse response"));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
143
|
+
reject(error);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
},
|
|
123
147
|
};
|
|
124
148
|
exports.default = codeboltMCP;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { ClientCapabilities, CreateMessageRequestSchema, Root } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { StrictEventEmitter } from "strict-event-emitter-types";
|
|
8
|
+
import { EventEmitter } from "events";
|
|
9
|
+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
10
|
+
export type SSEServer = {
|
|
11
|
+
close: () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
type FastMCPEvents = {
|
|
14
|
+
connect: (event: {
|
|
15
|
+
session: FastMCPSession;
|
|
16
|
+
}) => void;
|
|
17
|
+
disconnect: (event: {
|
|
18
|
+
session: FastMCPSession;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
21
|
+
type FastMCPSessionEvents = {
|
|
22
|
+
rootsChanged: (event: {
|
|
23
|
+
roots: Root[];
|
|
24
|
+
}) => void;
|
|
25
|
+
error: (event: {
|
|
26
|
+
error: Error;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Generates an image content object from a URL, file path, or buffer.
|
|
31
|
+
*/
|
|
32
|
+
export declare const imageContent: (input: {
|
|
33
|
+
url: string;
|
|
34
|
+
} | {
|
|
35
|
+
path: string;
|
|
36
|
+
} | {
|
|
37
|
+
buffer: Buffer;
|
|
38
|
+
}) => Promise<ImageContent>;
|
|
39
|
+
declare abstract class FastMCPError extends Error {
|
|
40
|
+
constructor(message?: string);
|
|
41
|
+
}
|
|
42
|
+
type Extra = unknown;
|
|
43
|
+
type Extras = Record<string, Extra>;
|
|
44
|
+
export declare class UnexpectedStateError extends FastMCPError {
|
|
45
|
+
extras?: Extras;
|
|
46
|
+
constructor(message: string, extras?: Extras);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An error that is meant to be surfaced to the user.
|
|
50
|
+
*/
|
|
51
|
+
export declare class UserError extends UnexpectedStateError {
|
|
52
|
+
}
|
|
53
|
+
type ToolParameters = z.ZodTypeAny;
|
|
54
|
+
type Literal = boolean | null | number | string | undefined;
|
|
55
|
+
type SerializableValue = Literal | SerializableValue[] | {
|
|
56
|
+
[key: string]: SerializableValue;
|
|
57
|
+
};
|
|
58
|
+
type Progress = {
|
|
59
|
+
/**
|
|
60
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
61
|
+
*/
|
|
62
|
+
progress: number;
|
|
63
|
+
/**
|
|
64
|
+
* Total number of items to process (or total progress required), if known.
|
|
65
|
+
*/
|
|
66
|
+
total?: number;
|
|
67
|
+
};
|
|
68
|
+
type Context = {
|
|
69
|
+
reportProgress: (progress: Progress) => Promise<void>;
|
|
70
|
+
log: {
|
|
71
|
+
debug: (message: string, data?: SerializableValue) => void;
|
|
72
|
+
error: (message: string, data?: SerializableValue) => void;
|
|
73
|
+
info: (message: string, data?: SerializableValue) => void;
|
|
74
|
+
warn: (message: string, data?: SerializableValue) => void;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
type TextContent = {
|
|
78
|
+
type: "text";
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
type ImageContent = {
|
|
82
|
+
type: "image";
|
|
83
|
+
data: string;
|
|
84
|
+
mimeType: string;
|
|
85
|
+
};
|
|
86
|
+
type Content = TextContent | ImageContent;
|
|
87
|
+
type ContentResult = {
|
|
88
|
+
content: Content[];
|
|
89
|
+
isError?: boolean;
|
|
90
|
+
};
|
|
91
|
+
type Completion = {
|
|
92
|
+
values: string[];
|
|
93
|
+
total?: number;
|
|
94
|
+
hasMore?: boolean;
|
|
95
|
+
};
|
|
96
|
+
type Tool<Params extends ToolParameters = ToolParameters> = {
|
|
97
|
+
name: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
parameters?: Params;
|
|
100
|
+
execute: (args: z.infer<Params>, context: Context) => Promise<string | ContentResult | TextContent | ImageContent>;
|
|
101
|
+
};
|
|
102
|
+
type ResourceResult = {
|
|
103
|
+
text: string;
|
|
104
|
+
} | {
|
|
105
|
+
blob: string;
|
|
106
|
+
};
|
|
107
|
+
type InputResourceTemplateArgument = Readonly<{
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
complete?: ArgumentValueCompleter;
|
|
111
|
+
}>;
|
|
112
|
+
type ResourceTemplateArgument = Readonly<{
|
|
113
|
+
name: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
complete?: ArgumentValueCompleter;
|
|
116
|
+
}>;
|
|
117
|
+
type ResourceTemplateArgumentsToObject<T extends {
|
|
118
|
+
name: string;
|
|
119
|
+
}[]> = {
|
|
120
|
+
[K in T[number]["name"]]: string;
|
|
121
|
+
};
|
|
122
|
+
type InputResourceTemplate<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = {
|
|
123
|
+
uriTemplate: string;
|
|
124
|
+
name: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
mimeType?: string;
|
|
127
|
+
arguments: Arguments;
|
|
128
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>) => Promise<ResourceResult>;
|
|
129
|
+
};
|
|
130
|
+
type Resource = {
|
|
131
|
+
uri: string;
|
|
132
|
+
name: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
mimeType?: string;
|
|
135
|
+
load: () => Promise<ResourceResult | ResourceResult[]>;
|
|
136
|
+
complete?: (name: string, value: string) => Promise<Completion>;
|
|
137
|
+
};
|
|
138
|
+
type ArgumentValueCompleter = (value: string) => Promise<Completion>;
|
|
139
|
+
type InputPromptArgument = Readonly<{
|
|
140
|
+
name: string;
|
|
141
|
+
description?: string;
|
|
142
|
+
required?: boolean;
|
|
143
|
+
complete?: ArgumentValueCompleter;
|
|
144
|
+
enum?: string[];
|
|
145
|
+
}>;
|
|
146
|
+
type PromptArgumentsToObject<T extends {
|
|
147
|
+
name: string;
|
|
148
|
+
required?: boolean;
|
|
149
|
+
}[]> = {
|
|
150
|
+
[K in T[number]["name"]]: Extract<T[number], {
|
|
151
|
+
name: K;
|
|
152
|
+
}>["required"] extends true ? string : string | undefined;
|
|
153
|
+
};
|
|
154
|
+
type InputPrompt<Arguments extends InputPromptArgument[] = InputPromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
|
|
155
|
+
name: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
arguments?: InputPromptArgument[];
|
|
158
|
+
load: (args: Args) => Promise<string>;
|
|
159
|
+
};
|
|
160
|
+
type PromptArgument = Readonly<{
|
|
161
|
+
name: string;
|
|
162
|
+
description?: string;
|
|
163
|
+
required?: boolean;
|
|
164
|
+
complete?: ArgumentValueCompleter;
|
|
165
|
+
enum?: string[];
|
|
166
|
+
}>;
|
|
167
|
+
type Prompt<Arguments extends PromptArgument[] = PromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
|
|
168
|
+
arguments?: PromptArgument[];
|
|
169
|
+
complete?: (name: string, value: string) => Promise<Completion>;
|
|
170
|
+
description?: string;
|
|
171
|
+
load: (args: Args) => Promise<string>;
|
|
172
|
+
name: string;
|
|
173
|
+
};
|
|
174
|
+
type ServerOptions = {
|
|
175
|
+
name: string;
|
|
176
|
+
version: `${number}.${number}.${number}`;
|
|
177
|
+
};
|
|
178
|
+
type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
179
|
+
declare const FastMCPSessionEventEmitterBase: {
|
|
180
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
|
|
181
|
+
};
|
|
182
|
+
declare class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
|
|
183
|
+
}
|
|
184
|
+
type SamplingResponse = {
|
|
185
|
+
model: string;
|
|
186
|
+
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
187
|
+
role: "user" | "assistant";
|
|
188
|
+
content: TextContent | ImageContent;
|
|
189
|
+
};
|
|
190
|
+
export declare class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
191
|
+
#private;
|
|
192
|
+
constructor({ name, version, tools, resources, resourcesTemplates, prompts, }: {
|
|
193
|
+
name: string;
|
|
194
|
+
version: string;
|
|
195
|
+
tools: Tool[];
|
|
196
|
+
resources: Resource[];
|
|
197
|
+
resourcesTemplates: InputResourceTemplate[];
|
|
198
|
+
prompts: Prompt[];
|
|
199
|
+
});
|
|
200
|
+
private addResource;
|
|
201
|
+
private addResourceTemplate;
|
|
202
|
+
private addPrompt;
|
|
203
|
+
get clientCapabilities(): ClientCapabilities | null;
|
|
204
|
+
get server(): Server;
|
|
205
|
+
requestSampling(message: z.infer<typeof CreateMessageRequestSchema>["params"]): Promise<SamplingResponse>;
|
|
206
|
+
connect(transport: Transport): Promise<void>;
|
|
207
|
+
get roots(): Root[];
|
|
208
|
+
close(): Promise<void>;
|
|
209
|
+
private setupErrorHandling;
|
|
210
|
+
get loggingLevel(): LoggingLevel;
|
|
211
|
+
private setupCompleteHandlers;
|
|
212
|
+
private setupRootsHandlers;
|
|
213
|
+
private setupLoggingHandlers;
|
|
214
|
+
private setupToolHandlers;
|
|
215
|
+
private setupResourceHandlers;
|
|
216
|
+
private setupResourceTemplateHandlers;
|
|
217
|
+
private setupPromptHandlers;
|
|
218
|
+
}
|
|
219
|
+
declare const FastMCPEventEmitterBase: {
|
|
220
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPEvents>;
|
|
221
|
+
};
|
|
222
|
+
declare class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
223
|
+
}
|
|
224
|
+
export declare class ToolBox extends FastMCPEventEmitter {
|
|
225
|
+
#private;
|
|
226
|
+
options: ServerOptions;
|
|
227
|
+
constructor(options: ServerOptions);
|
|
228
|
+
get sessions(): FastMCPSession[];
|
|
229
|
+
/**
|
|
230
|
+
* Adds a tool to the server.
|
|
231
|
+
*/
|
|
232
|
+
addTool<Params extends ToolParameters>(tool: Tool<Params>): void;
|
|
233
|
+
/**
|
|
234
|
+
* Adds a resource to the server.
|
|
235
|
+
*/
|
|
236
|
+
addResource(resource: Resource): void;
|
|
237
|
+
/**
|
|
238
|
+
* Adds a resource template to the server.
|
|
239
|
+
*/
|
|
240
|
+
addResourceTemplate<const Args extends InputResourceTemplateArgument[]>(resource: InputResourceTemplate<Args>): void;
|
|
241
|
+
/**
|
|
242
|
+
* Adds a prompt to the server.
|
|
243
|
+
*/
|
|
244
|
+
addPrompt<const Args extends InputPromptArgument[]>(prompt: InputPrompt<Args>): void;
|
|
245
|
+
/**
|
|
246
|
+
* Starts the server.
|
|
247
|
+
*/
|
|
248
|
+
activate(options?: {
|
|
249
|
+
transportType: "stdio";
|
|
250
|
+
} | {
|
|
251
|
+
transportType: "sse";
|
|
252
|
+
sse: {
|
|
253
|
+
endpoint: `/${string}`;
|
|
254
|
+
port: number;
|
|
255
|
+
};
|
|
256
|
+
}): Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* Stops the server.
|
|
259
|
+
*/
|
|
260
|
+
stop(): Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
export {};
|