@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.d.cts CHANGED
@@ -1018,8 +1018,6 @@ interface FlutchContext {
1018
1018
  agentId?: string;
1019
1019
  userId?: string;
1020
1020
  nodeName?: string;
1021
- companyId?: string;
1022
- accountId?: string;
1023
1021
  }
1024
1022
  declare function withFlutchContext<T>(ctx: FlutchContext, fn: () => T): T;
1025
1023
  declare function getFlutchContext(): FlutchContext | undefined;
@@ -1051,6 +1049,8 @@ interface ModelByIdConfig {
1051
1049
  baseURL?: string;
1052
1050
  toolsConfig?: IAgentToolConfig[];
1053
1051
  customTools?: DynamicStructuredTool[];
1052
+ mcpServers?: Record<string, any>[];
1053
+ mcpContext?: Record<string, any>;
1054
1054
  }
1055
1055
  type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
1056
1056
  interface ModelConfigWithToken {
@@ -1275,7 +1275,7 @@ declare class McpToolFilter {
1275
1275
  private readonly logger;
1276
1276
  private readonly mcpConverter;
1277
1277
  constructor(mcpRuntimeUrl?: string);
1278
- getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
1278
+ getFilteredTools(toolsConfig?: IAgentToolConfig[], mcpServers?: Record<string, any>[], context?: Record<string, any>): Promise<StructuredTool[]>;
1279
1279
  getAllTools(): Promise<StructuredTool[]>;
1280
1280
  isHealthy(): Promise<boolean>;
1281
1281
  getAvailableToolNames(): Promise<string[]>;
@@ -1287,10 +1287,10 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
1287
1287
  private readonly baseUrl;
1288
1288
  constructor(mcpRuntimeUrl?: string);
1289
1289
  getTools(): Promise<McpTool[]>;
1290
- executeTool(name: string, args: any, context?: any): Promise<ToolExecutionResult>;
1290
+ executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
1291
1291
  getToolStats(): Promise<any>;
1292
1292
  isHealthy(): Promise<boolean>;
1293
- executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig): Promise<{
1293
+ executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig, mcpServers?: Record<string, any>[]): Promise<{
1294
1294
  content: string;
1295
1295
  success: boolean;
1296
1296
  rawResult?: any;
@@ -1328,6 +1328,7 @@ interface ExecuteToolWithAttachmentsParams {
1328
1328
  properties?: Record<string, any>;
1329
1329
  required?: string[];
1330
1330
  };
1331
+ mcpServers?: Record<string, any>[];
1331
1332
  }
1332
1333
  interface ExecuteToolWithAttachmentsResult {
1333
1334
  toolMessage: ToolMessage;
package/dist/index.d.ts CHANGED
@@ -1018,8 +1018,6 @@ interface FlutchContext {
1018
1018
  agentId?: string;
1019
1019
  userId?: string;
1020
1020
  nodeName?: string;
1021
- companyId?: string;
1022
- accountId?: string;
1023
1021
  }
1024
1022
  declare function withFlutchContext<T>(ctx: FlutchContext, fn: () => T): T;
1025
1023
  declare function getFlutchContext(): FlutchContext | undefined;
@@ -1051,6 +1049,8 @@ interface ModelByIdConfig {
1051
1049
  baseURL?: string;
1052
1050
  toolsConfig?: IAgentToolConfig[];
1053
1051
  customTools?: DynamicStructuredTool[];
1052
+ mcpServers?: Record<string, any>[];
1053
+ mcpContext?: Record<string, any>;
1054
1054
  }
1055
1055
  type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
1056
1056
  interface ModelConfigWithToken {
@@ -1275,7 +1275,7 @@ declare class McpToolFilter {
1275
1275
  private readonly logger;
1276
1276
  private readonly mcpConverter;
1277
1277
  constructor(mcpRuntimeUrl?: string);
1278
- getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
1278
+ getFilteredTools(toolsConfig?: IAgentToolConfig[], mcpServers?: Record<string, any>[], context?: Record<string, any>): Promise<StructuredTool[]>;
1279
1279
  getAllTools(): Promise<StructuredTool[]>;
1280
1280
  isHealthy(): Promise<boolean>;
1281
1281
  getAvailableToolNames(): Promise<string[]>;
@@ -1287,10 +1287,10 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
1287
1287
  private readonly baseUrl;
1288
1288
  constructor(mcpRuntimeUrl?: string);
1289
1289
  getTools(): Promise<McpTool[]>;
1290
- executeTool(name: string, args: any, context?: any): Promise<ToolExecutionResult>;
1290
+ executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
1291
1291
  getToolStats(): Promise<any>;
1292
1292
  isHealthy(): Promise<boolean>;
1293
- executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig): Promise<{
1293
+ executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig, mcpServers?: Record<string, any>[]): Promise<{
1294
1294
  content: string;
1295
1295
  success: boolean;
1296
1296
  rawResult?: any;
@@ -1328,6 +1328,7 @@ interface ExecuteToolWithAttachmentsParams {
1328
1328
  properties?: Record<string, any>;
1329
1329
  required?: string[];
1330
1330
  };
1331
+ mcpServers?: Record<string, any>[];
1331
1332
  }
1332
1333
  interface ExecuteToolWithAttachmentsResult {
1333
1334
  toolMessage: ToolMessage;
package/dist/index.js CHANGED
@@ -4459,7 +4459,8 @@ async function executeToolWithAttachments(params) {
4459
4459
  injectIntoArg = "data",
4460
4460
  sourceAttachmentId,
4461
4461
  threadId,
4462
- toolSchema
4462
+ toolSchema,
4463
+ mcpServers
4463
4464
  } = params;
4464
4465
  const argsWithInjection = { ...enrichedArgs };
4465
4466
  try {
@@ -4490,7 +4491,8 @@ async function executeToolWithAttachments(params) {
4490
4491
  toolCall.name,
4491
4492
  argsWithInjection,
4492
4493
  executionContext,
4493
- config
4494
+ config,
4495
+ mcpServers
4494
4496
  );
4495
4497
  try {
4496
4498
  if (success && rawResult !== void 0 && content.length > threshold) {
@@ -5286,9 +5288,7 @@ var HEADER_MAP = {
5286
5288
  threadId: "x-flutch-thread-id",
5287
5289
  agentId: "x-flutch-agent-id",
5288
5290
  userId: "x-flutch-user-id",
5289
- nodeName: "x-flutch-node",
5290
- companyId: "x-flutch-company-id",
5291
- accountId: "x-flutch-account-id"
5291
+ nodeName: "x-flutch-node"
5292
5292
  };
5293
5293
  var INTERNAL_TOKEN_HEADER = "x-flutch-internal-token";
5294
5294
  function isInternalMode() {
@@ -6352,12 +6352,13 @@ var McpToolFilter = class _McpToolFilter {
6352
6352
  * @param toolsConfig Array of tool configurations with dynamic config
6353
6353
  * @returns Array of LangChain Tool instances with dynamic schemas
6354
6354
  */
6355
- async getFilteredTools(toolsConfig = []) {
6355
+ async getFilteredTools(toolsConfig = [], mcpServers, context) {
6356
6356
  this.logger.debug(
6357
6357
  `[DEBUG] Getting filtered tools with dynamic schemas. Config: ${JSON.stringify(toolsConfig)}`
6358
6358
  );
6359
6359
  this.logger.debug(`[DEBUG] MCP Runtime URL: ${this.mcpRuntimeUrl}`);
6360
- if (toolsConfig.length === 0) {
6360
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
6361
+ if (toolsConfig.length === 0 && !hasInlineServers) {
6361
6362
  this.logger.debug("No tools configured, returning empty array");
6362
6363
  return [];
6363
6364
  }
@@ -6365,10 +6366,13 @@ var McpToolFilter = class _McpToolFilter {
6365
6366
  this.logger.debug(
6366
6367
  `[DEBUG] Making HTTP POST request to: ${this.mcpRuntimeUrl}/tools/schemas`
6367
6368
  );
6368
- this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(toolsConfig)}`);
6369
+ const requestBody = { tools: toolsConfig };
6370
+ if (hasInlineServers) requestBody.mcpServers = mcpServers;
6371
+ if (context) requestBody.context = context;
6372
+ this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(requestBody)}`);
6369
6373
  const response = await axios2.post(
6370
6374
  `${this.mcpRuntimeUrl}/tools/schemas`,
6371
- { tools: toolsConfig },
6375
+ requestBody,
6372
6376
  {
6373
6377
  timeout: 5e3,
6374
6378
  headers: {
@@ -6385,14 +6389,14 @@ var McpToolFilter = class _McpToolFilter {
6385
6389
  );
6386
6390
  const mcpClient = {
6387
6391
  getTools: async () => dynamicTools,
6388
- executeTool: async (name, args, context) => {
6392
+ executeTool: async (name, args, context2) => {
6389
6393
  this.logger.debug(`[DEBUG] Executing tool ${name} with args:`, args);
6390
6394
  const response2 = await axios2.post(
6391
6395
  `${this.mcpRuntimeUrl}/tools/execute`,
6392
6396
  {
6393
6397
  name,
6394
6398
  arguments: args || {},
6395
- context
6399
+ context: context2
6396
6400
  }
6397
6401
  );
6398
6402
  return response2.data;
@@ -6531,7 +6535,7 @@ var McpRuntimeHttpClient = class {
6531
6535
  /**
6532
6536
  * Execute a tool by name with given arguments
6533
6537
  */
6534
- async executeTool(name, args, context) {
6538
+ async executeTool(name, args, context, mcpServers) {
6535
6539
  try {
6536
6540
  this.logger.debug(`Executing tool: ${name} with args:`, args);
6537
6541
  const payload = {
@@ -6541,6 +6545,9 @@ var McpRuntimeHttpClient = class {
6541
6545
  if (context) {
6542
6546
  payload.context = context;
6543
6547
  }
6548
+ if (mcpServers && mcpServers.length > 0) {
6549
+ payload.mcpServers = mcpServers;
6550
+ }
6544
6551
  const response = await this.httpClient.post("/tools/execute", payload);
6545
6552
  this.logger.log(`Tool ${name} executed successfully`);
6546
6553
  return response.data;
@@ -6591,7 +6598,7 @@ var McpRuntimeHttpClient = class {
6591
6598
  * @param config - RunnableConfig with callbacks
6592
6599
  * @returns Tool execution result with content
6593
6600
  */
6594
- async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config) {
6601
+ async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config, mcpServers) {
6595
6602
  const parsedConfig = parseCallbackConfigArg(config);
6596
6603
  const callbackManager = CallbackManager.configure(parsedConfig.callbacks);
6597
6604
  let runManager;
@@ -6613,7 +6620,8 @@ var McpRuntimeHttpClient = class {
6613
6620
  const result = await this.executeTool(
6614
6621
  toolName,
6615
6622
  enrichedArgs,
6616
- executionContext
6623
+ executionContext,
6624
+ mcpServers
6617
6625
  );
6618
6626
  const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
6619
6627
  await runManager?.handleToolEnd(content);
@@ -6822,13 +6830,17 @@ var ModelInitializer = class _ModelInitializer {
6822
6830
  * Example: "model123:0.7:4096" or "model123:0.7:4096:a1b2c3d4e5f6g7h8"
6823
6831
  */
6824
6832
  generateModelCacheKey(config) {
6825
- return generateModelCacheKey(
6833
+ const base = generateModelCacheKey(
6826
6834
  config.modelId,
6827
6835
  config.temperature,
6828
6836
  config.maxTokens,
6829
6837
  config.toolsConfig,
6830
6838
  config.baseURL
6831
6839
  );
6840
+ if (config.mcpServers && config.mcpServers.length > 0) {
6841
+ return `${base}:mcp:${JSON.stringify(config.mcpServers)}`;
6842
+ }
6843
+ return base;
6832
6844
  }
6833
6845
  // Chat model creators
6834
6846
  chatModelCreators = {
@@ -7104,11 +7116,13 @@ var ModelInitializer = class _ModelInitializer {
7104
7116
  ...model.metadata,
7105
7117
  modelId: config.modelId
7106
7118
  };
7107
- if (config.toolsConfig || config.customTools) {
7119
+ if (config.toolsConfig || config.customTools || config.mcpServers && config.mcpServers.length > 0) {
7108
7120
  const boundModel = await this.bindToolsToModel(
7109
7121
  model,
7110
7122
  config.toolsConfig,
7111
- config.customTools
7123
+ config.customTools,
7124
+ config.mcpServers,
7125
+ config.mcpContext
7112
7126
  );
7113
7127
  this.modelInstanceCache.set(cacheKey, boundModel);
7114
7128
  return boundModel;
@@ -7125,24 +7139,27 @@ var ModelInitializer = class _ModelInitializer {
7125
7139
  * - Runnable when tools are bound (model.bindTools returns Runnable)
7126
7140
  * - BaseChatModel when no tools
7127
7141
  */
7128
- async bindToolsToModel(model, toolsConfig, customTools) {
7142
+ async bindToolsToModel(model, toolsConfig, customTools, mcpServers, mcpContext) {
7129
7143
  const allTools = [];
7130
- if (toolsConfig && toolsConfig.length > 0) {
7144
+ const enabledToolsConfig = (toolsConfig || []).filter(
7145
+ (tc) => tc.enabled !== false
7146
+ );
7147
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
7148
+ if (enabledToolsConfig.length > 0 || hasInlineServers) {
7131
7149
  try {
7132
- const enabledToolsConfig = toolsConfig.filter(
7133
- (tc) => tc.enabled !== false
7150
+ this.logger.debug(
7151
+ `Fetching ${enabledToolsConfig.length} tools (+${mcpServers?.length || 0} inline server(s)) with dynamic schemas from MCP Runtime`
7134
7152
  );
7135
- if (enabledToolsConfig.length > 0) {
7136
- this.logger.debug(
7137
- `Fetching ${enabledToolsConfig.length} tools with dynamic schemas from MCP Runtime: ${enabledToolsConfig.map((tc) => tc.toolName).join(", ")}`
7138
- );
7139
- const mcpToolFilter = new McpToolFilter();
7140
- const mcpTools = await mcpToolFilter.getFilteredTools(enabledToolsConfig);
7141
- this.logger.debug(
7142
- `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7143
- );
7144
- allTools.push(...mcpTools);
7145
- }
7153
+ const mcpToolFilter = new McpToolFilter();
7154
+ const mcpTools = await mcpToolFilter.getFilteredTools(
7155
+ enabledToolsConfig,
7156
+ mcpServers,
7157
+ mcpContext
7158
+ );
7159
+ this.logger.debug(
7160
+ `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7161
+ );
7162
+ allTools.push(...mcpTools);
7146
7163
  } catch (error) {
7147
7164
  this.logger.error(
7148
7165
  `Failed to fetch tools from MCP Runtime: ${error instanceof Error ? error.message : String(error)}`