@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.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) {
|
|
@@ -6380,12 +6382,13 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6380
6382
|
* @param toolsConfig Array of tool configurations with dynamic config
|
|
6381
6383
|
* @returns Array of LangChain Tool instances with dynamic schemas
|
|
6382
6384
|
*/
|
|
6383
|
-
async getFilteredTools(toolsConfig = []) {
|
|
6385
|
+
async getFilteredTools(toolsConfig = [], mcpServers, context) {
|
|
6384
6386
|
this.logger.debug(
|
|
6385
6387
|
`[DEBUG] Getting filtered tools with dynamic schemas. Config: ${JSON.stringify(toolsConfig)}`
|
|
6386
6388
|
);
|
|
6387
6389
|
this.logger.debug(`[DEBUG] MCP Runtime URL: ${this.mcpRuntimeUrl}`);
|
|
6388
|
-
|
|
6390
|
+
const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
|
|
6391
|
+
if (toolsConfig.length === 0 && !hasInlineServers) {
|
|
6389
6392
|
this.logger.debug("No tools configured, returning empty array");
|
|
6390
6393
|
return [];
|
|
6391
6394
|
}
|
|
@@ -6393,10 +6396,13 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6393
6396
|
this.logger.debug(
|
|
6394
6397
|
`[DEBUG] Making HTTP POST request to: ${this.mcpRuntimeUrl}/tools/schemas`
|
|
6395
6398
|
);
|
|
6396
|
-
|
|
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)}`);
|
|
6397
6403
|
const response = await axios2__default.default.post(
|
|
6398
6404
|
`${this.mcpRuntimeUrl}/tools/schemas`,
|
|
6399
|
-
|
|
6405
|
+
requestBody,
|
|
6400
6406
|
{
|
|
6401
6407
|
timeout: 5e3,
|
|
6402
6408
|
headers: {
|
|
@@ -6413,14 +6419,14 @@ var McpToolFilter = class _McpToolFilter {
|
|
|
6413
6419
|
);
|
|
6414
6420
|
const mcpClient = {
|
|
6415
6421
|
getTools: async () => dynamicTools,
|
|
6416
|
-
executeTool: async (name, args,
|
|
6422
|
+
executeTool: async (name, args, context2) => {
|
|
6417
6423
|
this.logger.debug(`[DEBUG] Executing tool ${name} with args:`, args);
|
|
6418
6424
|
const response2 = await axios2__default.default.post(
|
|
6419
6425
|
`${this.mcpRuntimeUrl}/tools/execute`,
|
|
6420
6426
|
{
|
|
6421
6427
|
name,
|
|
6422
6428
|
arguments: args || {},
|
|
6423
|
-
context
|
|
6429
|
+
context: context2
|
|
6424
6430
|
}
|
|
6425
6431
|
);
|
|
6426
6432
|
return response2.data;
|
|
@@ -6559,7 +6565,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
|
|
|
6559
6565
|
/**
|
|
6560
6566
|
* Execute a tool by name with given arguments
|
|
6561
6567
|
*/
|
|
6562
|
-
async executeTool(name, args, context) {
|
|
6568
|
+
async executeTool(name, args, context, mcpServers) {
|
|
6563
6569
|
try {
|
|
6564
6570
|
this.logger.debug(`Executing tool: ${name} with args:`, args);
|
|
6565
6571
|
const payload = {
|
|
@@ -6569,6 +6575,9 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
|
|
|
6569
6575
|
if (context) {
|
|
6570
6576
|
payload.context = context;
|
|
6571
6577
|
}
|
|
6578
|
+
if (mcpServers && mcpServers.length > 0) {
|
|
6579
|
+
payload.mcpServers = mcpServers;
|
|
6580
|
+
}
|
|
6572
6581
|
const response = await this.httpClient.post("/tools/execute", payload);
|
|
6573
6582
|
this.logger.log(`Tool ${name} executed successfully`);
|
|
6574
6583
|
return response.data;
|
|
@@ -6619,7 +6628,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
|
|
|
6619
6628
|
* @param config - RunnableConfig with callbacks
|
|
6620
6629
|
* @returns Tool execution result with content
|
|
6621
6630
|
*/
|
|
6622
|
-
async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config) {
|
|
6631
|
+
async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config, mcpServers) {
|
|
6623
6632
|
const parsedConfig = manager.parseCallbackConfigArg(config);
|
|
6624
6633
|
const callbackManager = manager.CallbackManager.configure(parsedConfig.callbacks);
|
|
6625
6634
|
let runManager;
|
|
@@ -6641,7 +6650,8 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
|
|
|
6641
6650
|
const result = await this.executeTool(
|
|
6642
6651
|
toolName,
|
|
6643
6652
|
enrichedArgs,
|
|
6644
|
-
executionContext
|
|
6653
|
+
executionContext,
|
|
6654
|
+
mcpServers
|
|
6645
6655
|
);
|
|
6646
6656
|
const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
|
|
6647
6657
|
await runManager?.handleToolEnd(content);
|
|
@@ -6850,13 +6860,17 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6850
6860
|
* Example: "model123:0.7:4096" or "model123:0.7:4096:a1b2c3d4e5f6g7h8"
|
|
6851
6861
|
*/
|
|
6852
6862
|
generateModelCacheKey(config) {
|
|
6853
|
-
|
|
6863
|
+
const base = generateModelCacheKey(
|
|
6854
6864
|
config.modelId,
|
|
6855
6865
|
config.temperature,
|
|
6856
6866
|
config.maxTokens,
|
|
6857
6867
|
config.toolsConfig,
|
|
6858
6868
|
config.baseURL
|
|
6859
6869
|
);
|
|
6870
|
+
if (config.mcpServers && config.mcpServers.length > 0) {
|
|
6871
|
+
return `${base}:mcp:${JSON.stringify(config.mcpServers)}`;
|
|
6872
|
+
}
|
|
6873
|
+
return base;
|
|
6860
6874
|
}
|
|
6861
6875
|
// Chat model creators
|
|
6862
6876
|
chatModelCreators = {
|
|
@@ -7132,11 +7146,13 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7132
7146
|
...model.metadata,
|
|
7133
7147
|
modelId: config.modelId
|
|
7134
7148
|
};
|
|
7135
|
-
if (config.toolsConfig || config.customTools) {
|
|
7149
|
+
if (config.toolsConfig || config.customTools || config.mcpServers && config.mcpServers.length > 0) {
|
|
7136
7150
|
const boundModel = await this.bindToolsToModel(
|
|
7137
7151
|
model,
|
|
7138
7152
|
config.toolsConfig,
|
|
7139
|
-
config.customTools
|
|
7153
|
+
config.customTools,
|
|
7154
|
+
config.mcpServers,
|
|
7155
|
+
config.mcpContext
|
|
7140
7156
|
);
|
|
7141
7157
|
this.modelInstanceCache.set(cacheKey, boundModel);
|
|
7142
7158
|
return boundModel;
|
|
@@ -7153,24 +7169,27 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7153
7169
|
* - Runnable when tools are bound (model.bindTools returns Runnable)
|
|
7154
7170
|
* - BaseChatModel when no tools
|
|
7155
7171
|
*/
|
|
7156
|
-
async bindToolsToModel(model, toolsConfig, customTools) {
|
|
7172
|
+
async bindToolsToModel(model, toolsConfig, customTools, mcpServers, mcpContext) {
|
|
7157
7173
|
const allTools = [];
|
|
7158
|
-
|
|
7174
|
+
const enabledToolsConfig = (toolsConfig || []).filter(
|
|
7175
|
+
(tc) => tc.enabled !== false
|
|
7176
|
+
);
|
|
7177
|
+
const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
|
|
7178
|
+
if (enabledToolsConfig.length > 0 || hasInlineServers) {
|
|
7159
7179
|
try {
|
|
7160
|
-
|
|
7161
|
-
(
|
|
7180
|
+
this.logger.debug(
|
|
7181
|
+
`Fetching ${enabledToolsConfig.length} tools (+${mcpServers?.length || 0} inline server(s)) with dynamic schemas from MCP Runtime`
|
|
7162
7182
|
);
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
}
|
|
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);
|
|
7174
7193
|
} catch (error) {
|
|
7175
7194
|
this.logger.error(
|
|
7176
7195
|
`Failed to fetch tools from MCP Runtime: ${error instanceof Error ? error.message : String(error)}`
|