@mozaik-ai/core 3.13.1 → 3.14.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/README.md +2 -2
- package/dist/index.d.mts +81 -16
- package/dist/index.d.ts +81 -16
- package/dist/index.js +111 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -4
package/dist/index.mjs
CHANGED
|
@@ -204,6 +204,98 @@ var TokenUsage = class {
|
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
+
// src/infrastructure/mcp/mcp-client.ts
|
|
208
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
209
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
210
|
+
var McpClient = class {
|
|
211
|
+
constructor(config) {
|
|
212
|
+
this.config = config;
|
|
213
|
+
this.connected = false;
|
|
214
|
+
var _a, _b;
|
|
215
|
+
const headers = { ...(_a = config.headers) != null ? _a : {} };
|
|
216
|
+
if (config.authToken) headers.Authorization = `Bearer ${config.authToken}`;
|
|
217
|
+
this.transport = new StreamableHTTPClientTransport(
|
|
218
|
+
new URL(config.url),
|
|
219
|
+
Object.keys(headers).length > 0 ? { requestInit: { headers } } : void 0
|
|
220
|
+
);
|
|
221
|
+
this.client = new Client({ name: (_b = config.name) != null ? _b : "mozaik", version: "1.0.0" }, { capabilities: {} });
|
|
222
|
+
}
|
|
223
|
+
async connect() {
|
|
224
|
+
if (this.connected) return;
|
|
225
|
+
await this.client.connect(this.transport);
|
|
226
|
+
this.connected = true;
|
|
227
|
+
}
|
|
228
|
+
/** The tools this server exposes. */
|
|
229
|
+
async listTools() {
|
|
230
|
+
var _a;
|
|
231
|
+
await this.connect();
|
|
232
|
+
const res = await this.client.listTools();
|
|
233
|
+
return ((_a = res.tools) != null ? _a : []).map((t) => {
|
|
234
|
+
var _a2, _b;
|
|
235
|
+
return {
|
|
236
|
+
name: t.name,
|
|
237
|
+
description: (_a2 = t.description) != null ? _a2 : "",
|
|
238
|
+
inputSchema: (_b = t.inputSchema) != null ? _b : { type: "object", properties: {} }
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/** Call a tool by name; returns its text output. Throws if the server flags an error. */
|
|
243
|
+
async callTool(name, args) {
|
|
244
|
+
await this.connect();
|
|
245
|
+
const res = await this.client.callTool({ name, arguments: args != null ? args : {} });
|
|
246
|
+
const text = extractText(res);
|
|
247
|
+
if (res.isError) {
|
|
248
|
+
throw new Error(`MCP tool "${name}" failed: ${text || "unknown error"}`);
|
|
249
|
+
}
|
|
250
|
+
return text;
|
|
251
|
+
}
|
|
252
|
+
async close() {
|
|
253
|
+
if (!this.connected) return;
|
|
254
|
+
try {
|
|
255
|
+
await this.client.close();
|
|
256
|
+
} catch (e) {
|
|
257
|
+
}
|
|
258
|
+
this.connected = false;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
function extractText(res) {
|
|
262
|
+
const content = res.content;
|
|
263
|
+
if (!Array.isArray(content)) return "";
|
|
264
|
+
return content.filter((c) => (c == null ? void 0 : c.type) === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/infrastructure/mcp/mcp-tool-registry.ts
|
|
268
|
+
var McpToolRegistry = class {
|
|
269
|
+
constructor(servers, createClient = (config) => new McpClient(config)) {
|
|
270
|
+
this.servers = servers;
|
|
271
|
+
this.createClient = createClient;
|
|
272
|
+
this.clients = [];
|
|
273
|
+
}
|
|
274
|
+
/** Discover every tool across the configured servers, as FunctionTools ready to pass to a model. */
|
|
275
|
+
async discoverTools() {
|
|
276
|
+
const tools = [];
|
|
277
|
+
for (const server of this.servers) {
|
|
278
|
+
const client = this.createClient(server);
|
|
279
|
+
this.clients.push(client);
|
|
280
|
+
for (const spec of await client.listTools()) {
|
|
281
|
+
tools.push({
|
|
282
|
+
type: "function",
|
|
283
|
+
name: spec.name,
|
|
284
|
+
description: spec.description,
|
|
285
|
+
parameters: spec.inputSchema,
|
|
286
|
+
strict: false,
|
|
287
|
+
invoke: (args) => client.callTool(spec.name, args != null ? args : {})
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return tools;
|
|
292
|
+
}
|
|
293
|
+
/** Close all underlying MCP connections. */
|
|
294
|
+
async close() {
|
|
295
|
+
await Promise.all(this.clients.map((c) => c.close()));
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
207
299
|
// src/infrastructure/repository/in-memory-model-context-repository.ts
|
|
208
300
|
var InMemoryModelContextRepository = class {
|
|
209
301
|
constructor() {
|
|
@@ -566,39 +658,39 @@ var FunctionCallRunner = class {
|
|
|
566
658
|
|
|
567
659
|
// src/application/participants/participant.ts
|
|
568
660
|
var BaseParticipant = class extends Participant {
|
|
569
|
-
onFunctionCall(
|
|
661
|
+
onFunctionCall(_item) {
|
|
570
662
|
}
|
|
571
|
-
onExternalFunctionCall(
|
|
663
|
+
onExternalFunctionCall(_source, _item) {
|
|
572
664
|
}
|
|
573
|
-
onFunctionCallOutput(
|
|
665
|
+
onFunctionCallOutput(_item) {
|
|
574
666
|
}
|
|
575
|
-
onExternalFunctionCallOutput(
|
|
667
|
+
onExternalFunctionCallOutput(_source, _item) {
|
|
576
668
|
}
|
|
577
|
-
onReasoning(
|
|
669
|
+
onReasoning(_item) {
|
|
578
670
|
}
|
|
579
|
-
onExternalReasoning(
|
|
671
|
+
onExternalReasoning(_source, _item) {
|
|
580
672
|
}
|
|
581
|
-
onModelMessage(
|
|
673
|
+
onModelMessage(_item) {
|
|
582
674
|
}
|
|
583
|
-
onExternalModelMessage(
|
|
675
|
+
onExternalModelMessage(_source, _item) {
|
|
584
676
|
}
|
|
585
|
-
onMessage(
|
|
677
|
+
onMessage(_message) {
|
|
586
678
|
}
|
|
587
679
|
onJoined() {
|
|
588
680
|
}
|
|
589
681
|
onLeft() {
|
|
590
682
|
}
|
|
591
|
-
onParticipantJoined(
|
|
683
|
+
onParticipantJoined(_participant) {
|
|
592
684
|
}
|
|
593
|
-
onParticipantLeft(
|
|
685
|
+
onParticipantLeft(_participant) {
|
|
594
686
|
}
|
|
595
|
-
onInternalEvent(
|
|
687
|
+
onInternalEvent(_item) {
|
|
596
688
|
}
|
|
597
|
-
onExternalEvent(
|
|
689
|
+
onExternalEvent(_source, _item) {
|
|
598
690
|
}
|
|
599
|
-
onError(
|
|
691
|
+
onError(_error) {
|
|
600
692
|
}
|
|
601
|
-
onParticipantError(
|
|
693
|
+
onParticipantError(_source, _error) {
|
|
602
694
|
}
|
|
603
695
|
};
|
|
604
696
|
|
|
@@ -1758,6 +1850,8 @@ export {
|
|
|
1758
1850
|
InMemoryModelContextRepository,
|
|
1759
1851
|
InferenceResponse,
|
|
1760
1852
|
InputTokenDetails,
|
|
1853
|
+
McpClient,
|
|
1854
|
+
McpToolRegistry,
|
|
1761
1855
|
ModelContext,
|
|
1762
1856
|
ModelMessageItem,
|
|
1763
1857
|
OutputTokenDetails,
|