MCP tool calling method and device for large language model and storage medium
By performing intent prediction and resource preloading during user input, the problem of low efficiency in collaborative response when large models call MCP tools is solved, achieving more efficient resource utilization and user interaction experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-04-03
AI Technical Summary
When large models call the MCP tool, the collaborative response efficiency is low, especially in high-concurrency scenarios where the startup latency is too long, which affects the user experience in real-time interactive scenarios.
By predicting intent during user input, the resources of the MCP tool are preloaded based on the confidence level of the predicted intent category, and the preloaded MCP tool is used to execute the call instruction directly when the target intent matches the predicted intent, thus optimizing the resource allocation and instruction generation process.
It significantly shortens the collaborative response time between large models and MCP tools, optimizes the user interaction experience, avoids resource waste and unnecessary waiting, and improves the response efficiency of real-time interactive scenarios.
Smart Images

Figure CN121785743A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer network technology, and in particular to a method, device and storage medium for calling MCP tools for large language models. Background Technology
[0002] In scenarios where large models call tools, MCP (Model Context Protocol) allows models to directly call external services such as APIs, databases, and file systems using natural language commands.
[0003] When the MCP tool is invoked for the first time or when faced with high-concurrency tool invocation requests, the tool needs to complete a series of pre-operations, such as runtime environment initialization, hardware and software resource scheduling and allocation, and establishing communication connections with the large model and external services. These operations significantly increase the overall time taken for the large model to go from receiving user input to outputting the final result, resulting in low collaborative response efficiency between the large model and the MCP tool.
[0004] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0005] The main purpose of this application is to provide a method, device and storage medium for calling the MCP tool for a large language model, which aims to solve the technical problem of low collaborative response efficiency between the large model and the MCP tool when calling the MCP tool.
[0006] To achieve the above objectives, this application proposes a method for invoking the MCP tool of a large language model, the method comprising: In response to an input action targeting a large language model, a predicted intent category for the received temporary input fragment is generated based on the multi-dimensional features corresponding to the temporary input fragment. If the confidence level of the predicted intent category is greater than the preset confidence level, the resource preloading process of the MCP tool corresponding to the predicted intent category is triggered; The target intent category is determined based on the received complete input content, and an MCP invocation instruction is generated according to the target intent category; If the target MCP tool matching the target intent category is the same as the MCP tool, the MCP invocation instruction is executed according to the interface protocol of the MCP tool.
[0007] In one embodiment, the step of determining the target intent category based on the received complete input content and generating an MCP invocation instruction according to the target intent category includes: Based on the received complete input content, determine the target intent category; The target MCP tool and its parameter template are determined based on a preset mapping library to match the target intent category. The MCP invocation instruction is generated based on the target MCP tool and the parameter template.
[0008] In one embodiment, before the step of executing the MCP invocation instruction according to the interface protocol of the MCP tool, the MCP tool invocation method of the large language model further includes: If the target MCP tool matching the target intent category is the same as the MCP tool, obtain the preceding task and the current task corresponding to the MCP invocation instruction; If the semantic similarity between the current task and the preceding task is less than a preset similarity, the step of executing the MCP call instruction according to the interface protocol of the MCP tool is performed.
[0009] In one embodiment, after the steps of obtaining the preceding task and the current task corresponding to the MCP invocation instruction if the target MCP tool matching the target intent category is the same as the MCP tool, the MCP tool invocation method of the large language model further includes: If the semantic similarity between the current task and the preceding task is greater than or equal to a preset similarity, the MCP call instruction is executed according to the interface protocol of the preceding MCP tool corresponding to the preceding task.
[0010] In one embodiment, the step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category if the confidence level of the predicted intent category is greater than a preset confidence level includes: If the confidence level of the predicted intent category is greater than the preset confidence level, determine the resource preloading operation level corresponding to the confidence level; Determine the hierarchical resource ready actions corresponding to the resource preloading operation level; The resource loading action is executed during the hierarchical resource readiness action.
[0011] In one embodiment, after the step of determining the hierarchical resource readiness action corresponding to the resource preloading operation level, the MCP tool invocation method of the large language model further includes: Based on the current idle resources, determine the resource occupancy rate of the hierarchical resource ready actions; If the resource occupancy rate is less than or equal to the preset occupancy rate, execute the resource loading action of the hierarchical resource ready action; Otherwise, the resource preloading operation level is reduced, and the process jumps to the step of determining the hierarchical resource ready action corresponding to the resource preloading operation level.
[0012] In one embodiment, before the step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category, the MCP tool invocation method of the large language model further includes: If the confidence level of the predicted intent category is greater than the preset confidence level, determine whether there is an MCP tool that matches the predicted intent category and is in a loading state; If not, then execute the step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category.
[0013] In one embodiment, the step of generating a predicted intent category for a temporary input fragment based on multi-dimensional features corresponding to the received temporary input fragment in response to an input action for a large language model includes: In response to an input action targeting a large language model, the semantic feature vector, context feature vector, and behavioral feature vector corresponding to the temporary input fragment are obtained; By concatenating the semantic feature vector, the context feature vector, and the behavior feature vector, a multi-dimensional feature set is obtained. The preset classifier outputs the predicted intent category and its confidence level of the target feature vector. If the target MCP tool is different from the MCP tool, the weights of the preset classifier are updated based on the error direction propagation function.
[0014] In addition, to achieve the above objectives, this application also proposes an XX device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the MCP tool invocation method for large language models as described above.
[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the MCP tool invocation method of the large language model as described above.
[0016] One or more technical solutions proposed in this application have at least the following technical effects: By performing intent prediction during user input and triggering the preloading of MCP tool resources corresponding to the predicted intent category when the confidence level of the predicted intent category exceeds a preset confidence level, the tool resource loading step, which traditionally needs to be executed serially after user input, is transformed into a parallel preparation step during the input process. This eliminates the need for large models to redundantly execute intent analysis and tool matching steps after receiving complete input, avoiding the time-consuming process of waiting for MCP tool resource loading after user input and the resource waste and ineffective waiting caused by blindly starting the MCP tool process. This ensures that the target intent and the predicted intent are matched. Figure 1 In scenarios where the MCP tool is preloaded, the calling instructions can be executed directly, improving the collaborative response efficiency between the large model and the MCP tool, while ensuring the smoothness of instruction execution and optimizing the user experience during the interaction with the large language model. Attached Figure Description
[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic diagram of the device's functional modules in the MCP tool invocation method of the large language model of this application. Figure 2 A flowchart illustrating the first embodiment of the MCP tool invocation method for the large language model of this application; Figure 3 A flowchart illustrating the second embodiment of the MCP tool invocation method for the large language model of this application; Figure 4 A flowchart illustrating the process obtained by combining various embodiments provided for the third embodiment of this application; Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the MCP tool invocation method of the large language model in this embodiment of the application.
[0020] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0021] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0022] The main solution of this application embodiment is: in response to an input action for a large language model, a predicted intent category of the temporary input fragment is generated based on the multi-dimensional features corresponding to the received temporary input fragment; If the confidence level of the predicted intent category is greater than the preset confidence level, the resource preloading process of the MCP tool corresponding to the predicted intent category is triggered; The target intent category is determined based on the received complete input content, and an MCP invocation instruction is generated according to the target intent category; If the target MCP tool matching the target intent category is the same as the MCP tool, the MCP invocation instruction is executed according to the interface protocol of the MCP tool.
[0023] In this embodiment, for ease of description, the following description will focus on the execution entity being the MCP tool of the large language model calling the device.
[0024] The current common process for large models to call MCP tools is "user input → large model understanding → generation of MCP calling instructions → tool execution → result return → large model processing and output". This model has the following latency issues: First, large models take hundreds of milliseconds to several seconds to understand user input and generate instructions. This process is "passive response" and can only start processing after the user has completed the input. Second, the initialization, resource allocation, and connection establishment of the MCP tool require additional time, especially in the first use of the tool or in high-concurrency scenarios, where startup latency can account for more than 40% of the total latency. Third, some user inputs have obvious task correlations, such as continuous data analysis instructions. The traditional mode does not utilize this correlation for pre-processing, resulting in repeated understanding and calls that consume time.
[0025] Current optimization solutions mostly focus on improving the execution efficiency of the MCP tool itself or optimizing network transmission speed, without addressing the core latency issue from the perspectives of "call process reconstruction" and "user intent prediction". As a result, the collaborative response speed between large models and MCP tools cannot meet the needs of real-time interactive scenarios such as online customer service and real-time data analysis, and the user experience is greatly reduced.
[0026] Based on this, this application provides a solution that completes intent prediction during user input and triggers the preloading of MCP tool resources corresponding to the predicted intent category when the confidence level of the predicted intent category is greater than a preset confidence level. This transforms the tool resource loading step, which traditionally needs to be executed serially after user input, into a parallel preparation step during the input process. This eliminates the need for large models to redundantly execute intent analysis and tool matching steps after receiving complete input, avoiding the time-consuming process of waiting for MCP tool resource loading after user input and the resource waste and ineffective waiting caused by blindly starting the MCP tool process. This ensures that the target intent and the predicted intent are matched... Figure 1 In scenarios where the MCP tool is preloaded, the calling instructions can be executed directly, improving the collaborative response efficiency between the large model and the MCP tool, while ensuring the smoothness of instruction execution and optimizing the user experience during the interaction with the large language model.
[0027] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, personal computer, mobile phone, etc., or an electronic device that can realize the above functions, a large language model MCP tool calling device, etc.
[0028] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0029] Specifically, please refer to Figure 1 The MCP tool invocation device for large language models includes a real-time intent prediction module, a hierarchical resource preloading module, an instruction optimization module, and a state reuse module. The real-time intent prediction module constructs a lightweight intent recognition model based on the contextual semantics and behavioral features of user input, enabling real-time intent inference during the user input process and breaking the passive mode of "processing only after complete input." The hierarchical resource preloading module allocates resources, establishes connections, and pre-configures parameters for the MCP tool in stages according to the confidence level of intent prediction, maximizing startup latency while ensuring resource utilization efficiency. The instruction optimization module reduces the decision-making time for large model instruction generation and improves invocation accuracy by establishing a dynamically updated user intent-MCP tool-invocation parameter mapping library. The state reuse module reuses the MCP tool resources and execution states of preceding tasks for continuously related tasks, avoiding repeated initialization and connection time consumption. Based on this, the four core modules of intent prediction, resource scheduling, instruction optimization, and state reuse are used in conjunction to reduce the startup latency of the MCP tool based on intent prediction and hierarchical preloading mechanism; the instruction optimization module reduces the time spent generating instructions for large model calls; and in continuous associated tasks, the state reuse module significantly shortens the latency of the entire chain of subsequent tasks, thereby optimizing the latency of large model calls to the MCP tool.
[0030] The following uses the example of the MCP tool of the large language model calling the device to illustrate this embodiment and the following embodiments.
[0031] based on Figure 1 The present application provides a method for calling the MCP tool of a large language model, which calls the functional modules of the device. Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the MCP tool invocation method for the large language model of this application.
[0032] In this embodiment, the MCP tool invocation method of the large language model includes steps S10 to S40: Step S10: In response to the input action for the large language model, generate the predicted intent category of the temporary input fragment based on the multi-dimensional features corresponding to the received temporary input fragment.
[0033] In this embodiment, input actions for the large language model refer to information input actions initiated by the user through the text input box or voice input module of the input interface of a terminal such as a computer or smartphone, including text input and voice input. Temporary input fragments refer to staged input data that has not yet been finalized and submitted during the user's input process, such as an incomplete sentence like "convert the document to..." or an incomplete sentence after speech-to-text transcription. Multi-dimensional features include semantic features, contextual features, and behavioral features. Semantic features are extracted using a lightweight BERT model, contextual features are extracted from historical interaction logs, and behavioral features include data such as input rate, pause time, and historical preferences collected using input monitoring technology. Predicted intent category refers to the category of potential user needs inferred based on temporary input fragments.
[0034] As an optional implementation, intent prediction can be achieved through an ERT model. Specifically, when a user triggers an input operation, the program sends a data transmission request to the MCP tool calling device of the large language model. At this time, the real-time intent prediction module responds to the input action for the large language model, inputting the input fragment into a lightweight BERT (Bidirectional Encoder Representations from Transformers, a pre-trained language model based on the Transformer architecture) model. The model captures the semantic association between words through its bidirectional attention mechanism, outputting a 768-dimensional semantic feature vector. Simultaneously, the context feature extraction submodule is activated to parse the first three rounds of dialogue data in the historical interaction log, generating a 768-dimensional context summary vector through keyword extraction and semantic condensation. Finally, the behavior feature acquisition submodule is activated to count the input rate (unit: words / second) and the pause time of adjacent input units (unit: milliseconds) through the timing module, and generate call preference labels by combining the user's historical MCP tool call records, thereby obtaining semantic feature vectors, context feature vectors, and behavior feature vectors. Subsequently, through feature concatenation and MLP classifier processing, the three types of feature vectors are concatenated to obtain a multi-dimensional feature set, which is then input into a preset classifier. The classifier outputs the predicted intent category and confidence level of the target feature vector. The classifier output formula is shown below: .
[0035] Where W is the classifier weight matrix, b is the bias term, I is the predicted intent category, Vsem is the semantic feature, Vctx is the contextual feature, and Vbeh is the behavioral feature. It is a normalization function, and P is the confidence level of the corresponding intention (range 0-1).
[0036] For example, when a user inputs "Please compile statistics for xx month of 20xx", this temporary input fragment (input rate 3 words / second, window length set to 5) is captured. At this time, the semantic vectors corresponding to "statistics" and "xx month of 20xx" are extracted using lightweight BERT. The dialogue summary vectors of the previous 3 rounds of "querying monthly sales data" are extracted from the historical logs. The input rate is 3 words / second, the average pause time is 200 milliseconds, and the call preference label is 1. Then, these are concatenated into a multi-dimensional feature set. The obtained multi-dimensional features are then preprocessed and input into an MLP classifier. The outputs have a probability of 0.85 for "data statistics", a probability of 0.12 for "formula calculation", and a probability of 0.03 for "format conversion". Finally, the predicted intent category is determined to be "data statistics" with a confidence level of 0.85.
[0037] As another alternative implementation, LSTM (Long Short-Term Memory) can be used. The system uses a combination of long and short term gating networks (LSTM) and an attention mechanism to determine the predicted intent category. Specifically, the real-time intent prediction module uses pre-defined processing tools to convert each word in the temporary input segment into a low-dimensional vector. It then processes the word vector sequence using an LSTM neural network to capture temporal dependencies in the text to extract semantic features. Next, it extracts grammatical features using part-of-speech tagging. Simultaneously, it calculates the similarity between the current temporary segment and the user's historical input text vectors based on cosine similarity to extract contextual features. Temporal analysis techniques are also used to process temporal data during the input process. Finally, the multi-dimensional features are input into the LSTM+attention mechanism classification model. The attention mechanism strengthens the influence of key features on intent judgment and outputs the predicted intent category and confidence level.
[0038] This embodiment achieves early prediction of user intent through the analysis of multi-dimensional features, providing a direct basis for subsequent MCP tool matching and avoiding the blind activation of MCP tools.
[0039] Step S20: If the confidence level of the predicted intent category is greater than the preset confidence level, the resource preloading process of the MCP tool corresponding to the predicted intent category is triggered.
[0040] The confidence level of the aforementioned predicted intent category is a quantitative value of the reliability corresponding to the predicted intent category, ranging from 0 to 1. The resource preloading process is the process of loading the resources required for the MCP tool to run, such as program code, dependency libraries, and memory space, into the system's running memory in advance.
[0041] In this implementation, after receiving the predicted intent category and its corresponding confidence level, the resource preloading module compares it with a pre-stored preset confidence level to determine whether the predicted intent category has reliable preloading value. When the confidence level is greater than the preset confidence level, the module queries a preset mapping database of "intent category - MCP tool" to determine the MCP tool corresponding to the predicted intent category. Then, using memory mapping technology, the executable file and dependent dynamic link libraries of the MCP tool are mapped to the system's physical memory. Simultaneously, the tool's runtime environment is initialized, completing resource preloading. For example, if the predicted intent category is "data statistics" with a confidence level of 0.85 (greater than the preset 0.6), the mapping table matches the MCP tool to a database query MCP tool. An initialization command is then sent to the tool's server. The tool server loads its runtime environment, allocates 2GB of memory, establishes a long connection with the system, and returns a startup completion signal.
[0042] As an alternative implementation, an idle process can be woken up from the system process pool, and the runtime resources of the "Database Query MCP Tool" can be loaded into the memory space of the idle process to complete the pre-initialization of the tool. At the same time, the already created process can be reused to avoid the time consumption of process creation, quickly complete the pre-loading of MCP tool resources, and improve the system resource utilization.
[0043] This embodiment analyzes the confidence level and the pre-set confidence level to ensure the reliability of the predicted intent. When the confidence level meets the conditions, it directly triggers the resource preloading process of the MCP tool corresponding to the predicted intent category, realizing the targeted pre-start of the MCP tool corresponding to the intent category. This avoids the waste of resources caused by blindly starting tools, or the excessive system resource occupation, load surge and overall response efficiency decline caused by directly starting all MCP tools.
[0044] Step S30: Determine the target intent category based on the received complete input content, and generate an MCP invocation instruction according to the target intent category.
[0045] The complete input content mentioned above refers to all the input data submitted by the user after completing the input operation, i.e., the user's final expression of needs. This complete input content can be the same as the content of the temporary input fragment. For example, if the user enters half of the content, stops inputting, and performs a "confirmation" operation such as pressing the send button, the complete input content is equivalent to the content of the temporary input fragment. The target intent category is the actual need category determined based on the user's complete input content. The MCP invocation command, on the other hand, is the instruction data used to trigger the MCP tool to execute a specific task, containing information such as the tool identifier, task parameters, and execution requirements.
[0046] In this embodiment, after receiving complete input content, the target intent category can be calculated based on the received complete input content using the same calculation method as in step S10. After obtaining the target intent category, the corresponding instruction template can be obtained by querying the "Target Intent-MCP Instruction Template" mapping library, and the extracted parameters can be filled into the template using template filling technology to generate a standard calling instruction with a standardized format that can be directly recognized and executed by the MCP tool. As another alternative implementation, a structured instruction generation scheme in JSON format can be adopted. The required fields of the instruction are determined according to the target intent category, the extracted key parameters are filled into the corresponding fields, and a JSON format MCP call instruction containing multiple key fields is generated. At the same time, the instruction is syntax-validated to ensure that the instruction can be parsed by the MCP tool.
[0047] Step S40: If the target MCP tool matching the target intent category is the same as the MCP tool, execute the MCP call instruction according to the interface protocol of the MCP tool.
[0048] In this embodiment, the interface protocol of the MCP tool is the data interaction specification between the MCP tool and the calling system, which includes information such as communication protocol (e.g., HTTP, gRPC), data format (e.g., JSON, Protobuf), and interface address.
[0049] In this embodiment, the predicted intent category is generated based on temporary input fragments. Even if the confidence level is met, there is still a small probability that the user may subsequently correct the intent with their input. For example, if the initial input is "Calculate data A...", the predicted MCP tool is a data statistics MCP tool. However, if the user's final input is "Calculate the format conversion of data A", the corresponding MCP tool will be a format conversion MCP tool, and the two are not the same. Therefore, the target intent category, as a precise intent generated based on the complete input content, is the final basis for executing the MCP call instruction. Whether the target intent category and the predicted intent category are the same essentially determines whether "the pre-loaded MCP tool matches the final task to be executed". Therefore, to avoid tool misuse due to prediction bias, it is necessary to first determine whether the target MCP tool matched by the target intent category and the pre-loaded MCP tool corresponding to the predicted intent category are the same.
[0050] Specifically, by querying a pre-defined mapping database of "intent categories - MCP tools," the target MCP tool matching the target intent category can be determined, and then it can be determined whether the two tools are the same tool. When the target MCP tool and the MCP tool are the same, the interface protocol information of the "database query MCP tool" preloaded in step S20 can be queried. Then, the call command is converted into a request that the protocol can execute and the corresponding data query task is executed. Thus, when calling a large model, task processing is performed based on the preloaded MCP tool, which significantly shortens the MCP tool startup latency and improves the overall task response efficiency and user interaction experience.
[0051] After the MCP tool executes the call command, it sends a processing result back to the large language model. The large language model then organizes this result and outputs a result that matches the user's viewing needs. For example, if a user inputs "Query the total monthly sales orders of product A in xx month of 20xx", the database query MCP tool, after executing the query command, will return the raw processing result "{"product":"A","month":"20XX-XX","order_count":1286,"order_amount":568900}". Upon receiving this structured data, the large language model will automatically extract the core information and convert it into natural language: "The total monthly sales orders of product A in xx month of 20xx were 1286, with a total order amount of 568,900 yuan". Simultaneously, based on the user's historical interaction habits, it can supplement the results with month-on-month comparison data for similar products, such as "Order volume increased by 12% compared to the previous month," making the output more valuable and meeting the user's need for intuitive viewing. While outputting intuitive results, it can also store the tool status of the MCP tool corresponding to the current predicted intent category for future tool reuse.
[0052] Furthermore, if the user's final input does not correspond to the actual intent and the predicted intent (i.e., the target MCP tool differs from the actual MCP tool), the classifier weights W are updated through error backpropagation to optimize subsequent prediction accuracy. The weight update formula is: .
[0053] Where η is the learning rate (value 0.001), and L is the cross-entropy loss function, used to calculate the deviation between the predicted intent and the actual intent. It is the partial derivative of the loss function with respect to the old weights, used to calculate the contribution of each weight parameter to the error.
[0054] This embodiment provides a method for invoking the MCP tool of a large language model. The method allows for the generation of predicted intents and the preloading of resources for a high-confidence MCP tool during user input, eliminating the need to wait for user input to complete before loading resources. Furthermore, when the MCP tools corresponding to the target intent and the predicted intent are consistent, the invocation command can be directly executed through the preloaded MCP tool. This effectively shortens the overall time required for collaborative response between the large model and the MCP tool, optimizes the user experience during interaction with the large language model, and enables users to quickly obtain task processing results from the MCP tool after submitting a request, thereby improving the collaborative response efficiency between the large model and the MCP tool.
[0055] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3Step S30 also includes steps S31 to S33: Step S31: Determine the target intent category based on the received complete input content.
[0056] Step S32: Determine the target MCP tool and the parameter template of the target MCP tool corresponding to the target intent category according to the preset mapping library.
[0057] Step S33: Generate MCP calling instructions based on the target MCP tool and parameter template.
[0058] In this embodiment, the device's instruction optimization module can optimize the instruction generation process of the MCP tool for large language models through a dynamic mapping library, reducing the decision-making time of the large model and thus improving instruction accuracy. Specifically, after receiving complete input content, the intent prediction module can analyze it to obtain the target intent category.
[0059] After obtaining the target intent category, a pre-defined 3D mapping library of "intent category-tool type-call parameter template" is invoked. This mapping library is initialized through historical interaction data mining and manual annotation, and is updated in real time based on new interaction data. Using the target intent category as the search key, the corresponding adapted MCP tool type and associated call parameter template are queried in the mapping library, denoted as Map={I1:{T11:Temp11, T12: Temp12}, I2: {T21: Temp21},}, where I is the target intent category, T is the adapted MCP tool type, and Temp is the corresponding call parameter template, which includes required parameters and default values for optional parameters.
[0060] If the target intent category obtained from the query matches the predicted intent category generated in step S10, the target MCP tool is directly determined to be the MCP tool whose resources have been preloaded in step S20, without the need to re-match a new tool. Therefore, when the target intent category is the same as the predicted intent category, the target MCP tool is the preloaded MCP tool. When the two are inconsistent, a completely new target MCP tool is determined based on the mapping library query results.
[0061] After obtaining the target MCP tool and its parameter template, when generating the MCP call instruction based on both, the determined target MCP tool type, such as the tool ID and the corresponding parameter template, is input into the large language model as prompt information. The large language model does not need to re-determine the tool type and basic parameter format; it only needs to extract personalized parameters (such as document path, target format, output address, etc.) from the user's complete input and fill them into the corresponding fields of the parameter template. Subsequently, the format of the filled template is validated (to ensure parameter integrity and format standardization), and finally, a standardized MCP call instruction containing information such as tool identifier, task parameters, and execution requirements is generated.
[0062] Furthermore, after generating the calling command, the correctness of the command format is verified by a syntax parser. If there is a format error, it is automatically corrected based on the parameter template to avoid delays in tool call retry due to command errors.
[0063] This embodiment provides a method for calling MCP tools for large language models. By using template-based guidance, it simplifies the instruction generation task of large language models, avoids format errors or tool mismatch problems caused by free decision-making, and the generated standardized instructions can be directly adapted to the interface protocol of subsequent MCP tools, ensuring the smooth execution of instructions.
[0064] Based on any of the above embodiments, in the third embodiment of this application, the content that is the same as or similar to the above embodiments can be referred to the above description, and will not be repeated hereafter. Furthermore, before step S40, the MCP tool invocation method of the large language model further includes steps S50~S60: Step S50: If the target MCP tool matching the target intent category is the same as the MCP tool, obtain the preceding task and the current task corresponding to the MCP call instruction.
[0065] The preceding task is the task performed by the large language model before the user's current input. The current task, on the other hand, is the specific task required for this complete request.
[0066] In this embodiment, when the target MCP tool and the MCP tool are the same, it is also necessary to determine whether the currently executed task is a consecutive related task. For example, if the user inputs "first calculate the average value of data A", after the large language model calls the data statistics MCP to execute the corresponding task, the data statistics MCP tool is still in the loading completed state. However, during the resource release period of the data statistics MCP tool, if a related task, such as "calculate the standard deviation of data A", is received, both tasks require the use of the data statistics MCP tool. In this case, the preceding tool can be directly reused to execute the current MCP call instruction.
[0067] Therefore, when the target MCP tool is the same as the MCP tool, it is also necessary to detect the similarity between the current processing task and the preceding task, so as to determine whether tool reuse is necessary based on the similarity.
[0068] Step S60: If the semantic similarity between the current task and the preceding task is greater than the preset similarity, execute the step of executing the MCP call instruction according to the interface protocol of the MCP tool.
[0069] In this embodiment, semantic similarity is the degree of semantic fit between the current task and the preceding task. It is represented by semantic vector distance quantization and ranges from 0 to 1. The larger the value, the higher the correlation.
[0070] Specifically, the formula for calculating the semantic similarity S between the current task intent and the previous task intent is as follows: .
[0071] Where Vcurr is the semantic vector of the current task, and Vprev is the semantic vector of the preceding task.
[0072] A similarity threshold S0 = 0.7 can be set. When S < S0, it is determined to be a continuous associated task, that is, when the similarity between the two is less than the preset similarity, the step of executing the MCP call instruction through the interface protocol of the MCP tool in step 40 is executed.
[0073] Optionally, if the semantic similarity between the current task and the preceding task is greater than or equal to the preset similarity, the MCP tool of the preceding task is directly reused, that is, the MCP call instruction is executed according to the interface protocol of the preceding MCP tool corresponding to the preceding task.
[0074] Optionally, it is also possible to first determine whether the current task is a continuously related task, and then determine whether the target MCP tool is the same as the MCP tool.
[0075] It should be noted that when the time without new user input exceeds a preset threshold, or when the current task is not related to the preceding task, the MCP tool resources of the preceding task can be released to avoid long-term resource occupation. Therefore, if the semantic similarity between the current task and the preceding task is greater than the preset similarity, after executing step S40, the resources occupied by the preceding MCP tool corresponding to the preceding task can also be released.
[0076] For example, to help understand the implementation flow of the MCP tool invocation method for the large language model obtained by combining this embodiment with the first embodiment described above, please refer to... Figure 4 , Figure 4 A simplified flowchart illustrating the method for invoking the MCP tool in a large language model is provided, specifically: After user input begins, the intent prediction module monitors the input process in real time. Upon receiving an input segment, it calculates the predicted intent category and determines whether the confidence level of that category is greater than or equal to the threshold P1. If not, it proceeds to the stage of waiting for the next user input; if so, the resource scheduling module preloads the corresponding MCP tool resources. Once user input ends, the intent prediction module outputs the precise intent, i.e., the target intent recognition, based on the final output. Subsequently, the instruction optimization module matches a preset mapping library to generate an MCP call instruction. It then determines whether the current task is a consecutive related task. If so, the state reuse module reuses the state of the preceding tool, directly using the MCP tool of the preceding task. Otherwise, the resource scheduling module starts the preloaded tool to execute the instruction, where the target MCP tool is the same as the MCP tool. After the MCP tool completes the instruction, it returns the result, which is processed and output by the large model. The state reuse module then saves the current tool state, finally returning to the stage of waiting for the next user input, thus completing the entire cyclical process.
[0077] This embodiment provides a method for calling MCP tools for large language models. When calling an MCP tool, in addition to executing the calling instruction through the pre-loaded MCP tool, in the case of continuous input of related tasks by the user, the continuous task scenario can also be identified by semantic similarity comparison. This provides a decision basis for the state reuse module, enabling the tool process, connection state and other resources of the preceding task to be directly reused. This significantly shortens the end-to-end latency of the task in the continuous task scenario, greatly compresses the overall response time of the continuous task, reduces the resource overhead of the system frequently creating and destroying processes, and further reduces the scheduling latency caused by resource contention.
[0078] Based on any of the above embodiments, in the fourth embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. In addition, step S20 further includes steps S21 to S23: Step S21: If the confidence level of the predicted intent category is greater than the preset confidence level, determine the resource preloading operation level corresponding to the confidence level.
[0079] Step S22: Determine the hierarchical resource ready actions corresponding to the resource preloading operation level.
[0080] Step S23: Perform the resource loading action of the hierarchical resource ready action.
[0081] In this embodiment, when the resource preloading process of the MCP tool is triggered based on the confidence level output by the intent prediction module, the resource preparation process of the MCP tool can also be started in stages according to specific confidence levels, so as to avoid resource waste and maximize the compression of startup latency. Among them, the resource preloading operation level is a preloading intensity level divided according to the confidence value of the predicted intent category, while the hierarchical resource ready actions are the content that needs to be loaded.
[0082] For example, the confidence-based hierarchical resource preloading strategy is shown in the table below:
[0083] In the table above, P represents the confidence level of the predicted intent category, with a preset confidence level of 0.6. Process startup refers to allocating independent system process resources to the pre-loaded MCP tool, enabling it to have the basics to run. Loading the core algorithm library involves loading the algorithm library files required for the core functions of the MCP tool into the memory space of the started process, completing the deployment of core functions. Establishing a tool connection involves establishing a stable and reliable communication link between the collaborative processing platform and the MCP tool bound to the started process, completing the configuration of communication parameters. Secondary operations refer to advanced operations relative to "basic resource preloading," such as loading the tool's core code and establishing communication connections. These can be understood as supplementary actions such as parameter initialization and environment customization performed after the basic resources of the MCP tool are loaded. Pre-configuring tool parameters based on historical parameters refers to extracting parameters used by the user in the past when performing similar tasks from the system's task history repository and using these historical parameters as default values to pre-fill the parameter configuration of the pre-loaded MCP tool.
[0084] Based on the content of Table 1, assuming the user inputs the temporary fragment "convert the local test.docx file to", the predicted intent category is "document format conversion" with a confidence level of 0.93. The corresponding resource preloading operation level is level three preloading. Then, the table is looked up to match the hierarchical resource ready action corresponding to level three preloading as "level two operation + preconfigure tool parameters based on historical parameters". Then, the resource loading action corresponding to this ready action is executed to complete the resource preloading process of the MCP tool.
[0085] Furthermore, during resource preloading, a resource usage monitoring mechanism can be used to detect the current resource usage during preloading, ensuring that the preloading of resources does not affect the operation of other system services. Therefore, after step S22, steps S24-25 are also included: Step S24: Based on the current idle resources, determine the resource occupancy rate of the hierarchical resource ready actions.
[0086] Step S25: If the resource occupancy rate is less than or equal to the preset occupancy rate, execute the resource loading action of the hierarchical resource ready action.
[0087] In this embodiment, when the resource occupancy rate of the preloaded MCP tool exceeds the preset occupancy rate of the current system's idle resources, such as 50%, the preload level is automatically downgraded until the current loading level does not affect the operation of other system services. If it does not exceed the preset occupancy rate, the loading process proceeds normally.
[0088] Specifically, the formula for calculating resource utilization rate is as follows: .
[0089] Where R represents resource utilization, Rtool represents the amount of resources required for preloading the MCP tool, and Ridle represents the current amount of idle resources in the system. When R > 50%, the preloading level is reduced by one level, and this cycle continues until R ≤ 50%.
[0090] This embodiment provides a method for invoking the MCP tool for a large language model. Through a hierarchical preloading mechanism that includes confidence leveling, hierarchical action matching, and differentiated loading, the device can fully load the resources of the MCP tool in high-confidence scenarios, ensuring that subsequent tasks can be directly reused and achieving sub-second response times, thus meeting users' needs for interaction efficiency. At the same time, in low-confidence scenarios, lightweight loading is used to avoid unnecessary memory occupation, process creation, and other resource waste, thereby reducing system resource overhead and improving collaborative response efficiency.
[0091] Based on any of the above embodiments, in the fifth embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. On this basis, before triggering the resource preloading process, if the user inputs related tasks within a continuous time period, there may be MCP tools of the same category that are in a state of being loaded and not released after timeout. At this time, the tool can be directly marked as to be reused without triggering a new startup process.
[0092] For example, if the previous task was "calculate the average value of data A", and the data statistics MCP tool is in a loading and not yet released state after completing the task, and the received temporary input fragment is "calculate the...", then prediction determines that the data statistics MCP tool is still needed. However, since the tool is already in a loaded state, there is no need to reload it, avoiding the problem of a surge in system resource consumption and increased load caused by repeatedly starting the tool.
[0093] Therefore, if the confidence level of the predicted intent category is greater than the preset confidence level, it is determined whether there is an MCP tool in a loading state that matches the predicted intent category. If it exists, the tool is marked as reusable, and there is no need to trigger a new startup process. If it does not exist, the action of triggering the startup process of the MCP tool corresponding to the predicted intent category is executed. Based on this, the targeting of preloading is ensured, the resource retention value in continuous task scenarios is maximized, and the seamless connection of continuous tasks is achieved, while avoiding the problem of a surge in system resource consumption and increased load caused by repeated tool startup.
[0094] This application provides a large language model MCP tool invocation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the large language model MCP tool invocation method described in the first embodiment above.
[0095] The following is for reference. Figure 5 This document illustrates a structural diagram of an MCP tool invocation device suitable for implementing the large language model of the embodiments of this application. The MCP tool invocation device for the large language model in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The MCP tool call device for the large language model shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0096] like Figure 5As shown, the MCP tool invocation device for large language models may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the MCP tool invocation device for large language models. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the MCP tool invocation device for large language models to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows an MCP tool invocation device for large language models with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0097] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0098] The large language model MCP tool invocation device provided in this application, employing the large language model MCP tool invocation method described in the above embodiments, can solve the technical problem of low collaborative response efficiency between the large model and the MCP tool when calling MCP from a large model. Compared with the prior art, the beneficial effects of the large language model MCP tool invocation device provided in this application are the same as those of the large language model MCP tool invocation method described in the above embodiments, and other technical features in this large language model MCP tool invocation device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0099] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0100] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0101] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the MCP tool invocation method of the large language model in the above embodiments.
[0102] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory (EPROM, or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.
[0103] The aforementioned computer-readable storage medium may be included in the MCP tool invocation device of the large language model; or it may exist independently and not be assembled into the MCP tool invocation device of the large language model.
[0104] The aforementioned computer-readable storage medium carries one or more programs that, when executed by the MCP tool invocation device of the large language model, cause the MCP tool invocation device of the large language model to: In response to an input action targeting a large language model, a predicted intent category for the received temporary input fragment is generated based on the multi-dimensional features corresponding to the temporary input fragment. If the confidence level of the predicted intent category is greater than the preset confidence level, the resource preloading process of the MCP tool corresponding to the predicted intent category is triggered; The target intent category is determined based on the received complete input content, and an MCP invocation instruction is generated according to the target intent category; If the target MCP tool matching the target intent category is the same as the MCP tool, the MCP invocation instruction is executed according to the interface protocol of the MCP tool.
[0105] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0106] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0107] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0108] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the MCP tool invocation method of the aforementioned large language model. This solves the technical problem of low collaborative response efficiency between the large model and the MCP tool when calling MCP from a current large model. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the MCP tool invocation method of the large language model provided in the above embodiments, and will not be repeated here.
[0109] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for calling MCP tools for large language models, characterized in that, The methods for calling the MCP tool of the large language model include: In response to an input action targeting a large language model, a predicted intent category for the received temporary input fragment is generated based on the multi-dimensional features corresponding to the temporary input fragment. If the confidence level of the predicted intent category is greater than the preset confidence level, the resource preloading process of the MCP tool corresponding to the predicted intent category is triggered; The target intent category is determined based on the received complete input content, and an MCP invocation instruction is generated according to the target intent category; If the target MCP tool matching the target intent category is the same as the MCP tool, the MCP invocation instruction is executed according to the interface protocol of the MCP tool.
2. The method for calling the MCP tool of a large language model as described in claim 1, characterized in that, The step of determining the target intent category based on the received complete input content and generating an MCP invocation instruction based on the target intent category includes: Based on the received complete input content, determine the target intent category; The target MCP tool and its parameter template are determined based on a preset mapping library to match the target intent category. The MCP invocation instruction is generated based on the target MCP tool and the parameter template.
3. The method for calling the MCP tool of a large language model as described in claim 1, characterized in that, Before the step of executing the MCP invocation instruction according to the interface protocol of the MCP tool, the MCP tool invocation method of the large language model further includes: If the target MCP tool matching the target intent category is the same as the MCP tool, obtain the preceding task and the current task corresponding to the MCP invocation instruction; If the semantic similarity between the current task and the preceding task is less than a preset similarity, the step of executing the MCP call instruction according to the interface protocol of the MCP tool is performed.
4. The method for calling the MCP tool of a large language model as described in claim 3, characterized in that, After the steps of obtaining the preceding task and the current task corresponding to the MCP invocation instruction if the target MCP tool matching the target intent category is the same as the MCP tool, the MCP tool invocation method of the large language model further includes: If the semantic similarity between the current task and the preceding task is greater than or equal to a preset similarity, the MCP call instruction is executed according to the interface protocol of the preceding MCP tool corresponding to the preceding task.
5. The method for calling the MCP tool of a large language model as described in claim 1, characterized in that, The step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category if the confidence level of the predicted intent category is greater than the preset confidence level includes: If the confidence level of the predicted intent category is greater than the preset confidence level, determine the resource preloading operation level corresponding to the confidence level; Determine the hierarchical resource ready actions corresponding to the resource preloading operation level; The resource loading action is executed during the hierarchical resource readiness action.
6. The method for calling the MCP tool of a large language model as described in claim 5, characterized in that, After the step of determining the hierarchical resource ready action corresponding to the resource preloading operation level, the MCP tool invocation method of the large language model further includes: Based on the current idle resources, determine the resource occupancy rate of the hierarchical resource ready actions; If the resource occupancy rate is less than or equal to the preset occupancy rate, execute the resource loading action of the hierarchical resource ready action; Otherwise, the resource preloading operation level is reduced, and the process jumps to the step of determining the hierarchical resource ready action corresponding to the resource preloading operation level.
7. The method for calling the MCP tool of a large language model as described in any one of claims 1 to 6, characterized in that, Before the step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category, the MCP tool invocation method of the large language model further includes: If the confidence level of the predicted intent category is greater than the preset confidence level, determine whether there is an MCP tool that matches the predicted intent category and is in a loading state; If not, then execute the step of triggering the resource preloading process of the MCP tool corresponding to the predicted intent category.
8. The method for calling the MCP tool of a large language model as described in any one of claims 1 to 6, characterized in that, The step of generating the predicted intent category of the temporary input fragment based on the multi-dimensional features corresponding to the received temporary input fragment in response to an input action targeting a large language model includes: In response to an input action targeting a large language model, the semantic feature vector, context feature vector, and behavioral feature vector corresponding to the temporary input fragment are obtained; By concatenating the semantic feature vector, the context feature vector, and the behavior feature vector, a multi-dimensional feature set is obtained. The preset classifier outputs the predicted intent category and its confidence level of the target feature vector. If the target MCP tool is different from the MCP tool, the weights of the preset classifier are updated based on the error direction propagation function.
9. A device for calling MCP tools for large language models, characterized in that, The large language model MCP tool invocation device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the large language model MCP tool invocation method as described in any one of claims 1 to 8.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the MCP tool invocation method for a large language model as described in any one of claims 1 to 8.