@codebolt/codeboltjs 2.0.16 → 2.1.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/dist/core/Codebolt.d.ts +49 -54
- package/dist/core/messageManager.d.ts +0 -1
- package/dist/modules/chat.d.ts +1 -1
- package/dist/modules/codeparsers.js +24 -15
- package/dist/modules/codeutils.js +19 -9
- package/dist/modules/mcp.d.ts +1 -2
- package/dist/modules/mcp.js +2 -0
- package/dist/modules/task.d.ts +1 -1
- package/dist/modules/terminal.d.ts +0 -1
- package/dist/notificationfunctions/agent.js +4 -4
- package/dist/notificationfunctions/browser.js +5 -5
- package/dist/notificationfunctions/chat.js +5 -5
- package/dist/notificationfunctions/codeutils.js +5 -5
- package/dist/notificationfunctions/crawler.js +5 -5
- package/dist/notificationfunctions/dbmemory.js +5 -5
- package/dist/notificationfunctions/fs.js +23 -23
- package/dist/notificationfunctions/git.js +25 -25
- package/dist/notificationfunctions/history.js +5 -5
- package/dist/notificationfunctions/llm.js +5 -5
- package/dist/notificationfunctions/mcp.js +9 -9
- package/dist/notificationfunctions/search.js +7 -7
- package/dist/notificationfunctions/system.js +3 -3
- package/dist/notificationfunctions/terminal.js +3 -3
- package/dist/notificationfunctions/todo.js +7 -7
- package/dist/notificationfunctions/utils.js +8 -8
- package/dist/types/InternalTypes.d.ts +0 -3
- package/dist/types/commonTypes.d.ts +2 -2
- package/dist/types/socketMessageTypes.d.ts +0 -2
- package/dist/types/socketMessageTypes.js +6 -7
- package/package.json +20 -26
- package/dist/agentlib/agent.d.ts +0 -86
- package/dist/agentlib/agent.js +0 -326
- package/dist/agentlib/followupquestionbuilder.d.ts +0 -75
- package/dist/agentlib/followupquestionbuilder.js +0 -193
- package/dist/agentlib/llmoutputhandler.d.ts +0 -102
- package/dist/agentlib/llmoutputhandler.js +0 -451
- package/dist/agentlib/promptbuilder.d.ts +0 -382
- package/dist/agentlib/promptbuilder.js +0 -805
- package/dist/agentlib/systemprompt.d.ts +0 -20
- package/dist/agentlib/systemprompt.js +0 -48
- package/dist/agentlib/taskInstruction.d.ts +0 -37
- package/dist/agentlib/taskInstruction.js +0 -57
- package/dist/agentlib/usermessage.d.ts +0 -70
- package/dist/agentlib/usermessage.js +0 -124
- package/dist/utils/docutils.d.ts +0 -9
- package/dist/utils/docutils.js +0 -69
- package/dist/utils/mcpServer.d.ts +0 -481
- package/dist/utils/mcpServer.js +0 -779
- package/dist/utils/parse-source-code/index.d.ts +0 -9
- package/dist/utils/parse-source-code/index.js +0 -233
- package/dist/utils/parse-source-code/languageParser.d.ts +0 -2
- package/dist/utils/parse-source-code/languageParser.js +0 -137
- package/dist/utils/parse-source-code/queries/c-sharp.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/c-sharp.js +0 -25
- package/dist/utils/parse-source-code/queries/c.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/c.js +0 -17
- package/dist/utils/parse-source-code/queries/cpp.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/cpp.js +0 -25
- package/dist/utils/parse-source-code/queries/go.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/go.js +0 -29
- package/dist/utils/parse-source-code/queries/index.d.ts +0 -12
- package/dist/utils/parse-source-code/queries/index.js +0 -30
- package/dist/utils/parse-source-code/queries/java.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/java.js +0 -17
- package/dist/utils/parse-source-code/queries/javascript.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/javascript.js +0 -67
- package/dist/utils/parse-source-code/queries/php.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/php.js +0 -17
- package/dist/utils/parse-source-code/queries/python.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/python.js +0 -13
- package/dist/utils/parse-source-code/queries/ruby.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/ruby.js +0 -54
- package/dist/utils/parse-source-code/queries/rust.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/rust.js +0 -18
- package/dist/utils/parse-source-code/queries/swift.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/swift.js +0 -47
- package/dist/utils/parse-source-code/queries/typescript.d.ts +0 -2
- package/dist/utils/parse-source-code/queries/typescript.js +0 -34
- package/dist/utils/parse-source-code/tree-sitter-c.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-c_sharp.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-cpp.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-go.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-java.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-javascript.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-php.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-python.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-ruby.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-rust.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-swift.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-tsx.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter-typescript.wasm +0 -0
- package/dist/utils/parse-source-code/tree-sitter.wasm +0 -0
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -24
package/dist/utils/mcpServer.js
DELETED
|
@@ -1,779 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
var _FastMCPSession_capabilities, _FastMCPSession_clientCapabilities, _FastMCPSession_loggingLevel, _FastMCPSession_prompts, _FastMCPSession_resources, _FastMCPSession_resourceTemplates, _FastMCPSession_roots, _FastMCPSession_server, _FastMCPSession_auth, _FastMCPSession_pingInterval, _MCPServer_options, _MCPServer_prompts, _MCPServer_resources, _MCPServer_resourcesTemplates, _MCPServer_sessions, _MCPServer_sseServer, _MCPServer_tools, _MCPServer_authenticate;
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.MCPServer = exports.FastMCPSession = exports.UserError = exports.UnexpectedStateError = exports.imageContent = void 0;
|
|
19
|
-
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
20
|
-
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
21
|
-
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
22
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
23
|
-
const zod_1 = require("zod");
|
|
24
|
-
const promises_1 = require("timers/promises");
|
|
25
|
-
const promises_2 = require("fs/promises");
|
|
26
|
-
const events_1 = require("events");
|
|
27
|
-
const fuse_js_1 = __importDefault(require("fuse.js"));
|
|
28
|
-
const uri_templates_1 = __importDefault(require("uri-templates"));
|
|
29
|
-
const undici_1 = require("undici");
|
|
30
|
-
const load_esm_1 = require("load-esm");
|
|
31
|
-
/**
|
|
32
|
-
* Generates an image content object from a URL, file path, or buffer.
|
|
33
|
-
*
|
|
34
|
-
* @param input - The input source for the image (URL, file path, or buffer)
|
|
35
|
-
* @returns Promise with the image content object
|
|
36
|
-
*/
|
|
37
|
-
const imageContent = async (input) => {
|
|
38
|
-
var _a;
|
|
39
|
-
let rawData;
|
|
40
|
-
if ("url" in input) {
|
|
41
|
-
const response = await (0, undici_1.fetch)(input.url);
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
throw new Error(`Failed to fetch image from URL: ${response.statusText}`);
|
|
44
|
-
}
|
|
45
|
-
rawData = Buffer.from(await response.arrayBuffer());
|
|
46
|
-
}
|
|
47
|
-
else if ("path" in input) {
|
|
48
|
-
rawData = await (0, promises_2.readFile)(input.path);
|
|
49
|
-
}
|
|
50
|
-
else if ("buffer" in input) {
|
|
51
|
-
rawData = input.buffer;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
throw new Error("Invalid input: Provide a valid 'url', 'path', or 'buffer'");
|
|
55
|
-
}
|
|
56
|
-
const { fileTypeFromBuffer } = await (0, load_esm_1.loadEsm)('file-type');
|
|
57
|
-
const mimeType = await fileTypeFromBuffer(rawData);
|
|
58
|
-
const base64Data = rawData.toString("base64");
|
|
59
|
-
return {
|
|
60
|
-
type: "image",
|
|
61
|
-
data: base64Data,
|
|
62
|
-
mimeType: (_a = mimeType === null || mimeType === void 0 ? void 0 : mimeType.mime) !== null && _a !== void 0 ? _a : "image/png",
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.imageContent = imageContent;
|
|
66
|
-
/**
|
|
67
|
-
* Base class for FastMCP errors.
|
|
68
|
-
*/
|
|
69
|
-
class FastMCPError extends Error {
|
|
70
|
-
constructor(message) {
|
|
71
|
-
super(message);
|
|
72
|
-
this.name = new.target.name;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Error class for unexpected state conditions.
|
|
77
|
-
*/
|
|
78
|
-
class UnexpectedStateError extends FastMCPError {
|
|
79
|
-
/**
|
|
80
|
-
* Creates a new UnexpectedStateError.
|
|
81
|
-
*
|
|
82
|
-
* @param message - Error message
|
|
83
|
-
* @param extras - Additional context for the error
|
|
84
|
-
*/
|
|
85
|
-
constructor(message, extras) {
|
|
86
|
-
super(message);
|
|
87
|
-
this.name = new.target.name;
|
|
88
|
-
this.extras = extras;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.UnexpectedStateError = UnexpectedStateError;
|
|
92
|
-
/**
|
|
93
|
-
* Error that is meant to be surfaced to the user.
|
|
94
|
-
*/
|
|
95
|
-
class UserError extends UnexpectedStateError {
|
|
96
|
-
}
|
|
97
|
-
exports.UserError = UserError;
|
|
98
|
-
const TextContentZodSchema = zod_1.z
|
|
99
|
-
.object({
|
|
100
|
-
type: zod_1.z.literal("text"),
|
|
101
|
-
/**
|
|
102
|
-
* The text content of the message.
|
|
103
|
-
*/
|
|
104
|
-
text: zod_1.z.string(),
|
|
105
|
-
})
|
|
106
|
-
.strict();
|
|
107
|
-
const ImageContentZodSchema = zod_1.z
|
|
108
|
-
.object({
|
|
109
|
-
type: zod_1.z.literal("image"),
|
|
110
|
-
/**
|
|
111
|
-
* The base64-encoded image data.
|
|
112
|
-
*/
|
|
113
|
-
data: zod_1.z.string().base64(),
|
|
114
|
-
/**
|
|
115
|
-
* The MIME type of the image. Different providers may support different image types.
|
|
116
|
-
*/
|
|
117
|
-
mimeType: zod_1.z.string(),
|
|
118
|
-
})
|
|
119
|
-
.strict();
|
|
120
|
-
const ContentZodSchema = zod_1.z.discriminatedUnion("type", [
|
|
121
|
-
TextContentZodSchema,
|
|
122
|
-
ImageContentZodSchema,
|
|
123
|
-
]);
|
|
124
|
-
const ContentResultZodSchema = zod_1.z
|
|
125
|
-
.object({
|
|
126
|
-
content: ContentZodSchema.array(),
|
|
127
|
-
isError: zod_1.z.boolean().optional(),
|
|
128
|
-
})
|
|
129
|
-
.strict();
|
|
130
|
-
/**
|
|
131
|
-
* Schema for completion results.
|
|
132
|
-
* https://github.com/modelcontextprotocol/typescript-sdk/blob/3164da64d085ec4e022ae881329eee7b72f208d4/src/types.ts#L983-L1003
|
|
133
|
-
*/
|
|
134
|
-
const CompletionZodSchema = zod_1.z.object({
|
|
135
|
-
/**
|
|
136
|
-
* An array of completion values. Must not exceed 100 items.
|
|
137
|
-
*/
|
|
138
|
-
values: zod_1.z.array(zod_1.z.string()).max(100),
|
|
139
|
-
/**
|
|
140
|
-
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
141
|
-
*/
|
|
142
|
-
total: zod_1.z.optional(zod_1.z.number().int()),
|
|
143
|
-
/**
|
|
144
|
-
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
145
|
-
*/
|
|
146
|
-
hasMore: zod_1.z.optional(zod_1.z.boolean()),
|
|
147
|
-
});
|
|
148
|
-
const FastMCPSessionEventEmitterBase = events_1.EventEmitter;
|
|
149
|
-
class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Class representing a FastMCP session.
|
|
153
|
-
* Manages communication between the client and server.
|
|
154
|
-
*/
|
|
155
|
-
class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
156
|
-
/**
|
|
157
|
-
* Creates a new FastMCPSession.
|
|
158
|
-
*
|
|
159
|
-
* @param options - Configuration options for the session
|
|
160
|
-
*/
|
|
161
|
-
constructor({ auth, name, version, tools, resources, resourcesTemplates, prompts, }) {
|
|
162
|
-
super();
|
|
163
|
-
_FastMCPSession_capabilities.set(this, {});
|
|
164
|
-
_FastMCPSession_clientCapabilities.set(this, void 0);
|
|
165
|
-
_FastMCPSession_loggingLevel.set(this, "info");
|
|
166
|
-
_FastMCPSession_prompts.set(this, []);
|
|
167
|
-
_FastMCPSession_resources.set(this, []);
|
|
168
|
-
_FastMCPSession_resourceTemplates.set(this, []);
|
|
169
|
-
_FastMCPSession_roots.set(this, []);
|
|
170
|
-
_FastMCPSession_server.set(this, void 0);
|
|
171
|
-
_FastMCPSession_auth.set(this, void 0);
|
|
172
|
-
_FastMCPSession_pingInterval.set(this, null);
|
|
173
|
-
__classPrivateFieldSet(this, _FastMCPSession_auth, auth, "f");
|
|
174
|
-
if (tools.length) {
|
|
175
|
-
__classPrivateFieldGet(this, _FastMCPSession_capabilities, "f").tools = {};
|
|
176
|
-
}
|
|
177
|
-
if (resources.length || resourcesTemplates.length) {
|
|
178
|
-
__classPrivateFieldGet(this, _FastMCPSession_capabilities, "f").resources = {};
|
|
179
|
-
}
|
|
180
|
-
if (prompts.length) {
|
|
181
|
-
for (const prompt of prompts) {
|
|
182
|
-
this.addPrompt(prompt);
|
|
183
|
-
}
|
|
184
|
-
__classPrivateFieldGet(this, _FastMCPSession_capabilities, "f").prompts = {};
|
|
185
|
-
}
|
|
186
|
-
__classPrivateFieldGet(this, _FastMCPSession_capabilities, "f").logging = {};
|
|
187
|
-
__classPrivateFieldSet(this, _FastMCPSession_server, new index_js_1.Server({ name: name, version: version }, { capabilities: __classPrivateFieldGet(this, _FastMCPSession_capabilities, "f") }), "f");
|
|
188
|
-
this.setupErrorHandling();
|
|
189
|
-
this.setupLoggingHandlers();
|
|
190
|
-
this.setupRootsHandlers();
|
|
191
|
-
this.setupCompleteHandlers();
|
|
192
|
-
if (tools.length) {
|
|
193
|
-
this.setupToolHandlers(tools);
|
|
194
|
-
}
|
|
195
|
-
if (resources.length || resourcesTemplates.length) {
|
|
196
|
-
for (const resource of resources) {
|
|
197
|
-
this.addResource(resource);
|
|
198
|
-
}
|
|
199
|
-
this.setupResourceHandlers(resources);
|
|
200
|
-
if (resourcesTemplates.length) {
|
|
201
|
-
for (const resourceTemplate of resourcesTemplates) {
|
|
202
|
-
this.addResourceTemplate(resourceTemplate);
|
|
203
|
-
}
|
|
204
|
-
this.setupResourceTemplateHandlers(resourcesTemplates);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (prompts.length) {
|
|
208
|
-
this.setupPromptHandlers(prompts);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
addResource(inputResource) {
|
|
212
|
-
__classPrivateFieldGet(this, _FastMCPSession_resources, "f").push(inputResource);
|
|
213
|
-
}
|
|
214
|
-
addResourceTemplate(inputResourceTemplate) {
|
|
215
|
-
var _a;
|
|
216
|
-
const completers = {};
|
|
217
|
-
for (const argument of (_a = inputResourceTemplate.arguments) !== null && _a !== void 0 ? _a : []) {
|
|
218
|
-
if (argument.complete) {
|
|
219
|
-
completers[argument.name] = argument.complete;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const resourceTemplate = {
|
|
223
|
-
...inputResourceTemplate,
|
|
224
|
-
complete: async (name, value) => {
|
|
225
|
-
if (completers[name]) {
|
|
226
|
-
return await completers[name](value);
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
values: [],
|
|
230
|
-
};
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
__classPrivateFieldGet(this, _FastMCPSession_resourceTemplates, "f").push(resourceTemplate);
|
|
234
|
-
}
|
|
235
|
-
addPrompt(inputPrompt) {
|
|
236
|
-
var _a;
|
|
237
|
-
const completers = {};
|
|
238
|
-
const enums = {};
|
|
239
|
-
for (const argument of (_a = inputPrompt.arguments) !== null && _a !== void 0 ? _a : []) {
|
|
240
|
-
if (argument.complete) {
|
|
241
|
-
completers[argument.name] = argument.complete;
|
|
242
|
-
}
|
|
243
|
-
if (argument.enum) {
|
|
244
|
-
enums[argument.name] = argument.enum;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
const prompt = {
|
|
248
|
-
...inputPrompt,
|
|
249
|
-
complete: async (name, value) => {
|
|
250
|
-
if (completers[name]) {
|
|
251
|
-
return await completers[name](value);
|
|
252
|
-
}
|
|
253
|
-
if (enums[name]) {
|
|
254
|
-
const fuse = new fuse_js_1.default(enums[name], {
|
|
255
|
-
keys: ["value"],
|
|
256
|
-
});
|
|
257
|
-
const result = fuse.search(value);
|
|
258
|
-
return {
|
|
259
|
-
values: result.map((item) => item.item),
|
|
260
|
-
total: result.length,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
values: [],
|
|
265
|
-
};
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
__classPrivateFieldGet(this, _FastMCPSession_prompts, "f").push(prompt);
|
|
269
|
-
}
|
|
270
|
-
get clientCapabilities() {
|
|
271
|
-
var _a;
|
|
272
|
-
return (_a = __classPrivateFieldGet(this, _FastMCPSession_clientCapabilities, "f")) !== null && _a !== void 0 ? _a : null;
|
|
273
|
-
}
|
|
274
|
-
get server() {
|
|
275
|
-
return __classPrivateFieldGet(this, _FastMCPSession_server, "f");
|
|
276
|
-
}
|
|
277
|
-
async requestSampling(message) {
|
|
278
|
-
return __classPrivateFieldGet(this, _FastMCPSession_server, "f").createMessage(message);
|
|
279
|
-
}
|
|
280
|
-
async connect(transport) {
|
|
281
|
-
var _a;
|
|
282
|
-
if (__classPrivateFieldGet(this, _FastMCPSession_server, "f").transport) {
|
|
283
|
-
throw new UnexpectedStateError("Server is already connected");
|
|
284
|
-
}
|
|
285
|
-
await __classPrivateFieldGet(this, _FastMCPSession_server, "f").connect(transport);
|
|
286
|
-
let attempt = 0;
|
|
287
|
-
while (attempt++ < 10) {
|
|
288
|
-
const capabilities = await __classPrivateFieldGet(this, _FastMCPSession_server, "f").getClientCapabilities();
|
|
289
|
-
if (capabilities) {
|
|
290
|
-
__classPrivateFieldSet(this, _FastMCPSession_clientCapabilities, capabilities, "f");
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
await (0, promises_1.setTimeout)(100);
|
|
294
|
-
}
|
|
295
|
-
if (!__classPrivateFieldGet(this, _FastMCPSession_clientCapabilities, "f")) {
|
|
296
|
-
// console.warn('[warning] toolBox could not infer client capabilities')
|
|
297
|
-
}
|
|
298
|
-
if ((_a = __classPrivateFieldGet(this, _FastMCPSession_clientCapabilities, "f")) === null || _a === void 0 ? void 0 : _a.roots) {
|
|
299
|
-
const roots = await __classPrivateFieldGet(this, _FastMCPSession_server, "f").listRoots();
|
|
300
|
-
__classPrivateFieldSet(this, _FastMCPSession_roots, roots.roots, "f");
|
|
301
|
-
}
|
|
302
|
-
__classPrivateFieldSet(this, _FastMCPSession_pingInterval, setInterval(async () => {
|
|
303
|
-
try {
|
|
304
|
-
await __classPrivateFieldGet(this, _FastMCPSession_server, "f").ping();
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
this.emit("error", {
|
|
308
|
-
error: error,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}, 1000), "f");
|
|
312
|
-
}
|
|
313
|
-
get roots() {
|
|
314
|
-
return __classPrivateFieldGet(this, _FastMCPSession_roots, "f");
|
|
315
|
-
}
|
|
316
|
-
async close() {
|
|
317
|
-
if (__classPrivateFieldGet(this, _FastMCPSession_pingInterval, "f")) {
|
|
318
|
-
clearInterval(__classPrivateFieldGet(this, _FastMCPSession_pingInterval, "f"));
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
await __classPrivateFieldGet(this, _FastMCPSession_server, "f").close();
|
|
322
|
-
}
|
|
323
|
-
catch (error) {
|
|
324
|
-
console.error("[MCP Error]", "could not close server", error);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
setupErrorHandling() {
|
|
328
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").onerror = (error) => {
|
|
329
|
-
console.error("[MCP Error]", error);
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
get loggingLevel() {
|
|
333
|
-
return __classPrivateFieldGet(this, _FastMCPSession_loggingLevel, "f");
|
|
334
|
-
}
|
|
335
|
-
setupCompleteHandlers() {
|
|
336
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.CompleteRequestSchema, async (request) => {
|
|
337
|
-
if (request.params.ref.type === "ref/prompt") {
|
|
338
|
-
const prompt = __classPrivateFieldGet(this, _FastMCPSession_prompts, "f").find((prompt) => prompt.name === request.params.ref.name);
|
|
339
|
-
if (!prompt) {
|
|
340
|
-
throw new UnexpectedStateError("Unknown prompt", {
|
|
341
|
-
request,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
if (!prompt.complete) {
|
|
345
|
-
throw new UnexpectedStateError("Prompt does not support completion", {
|
|
346
|
-
request,
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
const completion = CompletionZodSchema.parse(await prompt.complete(request.params.argument.name, request.params.argument.value));
|
|
350
|
-
return {
|
|
351
|
-
completion,
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
if (request.params.ref.type === "ref/resource") {
|
|
355
|
-
const resource = __classPrivateFieldGet(this, _FastMCPSession_resourceTemplates, "f").find((resource) => resource.uriTemplate === request.params.ref.uri);
|
|
356
|
-
if (!resource) {
|
|
357
|
-
throw new UnexpectedStateError("Unknown resource", {
|
|
358
|
-
request,
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
if (!("uriTemplate" in resource)) {
|
|
362
|
-
throw new UnexpectedStateError("Unexpected resource");
|
|
363
|
-
}
|
|
364
|
-
if (!resource.complete) {
|
|
365
|
-
throw new UnexpectedStateError("Resource does not support completion", {
|
|
366
|
-
request,
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
const completion = CompletionZodSchema.parse(await resource.complete(request.params.argument.name, request.params.argument.value));
|
|
370
|
-
return {
|
|
371
|
-
completion,
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
throw new UnexpectedStateError("Unexpected completion request", {
|
|
375
|
-
request,
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
setupRootsHandlers() {
|
|
380
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setNotificationHandler(types_js_1.RootsListChangedNotificationSchema, () => {
|
|
381
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").listRoots().then((roots) => {
|
|
382
|
-
__classPrivateFieldSet(this, _FastMCPSession_roots, roots.roots, "f");
|
|
383
|
-
this.emit("rootsChanged", {
|
|
384
|
-
roots: roots.roots,
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
setupLoggingHandlers() {
|
|
390
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.SetLevelRequestSchema, (request) => {
|
|
391
|
-
__classPrivateFieldSet(this, _FastMCPSession_loggingLevel, request.params.level, "f");
|
|
392
|
-
return {};
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
setupToolHandlers(tools) {
|
|
396
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
397
|
-
return {
|
|
398
|
-
tools: tools.map((tool) => {
|
|
399
|
-
return {
|
|
400
|
-
name: tool.name,
|
|
401
|
-
description: tool.description,
|
|
402
|
-
inputSchema: tool.parameters
|
|
403
|
-
? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.parameters)
|
|
404
|
-
: undefined,
|
|
405
|
-
};
|
|
406
|
-
}),
|
|
407
|
-
};
|
|
408
|
-
});
|
|
409
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
410
|
-
var _a, _b;
|
|
411
|
-
const tool = tools.find((tool) => tool.name === request.params.name);
|
|
412
|
-
if (!tool) {
|
|
413
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
|
|
414
|
-
}
|
|
415
|
-
let args = undefined;
|
|
416
|
-
if (tool.parameters) {
|
|
417
|
-
const parsed = tool.parameters.safeParse(request.params.arguments);
|
|
418
|
-
if (!parsed.success) {
|
|
419
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid ${request.params.name} parameters`);
|
|
420
|
-
}
|
|
421
|
-
args = parsed.data;
|
|
422
|
-
}
|
|
423
|
-
const progressToken = (_b = (_a = request.params) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.progressToken;
|
|
424
|
-
let result;
|
|
425
|
-
try {
|
|
426
|
-
const reportProgress = async (progress) => {
|
|
427
|
-
await __classPrivateFieldGet(this, _FastMCPSession_server, "f").notification({
|
|
428
|
-
method: "notifications/progress",
|
|
429
|
-
params: {
|
|
430
|
-
...progress,
|
|
431
|
-
progressToken,
|
|
432
|
-
},
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
const log = {
|
|
436
|
-
debug: (message, context) => {
|
|
437
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").sendLoggingMessage({
|
|
438
|
-
level: "debug",
|
|
439
|
-
data: {
|
|
440
|
-
message,
|
|
441
|
-
context,
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
},
|
|
445
|
-
error: (message, context) => {
|
|
446
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").sendLoggingMessage({
|
|
447
|
-
level: "error",
|
|
448
|
-
data: {
|
|
449
|
-
message,
|
|
450
|
-
context,
|
|
451
|
-
},
|
|
452
|
-
});
|
|
453
|
-
},
|
|
454
|
-
info: (message, context) => {
|
|
455
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").sendLoggingMessage({
|
|
456
|
-
level: "info",
|
|
457
|
-
data: {
|
|
458
|
-
message,
|
|
459
|
-
context,
|
|
460
|
-
},
|
|
461
|
-
});
|
|
462
|
-
},
|
|
463
|
-
warn: (message, context) => {
|
|
464
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").sendLoggingMessage({
|
|
465
|
-
level: "warning",
|
|
466
|
-
data: {
|
|
467
|
-
message,
|
|
468
|
-
context,
|
|
469
|
-
},
|
|
470
|
-
});
|
|
471
|
-
},
|
|
472
|
-
};
|
|
473
|
-
const maybeStringResult = await tool.execute(args, {
|
|
474
|
-
reportProgress,
|
|
475
|
-
log,
|
|
476
|
-
session: __classPrivateFieldGet(this, _FastMCPSession_auth, "f"),
|
|
477
|
-
});
|
|
478
|
-
if (typeof maybeStringResult === "string") {
|
|
479
|
-
result = ContentResultZodSchema.parse({
|
|
480
|
-
content: [{ type: "text", text: maybeStringResult }],
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
else if ("type" in maybeStringResult) {
|
|
484
|
-
result = ContentResultZodSchema.parse({
|
|
485
|
-
content: [maybeStringResult],
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
result = ContentResultZodSchema.parse(maybeStringResult);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
catch (error) {
|
|
493
|
-
if (error instanceof UserError) {
|
|
494
|
-
return {
|
|
495
|
-
content: [{ type: "text", text: error.message }],
|
|
496
|
-
isError: true,
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
content: [{ type: "text", text: `Error: ${error}` }],
|
|
501
|
-
isError: true,
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
return result;
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
setupResourceHandlers(resources) {
|
|
508
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
|
|
509
|
-
return {
|
|
510
|
-
resources: resources.map((resource) => {
|
|
511
|
-
return {
|
|
512
|
-
uri: resource.uri,
|
|
513
|
-
name: resource.name,
|
|
514
|
-
mimeType: resource.mimeType,
|
|
515
|
-
};
|
|
516
|
-
}),
|
|
517
|
-
};
|
|
518
|
-
});
|
|
519
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
|
|
520
|
-
if ("uri" in request.params) {
|
|
521
|
-
const resource = resources.find((resource) => "uri" in resource && resource.uri === request.params.uri);
|
|
522
|
-
if (!resource) {
|
|
523
|
-
for (const resourceTemplate of __classPrivateFieldGet(this, _FastMCPSession_resourceTemplates, "f")) {
|
|
524
|
-
const uriTemplate = (0, uri_templates_1.default)(resourceTemplate.uriTemplate);
|
|
525
|
-
const match = uriTemplate.fromUri(request.params.uri);
|
|
526
|
-
if (!match) {
|
|
527
|
-
continue;
|
|
528
|
-
}
|
|
529
|
-
const uri = uriTemplate.fill(match);
|
|
530
|
-
const result = await resourceTemplate.load(match);
|
|
531
|
-
return {
|
|
532
|
-
contents: [
|
|
533
|
-
{
|
|
534
|
-
uri: uri,
|
|
535
|
-
mimeType: resourceTemplate.mimeType,
|
|
536
|
-
name: resourceTemplate.name,
|
|
537
|
-
...result,
|
|
538
|
-
},
|
|
539
|
-
],
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown resource: ${request.params.uri}`);
|
|
543
|
-
}
|
|
544
|
-
if (!("uri" in resource)) {
|
|
545
|
-
throw new UnexpectedStateError("Resource does not support reading");
|
|
546
|
-
}
|
|
547
|
-
let maybeArrayResult;
|
|
548
|
-
try {
|
|
549
|
-
maybeArrayResult = await resource.load();
|
|
550
|
-
}
|
|
551
|
-
catch (error) {
|
|
552
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Error reading resource: ${error}`, {
|
|
553
|
-
uri: resource.uri,
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
if (Array.isArray(maybeArrayResult)) {
|
|
557
|
-
return {
|
|
558
|
-
contents: maybeArrayResult.map((result) => ({
|
|
559
|
-
uri: resource.uri,
|
|
560
|
-
mimeType: resource.mimeType,
|
|
561
|
-
name: resource.name,
|
|
562
|
-
...result,
|
|
563
|
-
})),
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
return {
|
|
568
|
-
contents: [
|
|
569
|
-
{
|
|
570
|
-
uri: resource.uri,
|
|
571
|
-
mimeType: resource.mimeType,
|
|
572
|
-
name: resource.name,
|
|
573
|
-
...maybeArrayResult,
|
|
574
|
-
},
|
|
575
|
-
],
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
throw new UnexpectedStateError("Unknown resource request", {
|
|
580
|
-
request,
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
setupResourceTemplateHandlers(resourceTemplates) {
|
|
585
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.ListResourceTemplatesRequestSchema, async () => {
|
|
586
|
-
return {
|
|
587
|
-
resourceTemplates: resourceTemplates.map((resourceTemplate) => {
|
|
588
|
-
return {
|
|
589
|
-
name: resourceTemplate.name,
|
|
590
|
-
uriTemplate: resourceTemplate.uriTemplate,
|
|
591
|
-
};
|
|
592
|
-
}),
|
|
593
|
-
};
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
setupPromptHandlers(prompts) {
|
|
597
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.ListPromptsRequestSchema, async () => {
|
|
598
|
-
return {
|
|
599
|
-
prompts: prompts.map((prompt) => {
|
|
600
|
-
return {
|
|
601
|
-
name: prompt.name,
|
|
602
|
-
description: prompt.description,
|
|
603
|
-
arguments: prompt.arguments,
|
|
604
|
-
complete: prompt.complete,
|
|
605
|
-
};
|
|
606
|
-
}),
|
|
607
|
-
};
|
|
608
|
-
});
|
|
609
|
-
__classPrivateFieldGet(this, _FastMCPSession_server, "f").setRequestHandler(types_js_1.GetPromptRequestSchema, async (request) => {
|
|
610
|
-
var _a;
|
|
611
|
-
const prompt = prompts.find((prompt) => prompt.name === request.params.name);
|
|
612
|
-
if (!prompt) {
|
|
613
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown prompt: ${request.params.name}`);
|
|
614
|
-
}
|
|
615
|
-
const args = request.params.arguments;
|
|
616
|
-
for (const arg of (_a = prompt.arguments) !== null && _a !== void 0 ? _a : []) {
|
|
617
|
-
if (arg.required && !(args && arg.name in args)) {
|
|
618
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Missing required argument: ${arg.name}`);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
let result;
|
|
622
|
-
try {
|
|
623
|
-
result = await prompt.load(args);
|
|
624
|
-
}
|
|
625
|
-
catch (error) {
|
|
626
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Error loading prompt: ${error}`);
|
|
627
|
-
}
|
|
628
|
-
return {
|
|
629
|
-
description: prompt.description,
|
|
630
|
-
messages: [
|
|
631
|
-
{
|
|
632
|
-
role: "user",
|
|
633
|
-
content: { type: "text", text: result },
|
|
634
|
-
},
|
|
635
|
-
],
|
|
636
|
-
};
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
exports.FastMCPSession = FastMCPSession;
|
|
641
|
-
_FastMCPSession_capabilities = new WeakMap(), _FastMCPSession_clientCapabilities = new WeakMap(), _FastMCPSession_loggingLevel = new WeakMap(), _FastMCPSession_prompts = new WeakMap(), _FastMCPSession_resources = new WeakMap(), _FastMCPSession_resourceTemplates = new WeakMap(), _FastMCPSession_roots = new WeakMap(), _FastMCPSession_server = new WeakMap(), _FastMCPSession_auth = new WeakMap(), _FastMCPSession_pingInterval = new WeakMap();
|
|
642
|
-
const FastMCPEventEmitterBase = events_1.EventEmitter;
|
|
643
|
-
class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Class representing a toolbox for FastMCP.
|
|
647
|
-
* Manages tools, resources, and prompts for a Model Context Protocol server.
|
|
648
|
-
*/
|
|
649
|
-
class MCPServer extends FastMCPEventEmitter {
|
|
650
|
-
/**
|
|
651
|
-
* Creates a new ToolBox instance.
|
|
652
|
-
*
|
|
653
|
-
* @param options - Configuration options for the toolbox
|
|
654
|
-
*/
|
|
655
|
-
constructor(options) {
|
|
656
|
-
super();
|
|
657
|
-
this.options = options;
|
|
658
|
-
_MCPServer_options.set(this, void 0);
|
|
659
|
-
_MCPServer_prompts.set(this, []);
|
|
660
|
-
_MCPServer_resources.set(this, []);
|
|
661
|
-
_MCPServer_resourcesTemplates.set(this, []);
|
|
662
|
-
_MCPServer_sessions.set(this, []);
|
|
663
|
-
_MCPServer_sseServer.set(this, null);
|
|
664
|
-
_MCPServer_tools.set(this, []);
|
|
665
|
-
_MCPServer_authenticate.set(this, void 0);
|
|
666
|
-
__classPrivateFieldSet(this, _MCPServer_options, options, "f");
|
|
667
|
-
__classPrivateFieldSet(this, _MCPServer_authenticate, options.authenticate, "f");
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* Gets all active sessions.
|
|
671
|
-
*/
|
|
672
|
-
get sessions() {
|
|
673
|
-
return __classPrivateFieldGet(this, _MCPServer_sessions, "f");
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Adds a tool to the server.
|
|
677
|
-
*
|
|
678
|
-
* @param tool - The tool to add
|
|
679
|
-
*/
|
|
680
|
-
addTool(tool) {
|
|
681
|
-
__classPrivateFieldGet(this, _MCPServer_tools, "f").push(tool);
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Adds a resource to the server.
|
|
685
|
-
*
|
|
686
|
-
* @param resource - The resource to add
|
|
687
|
-
*/
|
|
688
|
-
addResource(resource) {
|
|
689
|
-
__classPrivateFieldGet(this, _MCPServer_resources, "f").push(resource);
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Adds a resource template to the server.
|
|
693
|
-
*
|
|
694
|
-
* @param resource - The resource template to add
|
|
695
|
-
*/
|
|
696
|
-
addResourceTemplate(resource) {
|
|
697
|
-
__classPrivateFieldGet(this, _MCPServer_resourcesTemplates, "f").push(resource);
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Adds a prompt to the server.
|
|
701
|
-
*
|
|
702
|
-
* @param prompt - The prompt to add
|
|
703
|
-
*/
|
|
704
|
-
addPrompt(prompt) {
|
|
705
|
-
__classPrivateFieldGet(this, _MCPServer_prompts, "f").push(prompt);
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Starts the server.
|
|
709
|
-
*
|
|
710
|
-
* @param options - Options for the server transport
|
|
711
|
-
*/
|
|
712
|
-
async start(options = {
|
|
713
|
-
transportType: "stdio",
|
|
714
|
-
}) {
|
|
715
|
-
if (options.transportType === "stdio") {
|
|
716
|
-
const transport = new stdio_js_1.StdioServerTransport();
|
|
717
|
-
const session = new FastMCPSession({
|
|
718
|
-
name: __classPrivateFieldGet(this, _MCPServer_options, "f").name,
|
|
719
|
-
version: __classPrivateFieldGet(this, _MCPServer_options, "f").version,
|
|
720
|
-
tools: __classPrivateFieldGet(this, _MCPServer_tools, "f"),
|
|
721
|
-
resources: __classPrivateFieldGet(this, _MCPServer_resources, "f"),
|
|
722
|
-
resourcesTemplates: __classPrivateFieldGet(this, _MCPServer_resourcesTemplates, "f"),
|
|
723
|
-
prompts: __classPrivateFieldGet(this, _MCPServer_prompts, "f"),
|
|
724
|
-
});
|
|
725
|
-
await session.connect(transport);
|
|
726
|
-
__classPrivateFieldGet(this, _MCPServer_sessions, "f").push(session);
|
|
727
|
-
this.emit("connect", {
|
|
728
|
-
session,
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
else if (options.transportType === "sse") {
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
throw new Error("Invalid transport type");
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Stops the server.
|
|
739
|
-
*/
|
|
740
|
-
async stop() {
|
|
741
|
-
if (__classPrivateFieldGet(this, _MCPServer_sseServer, "f")) {
|
|
742
|
-
__classPrivateFieldGet(this, _MCPServer_sseServer, "f").close();
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Activates the server.
|
|
747
|
-
*
|
|
748
|
-
* @param options - Options for the server transport
|
|
749
|
-
*/
|
|
750
|
-
async activate(options = {
|
|
751
|
-
transportType: "stdio",
|
|
752
|
-
}) {
|
|
753
|
-
if (options.transportType === "stdio") {
|
|
754
|
-
const transport = new stdio_js_1.StdioServerTransport();
|
|
755
|
-
const session = new FastMCPSession({
|
|
756
|
-
name: __classPrivateFieldGet(this, _MCPServer_options, "f").name,
|
|
757
|
-
version: __classPrivateFieldGet(this, _MCPServer_options, "f").version,
|
|
758
|
-
tools: __classPrivateFieldGet(this, _MCPServer_tools, "f"),
|
|
759
|
-
resources: __classPrivateFieldGet(this, _MCPServer_resources, "f"),
|
|
760
|
-
resourcesTemplates: __classPrivateFieldGet(this, _MCPServer_resourcesTemplates, "f"),
|
|
761
|
-
prompts: __classPrivateFieldGet(this, _MCPServer_prompts, "f"),
|
|
762
|
-
});
|
|
763
|
-
await session.connect(transport);
|
|
764
|
-
__classPrivateFieldGet(this, _MCPServer_sessions, "f").push(session);
|
|
765
|
-
this.emit("connect", {
|
|
766
|
-
session,
|
|
767
|
-
});
|
|
768
|
-
console.info(`server is running on stdio`);
|
|
769
|
-
}
|
|
770
|
-
else if (options.transportType === "sse") {
|
|
771
|
-
// Implementation for SSE transport
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
throw new Error("Invalid transport type");
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
exports.MCPServer = MCPServer;
|
|
779
|
-
_MCPServer_options = new WeakMap(), _MCPServer_prompts = new WeakMap(), _MCPServer_resources = new WeakMap(), _MCPServer_resourcesTemplates = new WeakMap(), _MCPServer_sessions = new WeakMap(), _MCPServer_sseServer = new WeakMap(), _MCPServer_tools = new WeakMap(), _MCPServer_authenticate = new WeakMap();
|