@@ -6465,14 +6465,31 @@ MiniA.prototype._registerMcpToolsForGoal = function(args) {
64656465
64666466 var parent = this
64676467 var registerMcpTools = function ( llmInstance ) {
6468- // Check if LLM actually supports function calling
6469- if ( isUnDef ( llmInstance ) || typeof llmInstance . withMcpTools != "function" ) {
6468+ // Check if we're using mcpproxy - if so, force function calling mode
6469+ var usingMcpProxy = toBoolean ( args . mcpproxy ) === true
6470+ var hasMcpProxyConnection = Object . keys ( parent . _mcpConnections || { } ) . some ( function ( id ) {
6471+ return id === md5 ( "mini-a-mcp-proxy" ) || id . indexOf ( "mini-a-mcp-proxy" ) >= 0
6472+ } )
6473+
6474+ // When mcpproxy=true, always use function calling mode regardless of LLM support
6475+ // NOTE: _useToolsActual is already pre-set before init() to ensure correct prompt template
6476+ if ( usingMcpProxy && hasMcpProxyConnection ) {
6477+ parent . fnI ( "info" , "MCP proxy mode enabled - using function calling for proxy-dispatch tool." )
6478+ parent . _useToolsActual = true // Confirm function calling mode for proxy (already set before init)
6479+
6480+ // Even if LLM doesn't have withMcpTools, proceed with registration
6481+ // The proxy-dispatch tool will be registered via the OpenAI functions format
6482+ if ( isUnDef ( llmInstance ) || typeof llmInstance . withMcpTools != "function" ) {
6483+ parent . fnI ( "warn" , "Model doesn't have withMcpTools method, but proxy-dispatch tool should still be registered via functions interface." )
6484+ }
6485+ } else if ( isUnDef ( llmInstance ) || typeof llmInstance . withMcpTools != "function" ) {
6486+ // Check if LLM actually supports function calling (non-proxy mode)
64706487 parent . fnI ( "warn" , "usetools=true but model doesn't support function calling. Falling back to action-based mode." )
6471- parent . _useToolsActual = false // Track actual capability
6488+ parent . _useToolsActual = false // Confirm action-based mode
64726489 return llmInstance
6490+ } else {
6491+ parent . _useToolsActual = true // Confirm function calling is supported
64736492 }
6474-
6475- parent . _useToolsActual = true // Function calling is supported
64766493 var updated = llmInstance
64776494 parent . fnI ( "info" , `Registering MCP tools on LLM via tool interface...` )
64786495
@@ -7600,6 +7617,29 @@ MiniA.prototype._startInternal = function(args, sessionStartTime) {
76007617 this . _isInitialized = false
76017618 }
76027619
7620+ // Pre-determine _useToolsActual BEFORE init() to ensure correct prompt template
7621+ var usingMcpProxy = toBoolean ( args . mcpproxy ) === true
7622+ var hasMcpProxyConnection = Object . keys ( this . _mcpConnections || { } ) . some ( function ( id ) {
7623+ return id === md5 ( "mini-a-mcp-proxy" ) || id . indexOf ( "mini-a-mcp-proxy" ) >= 0
7624+ } )
7625+
7626+ if ( usingMcpProxy && hasMcpProxyConnection ) {
7627+ // MCP proxy mode always uses function calling
7628+ this . _useToolsActual = true
7629+ this . fnI ( "info" , "Pre-setting _useToolsActual=true for MCP proxy mode before init()" )
7630+ } else if ( this . _useTools && isArray ( this . mcpTools ) && this . mcpTools . length > 0 ) {
7631+ // Check if LLM supports function calling (non-proxy mode)
7632+ this . _useToolsActual = isDef ( this . llm ) && typeof this . llm . withMcpTools === "function"
7633+ if ( ! this . _useToolsActual ) {
7634+ this . fnI ( "info" , "Pre-setting _useToolsActual=false (LLM doesn't support function calling)" )
7635+ } else {
7636+ this . fnI ( "info" , "Pre-setting _useToolsActual=true (LLM supports function calling)" )
7637+ }
7638+ } else {
7639+ // No tools or usetools=false
7640+ this . _useToolsActual = false
7641+ }
7642+
76037643 this . init ( args )
76047644 this . _registerMcpToolsForGoal ( args )
76057645
0 commit comments