@flutchai/flutch-sdk 0.4.0 → 0.5.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/index.cjs CHANGED
@@ -4489,7 +4489,8 @@ async function executeToolWithAttachments(params) {
4489
4489
  injectIntoArg = "data",
4490
4490
  sourceAttachmentId,
4491
4491
  threadId,
4492
- toolSchema
4492
+ toolSchema,
4493
+ mcpServers
4493
4494
  } = params;
4494
4495
  const argsWithInjection = { ...enrichedArgs };
4495
4496
  try {
@@ -4520,7 +4521,8 @@ async function executeToolWithAttachments(params) {
4520
4521
  toolCall.name,
4521
4522
  argsWithInjection,
4522
4523
  executionContext,
4523
- config
4524
+ config,
4525
+ mcpServers
4524
4526
  );
4525
4527
  try {
4526
4528
  if (success && rawResult !== void 0 && content.length > threshold) {
@@ -5316,9 +5318,7 @@ var HEADER_MAP = {
5316
5318
  threadId: "x-flutch-thread-id",
5317
5319
  agentId: "x-flutch-agent-id",
5318
5320
  userId: "x-flutch-user-id",
5319
- nodeName: "x-flutch-node",
5320
- companyId: "x-flutch-company-id",
5321
- accountId: "x-flutch-account-id"
5321
+ nodeName: "x-flutch-node"
5322
5322
  };
5323
5323
  var INTERNAL_TOKEN_HEADER = "x-flutch-internal-token";
5324
5324
  function isInternalMode() {
@@ -6382,12 +6382,13 @@ var McpToolFilter = class _McpToolFilter {
6382
6382
  * @param toolsConfig Array of tool configurations with dynamic config
6383
6383
  * @returns Array of LangChain Tool instances with dynamic schemas
6384
6384
  */
6385
- async getFilteredTools(toolsConfig = []) {
6385
+ async getFilteredTools(toolsConfig = [], mcpServers, context) {
6386
6386
  this.logger.debug(
6387
6387
  `[DEBUG] Getting filtered tools with dynamic schemas. Config: ${JSON.stringify(toolsConfig)}`
6388
6388
  );
6389
6389
  this.logger.debug(`[DEBUG] MCP Runtime URL: ${this.mcpRuntimeUrl}`);
6390
- if (toolsConfig.length === 0) {
6390
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
6391
+ if (toolsConfig.length === 0 && !hasInlineServers) {
6391
6392
  this.logger.debug("No tools configured, returning empty array");
6392
6393
  return [];
6393
6394
  }
@@ -6395,10 +6396,13 @@ var McpToolFilter = class _McpToolFilter {
6395
6396
  this.logger.debug(
6396
6397
  `[DEBUG] Making HTTP POST request to: ${this.mcpRuntimeUrl}/tools/schemas`
6397
6398
  );
6398
- this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(toolsConfig)}`);
6399
+ const requestBody = { tools: toolsConfig };
6400
+ if (hasInlineServers) requestBody.mcpServers = mcpServers;
6401
+ if (context) requestBody.context = context;
6402
+ this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(requestBody)}`);
6399
6403
  const response = await axios2__default.default.post(
6400
6404
  `${this.mcpRuntimeUrl}/tools/schemas`,
6401
- { tools: toolsConfig },
6405
+ requestBody,
6402
6406
  {
6403
6407
  timeout: 5e3,
6404
6408
  headers: {
@@ -6415,14 +6419,14 @@ var McpToolFilter = class _McpToolFilter {
6415
6419
  );
6416
6420
  const mcpClient = {
6417
6421
  getTools: async () => dynamicTools,
6418
- executeTool: async (name, args, context) => {
6422
+ executeTool: async (name, args, context2) => {
6419
6423
  this.logger.debug(`[DEBUG] Executing tool ${name} with args:`, args);
6420
6424
  const response2 = await axios2__default.default.post(
6421
6425
  `${this.mcpRuntimeUrl}/tools/execute`,
6422
6426
  {
6423
6427
  name,
6424
6428
  arguments: args || {},
6425
- context
6429
+ context: context2
6426
6430
  }
6427
6431
  );
6428
6432
  return response2.data;
@@ -6561,7 +6565,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6561
6565
  /**
6562
6566
  * Execute a tool by name with given arguments
6563
6567
  */
6564
- async executeTool(name, args, context) {
6568
+ async executeTool(name, args, context, mcpServers) {
6565
6569
  try {
6566
6570
  this.logger.debug(`Executing tool: ${name} with args:`, args);
6567
6571
  const payload = {
@@ -6571,6 +6575,9 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6571
6575
  if (context) {
6572
6576
  payload.context = context;
6573
6577
  }
6578
+ if (mcpServers && mcpServers.length > 0) {
6579
+ payload.mcpServers = mcpServers;
6580
+ }
6574
6581
  const response = await this.httpClient.post("/tools/execute", payload);
6575
6582
  this.logger.log(`Tool ${name} executed successfully`);
6576
6583
  return response.data;
@@ -6621,7 +6628,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6621
6628
  * @param config - RunnableConfig with callbacks
6622
6629
  * @returns Tool execution result with content
6623
6630
  */
6624
- async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config) {
6631
+ async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config, mcpServers) {
6625
6632
  const parsedConfig = manager.parseCallbackConfigArg(config);
6626
6633
  const callbackManager = manager.CallbackManager.configure(parsedConfig.callbacks);
6627
6634
  let runManager;
@@ -6643,7 +6650,8 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6643
6650
  const result = await this.executeTool(
6644
6651
  toolName,
6645
6652
  enrichedArgs,
6646
- executionContext
6653
+ executionContext,
6654
+ mcpServers
6647
6655
  );
6648
6656
  const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
6649
6657
  await runManager?.handleToolEnd(content);
@@ -6852,13 +6860,17 @@ var ModelInitializer = class _ModelInitializer {
6852
6860
  * Example: "model123:0.7:4096" or "model123:0.7:4096:a1b2c3d4e5f6g7h8"
6853
6861
  */
6854
6862
  generateModelCacheKey(config) {
6855
- return generateModelCacheKey(
6863
+ const base = generateModelCacheKey(
6856
6864
  config.modelId,
6857
6865
  config.temperature,
6858
6866
  config.maxTokens,
6859
6867
  config.toolsConfig,
6860
6868
  config.baseURL
6861
6869
  );
6870
+ if (config.mcpServers && config.mcpServers.length > 0) {
6871
+ return `${base}:mcp:${JSON.stringify(config.mcpServers)}`;
6872
+ }
6873
+ return base;
6862
6874
  }
6863
6875
  // Chat model creators
6864
6876
  chatModelCreators = {
@@ -7134,11 +7146,13 @@ var ModelInitializer = class _ModelInitializer {
7134
7146
  ...model.metadata,
7135
7147
  modelId: config.modelId
7136
7148
  };
7137
- if (config.toolsConfig || config.customTools) {
7149
+ if (config.toolsConfig || config.customTools || config.mcpServers && config.mcpServers.length > 0) {
7138
7150
  const boundModel = await this.bindToolsToModel(
7139
7151
  model,
7140
7152
  config.toolsConfig,
7141
- config.customTools
7153
+ config.customTools,
7154
+ config.mcpServers,
7155
+ config.mcpContext
7142
7156
  );
7143
7157
  this.modelInstanceCache.set(cacheKey, boundModel);
7144
7158
  return boundModel;
@@ -7155,24 +7169,27 @@ var ModelInitializer = class _ModelInitializer {
7155
7169
  * - Runnable when tools are bound (model.bindTools returns Runnable)
7156
7170
  * - BaseChatModel when no tools
7157
7171
  */
7158
- async bindToolsToModel(model, toolsConfig, customTools) {
7172
+ async bindToolsToModel(model, toolsConfig, customTools, mcpServers, mcpContext) {
7159
7173
  const allTools = [];
7160
- if (toolsConfig && toolsConfig.length > 0) {
7174
+ const enabledToolsConfig = (toolsConfig || []).filter(
7175
+ (tc) => tc.enabled !== false
7176
+ );
7177
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
7178
+ if (enabledToolsConfig.length > 0 || hasInlineServers) {
7161
7179
  try {
7162
- const enabledToolsConfig = toolsConfig.filter(
7163
- (tc) => tc.enabled !== false
7180
+ this.logger.debug(
7181
+ `Fetching ${enabledToolsConfig.length} tools (+${mcpServers?.length || 0} inline server(s)) with dynamic schemas from MCP Runtime`
7164
7182
  );
7165
- if (enabledToolsConfig.length > 0) {
7166
- this.logger.debug(
7167
- `Fetching ${enabledToolsConfig.length} tools with dynamic schemas from MCP Runtime: ${enabledToolsConfig.map((tc) => tc.toolName).join(", ")}`
7168
- );
7169
- const mcpToolFilter = new McpToolFilter();
7170
- const mcpTools = await mcpToolFilter.getFilteredTools(enabledToolsConfig);
7171
- this.logger.debug(
7172
- `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7173
- );
7174
- allTools.push(...mcpTools);
7175
- }
7183
+ const mcpToolFilter = new McpToolFilter();
7184
+ const mcpTools = await mcpToolFilter.getFilteredTools(
7185
+ enabledToolsConfig,
7186
+ mcpServers,
7187
+ mcpContext
7188
+ );
7189
+ this.logger.debug(
7190
+ `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7191
+ );
7192
+ allTools.push(...mcpTools);
7176
7193
  } catch (error) {
7177
7194
  this.logger.error(
7178
7195
  `Failed to fetch tools from MCP Runtime: ${error instanceof Error ? error.message : String(error)}`