@burtson-labs/bandit-engine 2.0.74 → 2.0.75

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.
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  chat_default
3
- } from "./chunk-YBQRVTZF.mjs";
3
+ } from "./chunk-BEXIQYMG.mjs";
4
4
  import "./chunk-ONQMRE2G.mjs";
5
5
  import "./chunk-U633CJBV.mjs";
6
- import "./chunk-DHYP4K5O.mjs";
6
+ import "./chunk-3LT77723.mjs";
7
7
  import "./chunk-6DY7W4NK.mjs";
8
8
  import "./chunk-4D7245ZO.mjs";
9
9
  import "./chunk-LWHSOEPR.mjs";
@@ -13,4 +13,4 @@ import "./chunk-BJTO5JO5.mjs";
13
13
  export {
14
14
  chat_default as default
15
15
  };
16
- //# sourceMappingURL=chat-W4HX45DE.mjs.map
16
+ //# sourceMappingURL=chat-S35XO43Z.mjs.map
@@ -6553,6 +6553,35 @@ var useKnowledgeStore = (0, import_zustand10.create)((set, get) => ({
6553
6553
  var import_zustand11 = require("zustand");
6554
6554
  init_indexedDBService();
6555
6555
  init_debugLogger();
6556
+
6557
+ // src/services/mcp/mcpServersService.ts
6558
+ init_packageSettingsStore();
6559
+ var gatewayBase = () => {
6560
+ const settings = usePackageSettingsStore.getState().settings;
6561
+ const url = settings?.gatewayApiUrl?.replace(/\/$/, "");
6562
+ if (!url) throw new Error("Gateway API is not configured.");
6563
+ return url;
6564
+ };
6565
+ var authHeaders = () => {
6566
+ const headers = { "Content-Type": "application/json" };
6567
+ const token = authenticationService.getToken();
6568
+ if (token) headers["Authorization"] = `Bearer ${token}`;
6569
+ return headers;
6570
+ };
6571
+ var parse = async (res) => {
6572
+ const text = await res.text();
6573
+ const body = text ? JSON.parse(text) : null;
6574
+ if (!res.ok) {
6575
+ const message = body && typeof body === "object" && (body.error || body.message) || `Request failed (${res.status})`;
6576
+ throw new Error(String(message));
6577
+ }
6578
+ return body;
6579
+ };
6580
+ var listMcpServers = async () => parse(await fetch(`${gatewayBase()}/mcp/servers`, { headers: authHeaders() }));
6581
+ var discoverMcpTools = async (id) => parse(await fetch(`${gatewayBase()}/mcp/servers/${encodeURIComponent(id)}/tools`, { headers: authHeaders() }));
6582
+
6583
+ // src/store/mcpToolsStore.ts
6584
+ var sanitizeMcpToolName = (raw) => raw.replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").slice(0, 60);
6556
6585
  var healthCheckTool = {
6557
6586
  id: "health-check",
6558
6587
  name: "check_gateway_health",
@@ -6739,7 +6768,7 @@ var useMCPToolsStore = (0, import_zustand11.create)((set, get) => ({
6739
6768
  try {
6740
6769
  const { tools } = get();
6741
6770
  const storeConfigs6 = [{ name: "config", keyPath: "id" }];
6742
- const customTools = tools.filter((tool) => !tool.isBuiltIn);
6771
+ const customTools = tools.filter((tool) => !tool.isBuiltIn && !tool.mcpServerId);
6743
6772
  await indexedDBService_default.put("banditConfig", 1, "config", {
6744
6773
  id: "mcpTools",
6745
6774
  tools: customTools
@@ -6748,6 +6777,48 @@ var useMCPToolsStore = (0, import_zustand11.create)((set, get) => ({
6748
6777
  } catch (error) {
6749
6778
  debugLogger.error("Failed to save MCP tools to IndexedDB", { error });
6750
6779
  }
6780
+ },
6781
+ // Discover the user's connected MCP servers' tools from the gateway and merge
6782
+ // them into the tool list (so the model can call them). Replaces any prior
6783
+ // MCP-server tools; best-effort — a single unreachable server is skipped.
6784
+ loadMcpServerTools: async () => {
6785
+ let servers;
6786
+ try {
6787
+ servers = await listMcpServers();
6788
+ } catch (error) {
6789
+ debugLogger.warn("Could not list MCP servers", { error: String(error) });
6790
+ return;
6791
+ }
6792
+ const collected = [];
6793
+ for (const server of servers.filter((s) => s.enabled)) {
6794
+ try {
6795
+ const { tools } = await discoverMcpTools(server.id);
6796
+ for (const t of tools) {
6797
+ const fnName = sanitizeMcpToolName(`mcp_${server.name}_${t.name}`);
6798
+ const schema = t.inputSchema && typeof t.inputSchema === "object" && t.inputSchema.type === "object" ? t.inputSchema : { type: "object", properties: {}, required: [] };
6799
+ collected.push({
6800
+ id: `mcp-${server.id}-${t.name}`,
6801
+ name: fnName,
6802
+ description: t.description || `${t.name} (via ${server.name})`,
6803
+ enabled: true,
6804
+ type: "function",
6805
+ function: {
6806
+ name: fnName,
6807
+ description: t.description || `${t.name} \u2014 provided by the ${server.name} MCP server.`,
6808
+ parameters: schema
6809
+ },
6810
+ mcpServerId: server.id,
6811
+ mcpToolName: t.name
6812
+ });
6813
+ }
6814
+ } catch (error) {
6815
+ debugLogger.warn("Failed to discover tools for MCP server", { server: server.name, error: String(error) });
6816
+ }
6817
+ }
6818
+ set((state) => ({
6819
+ tools: [...state.tools.filter((t) => !t.mcpServerId), ...collected]
6820
+ }));
6821
+ debugLogger.info("MCP server tools loaded", { count: collected.length });
6751
6822
  }
6752
6823
  }));
6753
6824
 
@@ -10472,6 +10543,7 @@ var ChatProvider = (props) => {
10472
10543
  await usePreferencesStore.getState().loadPreferences();
10473
10544
  await useKnowledgeStore.getState().loadDocs();
10474
10545
  await useMCPToolsStore.getState().loadTools();
10546
+ void useMCPToolsStore.getState().loadMcpServerTools();
10475
10547
  await useConversationSyncStore.getState().initialize();
10476
10548
  }
10477
10549
  debugLogger.info("ChatProvider about to call initModels - checking for existing branding first");