@flutchai/flutch-sdk 0.4.1 → 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 +48 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +48 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1049,6 +1049,8 @@ interface ModelByIdConfig {
|
|
|
1049
1049
|
baseURL?: string;
|
|
1050
1050
|
toolsConfig?: IAgentToolConfig[];
|
|
1051
1051
|
customTools?: DynamicStructuredTool[];
|
|
1052
|
+
mcpServers?: Record<string, any>[];
|
|
1053
|
+
mcpContext?: Record<string, any>;
|
|
1052
1054
|
}
|
|
1053
1055
|
type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
|
|
1054
1056
|
interface ModelConfigWithToken {
|
|
@@ -1273,7 +1275,7 @@ declare class McpToolFilter {
|
|
|
1273
1275
|
private readonly logger;
|
|
1274
1276
|
private readonly mcpConverter;
|
|
1275
1277
|
constructor(mcpRuntimeUrl?: string);
|
|
1276
|
-
getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
|
|
1278
|
+
getFilteredTools(toolsConfig?: IAgentToolConfig[], mcpServers?: Record<string, any>[], context?: Record<string, any>): Promise<StructuredTool[]>;
|
|
1277
1279
|
getAllTools(): Promise<StructuredTool[]>;
|
|
1278
1280
|
isHealthy(): Promise<boolean>;
|
|
1279
1281
|
getAvailableToolNames(): Promise<string[]>;
|
|
@@ -1285,10 +1287,10 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
|
|
|
1285
1287
|
private readonly baseUrl;
|
|
1286
1288
|
constructor(mcpRuntimeUrl?: string);
|
|
1287
1289
|
getTools(): Promise<McpTool[]>;
|
|
1288
|
-
executeTool(name: string, args: any, context?: any): Promise<ToolExecutionResult>;
|
|
1290
|
+
executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
|
|
1289
1291
|
getToolStats(): Promise<any>;
|
|
1290
1292
|
isHealthy(): Promise<boolean>;
|
|
1291
|
-
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<{
|
|
1292
1294
|
content: string;
|
|
1293
1295
|
success: boolean;
|
|
1294
1296
|
rawResult?: any;
|
|
@@ -1326,6 +1328,7 @@ interface ExecuteToolWithAttachmentsParams {
|
|
|
1326
1328
|
properties?: Record<string, any>;
|
|
1327
1329
|
required?: string[];
|
|
1328
1330
|
};
|
|
1331
|
+
mcpServers?: Record<string, any>[];
|
|
1329
1332
|
}
|
|
1330
1333
|
interface ExecuteToolWithAttachmentsResult {
|
|
1331
1334
|
toolMessage: ToolMessage;
|
package/dist/index.d.ts
CHANGED
|
@@ -1049,6 +1049,8 @@ interface ModelByIdConfig {
|
|
|
1049
1049
|
baseURL?: string;
|
|
1050
1050
|
toolsConfig?: IAgentToolConfig[];
|
|
1051
1051
|
customTools?: DynamicStructuredTool[];
|
|
1052
|
+
mcpServers?: Record<string, any>[];
|
|
1053
|
+
mcpContext?: Record<string, any>;
|
|
1052
1054
|
}
|
|
1053
1055
|
type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
|
|
1054
1056
|
interface ModelConfigWithToken {
|
|
@@ -1273,7 +1275,7 @@ declare class McpToolFilter {
|
|
|
1273
1275
|
private readonly logger;
|
|
1274
1276
|
private readonly mcpConverter;
|
|
1275
1277
|
constructor(mcpRuntimeUrl?: string);
|
|
1276
|
-
getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
|
|
1278
|
+
getFilteredTools(toolsConfig?: IAgentToolConfig[], mcpServers?: Record<string, any>[], context?: Record<string, any>): Promise<StructuredTool[]>;
|
|
1277
1279
|
getAllTools(): Promise<StructuredTool[]>;
|
|
1278
1280
|
isHealthy(): Promise<boolean>;
|
|
1279
1281
|
getAvailableToolNames(): Promise<string[]>;
|
|
@@ -1285,10 +1287,10 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
|
|
|
1285
1287
|
private readonly baseUrl;
|
|
1286
1288
|
constructor(mcpRuntimeUrl?: string);
|
|
1287
1289
|
getTools(): Promise<McpTool[]>;
|
|
1288
|
-
executeTool(name: string, args: any, context?: any): Promise<ToolExecutionResult>;
|
|
1290
|
+
executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
|
|
1289
1291
|
getToolStats(): Promise<any>;
|
|
1290
1292
|
isHealthy(): Promise<boolean>;
|
|
1291
|
-
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<{
|
|
1292
1294
|
content: string;
|
|
1293
1295
|
success: boolean;
|
|
1294
1296
|
rawResult?: any;
|
|
@@ -1326,6 +1328,7 @@ interface ExecuteToolWithAttachmentsParams {
|
|
|
1326
1328
|
properties?: Record<string, any>;
|
|
1327
1329
|
required?: string[];
|
|
1328
1330
|
};
|
|
1331
|
+
mcpServers?: Record<string, any>[];
|
|
1329
1332
|
}
|
|
1330
1333
|
interface ExecuteToolWithAttachmentsResult {
|
|
1331
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) {
|
|
@@ -6350,12 +6352,13 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6350
6352
|
* @param toolsConfig Array of tool configurations with dynamic config
|
|
6351
6353
|
* @returns Array of LangChain Tool instances with dynamic schemas
|
|
6352
6354
|
*/
|
|
6353
|
-
async getFilteredTools(toolsConfig = []) {
|
|
6355
|
+
async getFilteredTools(toolsConfig = [], mcpServers, context) {
|
|
6354
6356
|
this.logger.debug(
|
|
6355
6357
|
`[DEBUG] Getting filtered tools with dynamic schemas. Config: ${JSON.stringify(toolsConfig)}`
|
|
6356
6358
|
);
|
|
6357
6359
|
this.logger.debug(`[DEBUG] MCP Runtime URL: ${this.mcpRuntimeUrl}`);
|
|
6358
|
-
|
|
6360
|
+
const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
|
|
6361
|
+
if (toolsConfig.length === 0 && !hasInlineServers) {
|
|
6359
6362
|
this.logger.debug("No tools configured, returning empty array");
|
|
6360
6363
|
return [];
|
|
6361
6364
|
}
|
|
@@ -6363,10 +6366,13 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6363
6366
|
this.logger.debug(
|
|
6364
6367
|
`[DEBUG] Making HTTP POST request to: ${this.mcpRuntimeUrl}/tools/schemas`
|
|
6365
6368
|
);
|
|
6366
|
-
|
|
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)}`);
|
|
6367
6373
|
const response = await axios2.post(
|
|
6368
6374
|
`${this.mcpRuntimeUrl}/tools/schemas`,
|
|
6369
|
-
|
|
6375
|
+
requestBody,
|
|
6370
6376
|
{
|
|
6371
6377
|
timeout: 5e3,
|
|
6372
6378
|
headers: {
|
|
@@ -6383,14 +6389,14 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6383
6389
|
);
|
|
6384
6390
|
const mcpClient = {
|
|
6385
6391
|
getTools: async () => dynamicTools,
|
|
6386
|
-
executeTool: async (name, args,
|
|
6392
|
+
executeTool: async (name, args, context2) => {
|
|
6387
6393
|
this.logger.debug(`[DEBUG] Executing tool ${name} with args:`, args);
|
|
6388
6394
|
const response2 = await axios2.post(
|
|
6389
6395
|
`${this.mcpRuntimeUrl}/tools/execute`,
|
|
6390
6396
|
{
|
|
6391
6397
|
name,
|
|
6392
6398
|
arguments: args || {},
|
|
6393
|
-
context
|
|
6399
|
+
context: context2
|
|
6394
6400
|
}
|
|
6395
6401
|
);
|
|
6396
6402
|
return response2.data;
|
|
@@ -6529,7 +6535,7 @@ var McpRuntimeHttpClient = class {
|
|
|
6529
6535
|
/**
|
|
6530
6536
|
* Execute a tool by name with given arguments
|
|
6531
6537
|
*/
|
|
6532
|
-
async executeTool(name, args, context) {
|
|
6538
|
+
async executeTool(name, args, context, mcpServers) {
|
|
6533
6539
|
try {
|
|
6534
6540
|
this.logger.debug(`Executing tool: ${name} with args:`, args);
|
|
6535
6541
|
const payload = {
|
|
@@ -6539,6 +6545,9 @@ var McpRuntimeHttpClient = class {
|
|
|
6539
6545
|
if (context) {
|
|
6540
6546
|
payload.context = context;
|
|
6541
6547
|
}
|
|
6548
|
+
if (mcpServers && mcpServers.length > 0) {
|
|
6549
|
+
payload.mcpServers = mcpServers;
|
|
6550
|
+
}
|
|
6542
6551
|
const response = await this.httpClient.post("/tools/execute", payload);
|
|
6543
6552
|
this.logger.log(`Tool ${name} executed successfully`);
|
|
6544
6553
|
return response.data;
|
|
@@ -6589,7 +6598,7 @@ var McpRuntimeHttpClient = class {
|
|
|
6589
6598
|
* @param config - RunnableConfig with callbacks
|
|
6590
6599
|
* @returns Tool execution result with content
|
|
6591
6600
|
*/
|
|
6592
|
-
async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config) {
|
|
6601
|
+
async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config, mcpServers) {
|
|
6593
6602
|
const parsedConfig = parseCallbackConfigArg(config);
|
|
6594
6603
|
const callbackManager = CallbackManager.configure(parsedConfig.callbacks);
|
|
6595
6604
|
let runManager;
|
|
@@ -6611,7 +6620,8 @@ var McpRuntimeHttpClient = class {
|
|
|
6611
6620
|
const result = await this.executeTool(
|
|
6612
6621
|
toolName,
|
|
6613
6622
|
enrichedArgs,
|
|
6614
|
-
executionContext
|
|
6623
|
+
executionContext,
|
|
6624
|
+
mcpServers
|
|
6615
6625
|
);
|
|
6616
6626
|
const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
|
|
6617
6627
|
await runManager?.handleToolEnd(content);
|
|
@@ -6820,13 +6830,17 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6820
6830
|
* Example: "model123:0.7:4096" or "model123:0.7:4096:a1b2c3d4e5f6g7h8"
|
|
6821
6831
|
*/
|
|
6822
6832
|
generateModelCacheKey(config) {
|
|
6823
|
-
|
|
6833
|
+
const base = generateModelCacheKey(
|
|
6824
6834
|
config.modelId,
|
|
6825
6835
|
config.temperature,
|
|
6826
6836
|
config.maxTokens,
|
|
6827
6837
|
config.toolsConfig,
|
|
6828
6838
|
config.baseURL
|
|
6829
6839
|
);
|
|
6840
|
+
if (config.mcpServers && config.mcpServers.length > 0) {
|
|
6841
|
+
return `${base}:mcp:${JSON.stringify(config.mcpServers)}`;
|
|
6842
|
+
}
|
|
6843
|
+
return base;
|
|
6830
6844
|
}
|
|
6831
6845
|
// Chat model creators
|
|
6832
6846
|
chatModelCreators = {
|
|
@@ -7102,11 +7116,13 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7102
7116
|
...model.metadata,
|
|
7103
7117
|
modelId: config.modelId
|
|
7104
7118
|
};
|
|
7105
|
-
if (config.toolsConfig || config.customTools) {
|
|
7119
|
+
if (config.toolsConfig || config.customTools || config.mcpServers && config.mcpServers.length > 0) {
|
|
7106
7120
|
const boundModel = await this.bindToolsToModel(
|
|
7107
7121
|
model,
|
|
7108
7122
|
config.toolsConfig,
|
|
7109
|
-
config.customTools
|
|
7123
|
+
config.customTools,
|
|
7124
|
+
config.mcpServers,
|
|
7125
|
+
config.mcpContext
|
|
7110
7126
|
);
|
|
7111
7127
|
this.modelInstanceCache.set(cacheKey, boundModel);
|
|
7112
7128
|
return boundModel;
|
|
@@ -7123,24 +7139,27 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7123
7139
|
* - Runnable when tools are bound (model.bindTools returns Runnable)
|
|
7124
7140
|
* - BaseChatModel when no tools
|
|
7125
7141
|
*/
|
|
7126
|
-
async bindToolsToModel(model, toolsConfig, customTools) {
|
|
7142
|
+
async bindToolsToModel(model, toolsConfig, customTools, mcpServers, mcpContext) {
|
|
7127
7143
|
const allTools = [];
|
|
7128
|
-
|
|
7144
|
+
const enabledToolsConfig = (toolsConfig || []).filter(
|
|
7145
|
+
(tc) => tc.enabled !== false
|
|
7146
|
+
);
|
|
7147
|
+
const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
|
|
7148
|
+
if (enabledToolsConfig.length > 0 || hasInlineServers) {
|
|
7129
7149
|
try {
|
|
7130
|
-
|
|
7131
|
-
(
|
|
7150
|
+
this.logger.debug(
|
|
7151
|
+
`Fetching ${enabledToolsConfig.length} tools (+${mcpServers?.length || 0} inline server(s)) with dynamic schemas from MCP Runtime`
|
|
7132
7152
|
);
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
}
|
|
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);
|
|
7144
7163
|
} catch (error) {
|
|
7145
7164
|
this.logger.error(
|
|
7146
7165
|
`Failed to fetch tools from MCP Runtime: ${error instanceof Error ? error.message : String(error)}`
|