Search

CN-121996253-A - MCP service automatic generation system and method based on program semantic understanding

CN121996253ACN 121996253 ACN121996253 ACN 121996253ACN-121996253-A

Abstract

The invention relates to an automatic generation system and method of MCP service based on program semantic understanding, in particular to the field of semantic understanding, which can realize accurate understanding and reasoning of deep logic semantics of program codes, automatically convert complex codes into accurate and reliable natural language service descriptions, remarkably improve the semantic fidelity and reliability of a generated service interface by fusing multidimensional evidence and continuous online feedback optimization, effectively reduce the error risk when an agent is called, and form a closed loop with self-perfecting capability, thereby intelligently supporting the construction and evolution of software ecology.

Inventors

  • QIN JUN
  • MAO XIANXIN
  • LEI JIAN
  • ZHANG JINGRU

Assignees

  • 北京领翼工软科技有限公司

Dates

Publication Date
20260508
Application Date
20260129

Claims (10)

  1. 1. The MCP service automatic generation system based on program semantic understanding is characterized by comprising a data extraction and map construction module, a semantic reasoning and symbolization module, a description generation and alignment module and a feedback learning and optimization module which are connected in sequence, wherein the data extraction and map construction module, the semantic reasoning and symbolization module, the description generation and alignment module and the feedback learning and optimization module are connected in sequence; The data extraction and map construction module is used for respectively extracting grammar structure information, running track information and associated document information of the target program code through a static semantic analyzer, a dynamic behavior analyzer and a context information collector which are executed in parallel in response to receiving the target program code, and fusing and constructing the three heterogeneous information into an original program semantic knowledge map containing various node types and side relations; The semantic reasoning and symbolizing module is used for carrying out cross-level message transfer and semantic relation reasoning on nodes and edges in the original program semantic knowledge graph by loading the original program semantic knowledge graph generated by the data extraction and graph construction module and utilizing a cascading model comprising a heterogeneous graph neural network and a multi-hop reasoning unit, identifying a high-level logic unit representing the program functional intention and generating an intention symbolizing graph with the nodes being symbolizing intention units; the description generation and alignment module takes the intention symbolization map generated by the semantic reasoning and symbolization module as input through a structure-aware cross-mode transducer model, and adopts a dual-attention alignment mechanism to generate a natural language description manuscript corresponding to symbolization intention units in the intention symbolization map; And the feedback learning and optimizing module is used for monitoring an execution result of the MCP service constructed according to the natural language description manuscript generated by the description generation and alignment module in real time through deployment of a semantic feedback analyzer and a strategy network, converting the execution result into a semantic feedback signal, and adjusting parameters of a cascade model in the semantic reasoning and symbolizing module and parameters of a structure-perceived trans-former model in the description generation and alignment module based on the semantic feedback signal.
  2. 2. The automatic generation system of MCP service based on program semantic understanding of claim 1, wherein in the data extraction and map construction module, the extraction and preprocessing process of three types of heterogeneous information by a static semantic analyzer, a dynamic behavior analyzer and a context information collector specifically comprises: The static semantic analyzer performs lexical analysis and grammar analysis on the target program code to generate an abstract grammar tree, performs data flow and dependency analysis based on the abstract grammar tree, and extracts a static semantic metadata set composed of grammar entities and structural relationships thereof, wherein the static semantic metadata set comprises a plurality of first elements, and each first element represents one grammar entity and attribute thereof; the dynamic behavior analyzer drives and executes target program codes through a preset test case set in an isolated sandbox environment, captures a function call sequence, parameter transfer, a return value and an abnormal event by using a pile-inserting technology, and forms a dynamic behavior metadata set for recording the behavior of the program during running, wherein the dynamic behavior metadata set comprises a plurality of second elements, and each second element represents one running event or state snapshot; The context information collector scans the engineering catalog and the associated version control system to which the target program code belongs, extracts and constructs a configuration file, a dependency library list, an application program interface document fragment and a version submission log to form a context semantic metadata set, wherein the context semantic metadata set comprises a plurality of third elements, and each third element represents a section of descriptive text.
  3. 3. The automatic generation system of MCP service based on program semantic understanding according to claim 2, wherein the process of constructing three types of heterogeneous information fusion into an original program semantic knowledge graph is specifically as follows: Firstly, initializing a map skeleton comprising nodes and grammar relation edges by taking grammar entities in a static semantic metadata set as references, wherein the nodes correspond to the grammar entities; Then, a fusion algorithm based on an evidence theory is adopted, and information in a dynamic behavior metadata set and a context semantic metadata set is used as evidence and fused into a map skeleton; the fusion algorithm calculates a comprehensive confidence coefficient for each node in the map skeleton, wherein the comprehensive confidence coefficient is determined by a first calculation item and a second calculation item, the calculation process of the first calculation item is that a dynamic behavior evidence subset which supports that the current node is judged to have a core function status is screened out from a dynamic behavior metadata set, and for each dynamic behavior evidence in the evidence subset, the self weight of the dynamic behavior evidence subset is multiplied by a correlation strength function value, and the multiplication results of all the supporting dynamic behavior evidences are accumulated to obtain a basic value of the first calculation item; The second calculation item is an average similarity contribution value between semantic vectors of all context description fragments related to the node and node vectors, the semantic vectors are obtained by carrying out embedded model conversion on descriptive texts in a context semantic metadata set, the node vectors are obtained by carrying out the same embedded model conversion on identification texts of grammar entities corresponding to the node, and the average similarity contribution value is obtained by calculating cosine similarity between the node vectors and the semantic vectors of each related context description fragment and calculating an average value; The fusion algorithm is also provided with a total evidence normalization factor, which is used for carrying out scale adjustment and combination on the basic value of the first calculation item and the average similarity contribution value of the second calculation item, and the comprehensive confidence coefficient is the result processed by the total evidence normalization factor; Finally, integrating the atlas skeleton, the comprehensive confidence coefficient of each node obtained by calculation through a fusion algorithm and the description text extracted from the context semantic metadata set to generate an original program semantic knowledge atlas, wherein the original program semantic knowledge atlas comprises: A node set, wherein elements of the node set are grammar entities defined in the static semantic metadata set; An edge set, wherein elements of the edge set are connection relations defined based on structural relations in a static semantic metadata set, associations in a dynamic behavior metadata set and semantic associations; the attribute set comprises attribute information attached to elements in the node set and elements in the edge set, wherein the attribute information comprises comprehensive confidence level, grammar entity type and description text extracted from the context semantic metadata set.
  4. 4. The automatic generation system of MCP service based on program semantic understanding of claim 3, wherein in the semantic reasoning and symbolizing module, the process of performing cross-level message transfer and semantic relation reasoning on nodes and edges in the original program semantic knowledge graph is specifically as follows: Firstly, loading the original program semantic knowledge graph, and constructing an initial feature vector corresponding to each element in a node set of the original program semantic knowledge graph, namely the grammar entity, wherein the initial feature vector is formed by splicing type information, comprehensive confidence and an embedded vector of a description text in an attribute set from the original program semantic knowledge graph corresponding to the grammar entity; Then, coding an original program semantic knowledge graph by adopting a multi-relation graph attention network, wherein the multi-relation graph attention network comprises a group of learnable parameters, independent learnable parameters are defined for each type of side relation in the original program semantic knowledge graph, the learnable parameters comprise a linear transformation matrix for feature transformation and an attention vector for calculating attention weight, the learnable parameters are randomly initialized at the beginning of model training and optimized by adopting a gradient descent method through an optimizer and an optimizer super-parameter in the training process, and in the information transmission process, the attention weight of each neighbor node under different relation types is calculated for each grammar entity serving as a target node, and the calculation process of the attention weight is that the current layer feature vector of the target node and the current layer feature vector of the target node are respectively transformed by using a linear transformation matrix corresponding to the type of side relation for one neighbor node connected with the target node; Then, splicing the two transformed feature vectors to form a combined vector; Finally, the original attention score is subjected to index normalization processing relative to the original attention scores of all neighbor nodes connected by the same type of side relation of the target node, and the obtained result is the attention weight of the neighbor node to the target node under the relationship type; And then, the target node updates the characteristic representation of the target node by weighting and aggregating the characteristic information of all neighbor nodes transformed by the corresponding linear transformation matrix under all relation types according to the attention weight, and obtains the enhanced semantic representation of each grammar entity fused with multi-hop and multi-relation context in the original program semantic knowledge graph through multiple iterations.
  5. 5. The automatic generation system of MCP service based on program semantic understanding according to claim 4, wherein the process of generating the intention symbolizing map specifically comprises the following steps: Performing high-order semantic relation completion through a multi-hop inference unit based on the enhanced semantic representation, wherein the multi-hop inference unit predefines a group of element path templates, and the element path templates represent high-order semantic relation modes to be inferred; in the original program semantic knowledge graph, searching a path instance meeting the condition for a node pair and a meta path template formed by the grammar entity, and calculating a path reasoning score for each found path instance, wherein the path reasoning score is calculated by the steps that for a given path instance connecting an initial node and a target node, the path instance is formed by a series of edges and intermediate nodes; firstly, calculating a semantic compatibility evaluation value between a starting node and a target node, wherein the value is obtained through a function taking an enhanced semantic representation vector of the starting node and an enhanced semantic representation vector of the target node as inputs, secondly, calculating a path support degree continuous product, which is calculated for each edge and the next node connected with each edge in the path instance, calculating a support degree value, which is obtained through a function taking the type of the edge and the enhanced semantic representation vector of the node pointed by the edge as inputs, and multiplying the support degree values corresponding to all edges in the path instance to obtain the path support degree continuous product, and finally, multiplying the semantic compatibility evaluation value and the path support degree continuous product to obtain the path reasoning score; The clustering process is realized by a differentiable sparse clustering algorithm which comprises a set of leavable parameters, a weight matrix and a bias vector, which are used for mapping the enhanced semantic representation vector to a fully-connected neural network layer of an intention space, and a plurality of prototype vectors representing the central positions of the symbolized intention units, and a sparse allocation weight for each grammar entity, wherein the sparse allocation weight is used for calculating the prototype vectors of one or more symbolized intention units according to the following rule, namely, for a given grammar entity, firstly obtaining the representation vector of the grammar entity in the intention space, then calculating the square of the Euclidean distance between the grammar entity representation vector and the prototype vector of each symbolized unit; Finally, according to the sparse distribution weights, performing the following operations to generate the intent symbolization map, namely firstly classifying grammar entities with obvious sparse distribution weights into corresponding symbolization intent units, wherein each symbolization intent unit is used as one node in the intent symbolization map, then, the feature vector of each symbolization intent unit is formed by weighting and aggregating enhanced semantic representation vectors of all member grammar entities according to the corresponding sparse distribution weights, and meanwhile, the weight of a connecting edge between two symbolization intent units is obtained by accumulating the intensity of all connections existing in the completed map between all member grammar entities respectively belonging to the two symbolization intent units and carrying out weighting calculation according to the sparse distribution weights.
  6. 6. The system for automatically generating an MCP service based on program semantic understanding according to claim 5, wherein the process of coding and fusing the intent symbolization map by the structure-aware cross-modal converter model in the description generation and alignment module specifically comprises the following steps: firstly, loading an intention symbolizing map, and acquiring feature vectors of all symbolizing intention units in the map and connection relations among the units, wherein the feature vectors are feature vectors which are output from a semantic reasoning and symbolizing module and correspond to each symbolizing intention unit; Then, executing node characteristic enhancement, namely for each symbolized intention unit in the intention symbolizing map, processing the characteristic vector of each symbolized intention unit by using a connection relation among units through a layer of graph convolution network, so that the updated characteristic vector of each symbolized intention unit fuses the characteristic information of the directly adjacent unit of the unit to obtain an enhanced node characteristic vector; Generating a structural position coding vector, namely generating a plurality of node sequences by random walk sampling aiming at the intention symbolizing atlas, and learning to obtain a fixed vector representation for each symbolizing intention unit in the intention symbolizing atlas by using a language model training method based on the node sequences, wherein the fixed vector representation is called the structural position coding vector; Sequencing and vector splicing, namely sequencing all symbolizing intention units according to a preset rule to form an input sequence, splicing each symbolizing intention unit in the input sequence with the enhanced node characteristic vector, the corresponding structure position coding vector and a standard sine position coding vector calculated according to the position of the unit in the input sequence to form a final input characteristic vector of the unit; The final input feature vectors of all symbolized intention units arranged in the sequence are formed into an input sequence, the input sequence is input into an encoder part of a structural-aware cross-modal transducer model, the structural-aware cross-modal transducer model comprises a large number of learnable parameters including self-attention and cross-attention module queries, keys, value linear transformation matrices, weight matrices and bias vectors of a feedforward neural network and weight matrices and bias vectors of the learnable aligned gating linear transformation layers, a structural bias matrix is introduced in the self-attention calculation process of the encoder, the value of each element of the structural bias matrix is determined according to the following rule, the shortest path distance between two symbolized intention units corresponding to the element is searched in the self-attention score calculation of the encoder, the structural bias matrix is used for being added as a bias term, so that structural information of intention symbolization is injected in the attention weight redistribution process, and the model can sense topological adjacent relation among units to obtain a fusion intention spectrum representing the symbolized intention spectrum of the symbol unit.
  7. 7. The automatic generation system of MCP service based on program semantic understanding according to claim 6, wherein the process of generating the natural language description manuscript by adopting the dual-attention alignment mechanism specifically comprises the following steps: generating a natural language description manuscript in an autoregressive manner using a decoder portion of a structurally perceived cross-modal transducer model based on a sequence of symbolic intended unit representations fused with structural semantics, performing a dual attention alignment calculation at each time step of the decoder: the first is intended cohesive attention, which in the decoder self-attention layer, uses the structure bias matrix to correct the original attention score generated in the decoder self-attention calculation; The second copy is to describe and produce the alignment attention, it is in the decoder cross attention layer, set up a learnable alignment gating value, the learnable alignment gating value is according to the following rule dynamic calculation of every time step, at first, obtain the query vector of the decoder in the present time step, meanwhile, obtain the hidden state that the part that the decoder has already produced in all time steps before and describe the text corresponds to and represent the vector sequence, and calculate the average value of all vectors of this sequence, get the context vector of the text already produced; Describing to generate an alignment threshold value, dynamically mixing context vectors from two information sources to generate a vocabulary of a current time step, wherein a first information source is a first context vector obtained by carrying out cross attention calculation based on a symbolized intention unit representation sequence fused with structural semantics, a second information source is a second context vector obtained by carrying out cross attention calculation based on a hidden state representation vector sequence of a generated part of descriptive text, the mixed context vector used for generating a final vocabulary is equal to the alignment threshold value multiplied by the first context vector, and a result of subtracting the alignment threshold value is added by the second context vector; The whole generation process is trained and optimized by minimizing a combined loss function, wherein the combined loss function is called total loss, and the value of the combined loss function is obtained by adding a standard sequence generation loss and a semantic alignment constraint loss multiplied by a preset positive weighting coefficient.
  8. 8. The automatic generation system of MCP service based on program semantic understanding of claim 7, wherein the feedback learning and optimizing module converts the actual calling execution result of the MCP service into a semantic feedback signal by a semantic feedback parser specifically comprises: The method comprises the steps of establishing a natural language description manuscript, carrying out real-time monitoring on each call of the MCP service constructed according to the natural language description manuscript, recording complete execution track information of the MCP service, constructing a multi-dimensional and fine-granularity semantic feedback signal vector based on the recorded execution track information, wherein each dimension of the vector corresponds to a preset semantic feedback type, the value of the vector is calculated according to an evaluation rule of the corresponding semantic feedback type, the semantic feedback type comprises a functional correctness dimension, a parameter matching degree dimension, an abnormal semantic relevance dimension and a performance attenuation dimension, and finally, the generated semantic feedback signal vector is used as the input of a follow-up credit allocation and optimization strategy.
  9. 9. The system for automatically generating an MCP service based on program semantic understanding according to claim 8, wherein the process of adjusting parameters and descriptions of a cascade model in a semantic reasoning and symbolizing module based on the signal to generate and align parameters of a structure-aware cross-modal converter model in the module is specifically as follows: Firstly, inputting the semantic feedback signal vector into a credit distribution network, wherein the credit distribution network takes an intermediate representation of an original program semantic knowledge graph and an intention symbolization graph based on which the MCP service is currently called as input, and outputs a two-dimensional credit distribution vector; meanwhile, the semantic feedback signal vector is synthesized into a scalar rewarding value through a preset rewarding function, and the calculating process of the rewarding function comprises the steps of firstly inputting the semantic feedback signal vector into a nonlinear transformation function for processing, wherein the nonlinear transformation function is used for mapping each component of the vector into a unified numerical range; Then, according to the credit allocation vector, the scalar rewarding value is decomposed into two layered rewarding values respectively corresponding to the semantic reasoning and symbolizing module and the description generating and aligning module, wherein the concrete calculation of the decomposition is that the scalar rewarding value is multiplied by a first element value of the credit allocation vector to obtain the layered rewarding value corresponding to the semantic reasoning and symbolizing module; Then, inputting the semantic feedback signal vector, the historical statistical information of the hierarchical rewards value and the gradient statistical information of the cascade model and the structure-aware cross-mode transducer model in the recent training into the strategy network, wherein the input information jointly forms the context according to which the strategy network makes a decision, namely the current state information of the system; Finally, applying adjustment suggestions by adopting a progressive knowledge distillation strategy to update the learnable parameters inside the cascade model and the structure-aware trans-former model; the implementation process of the progressive knowledge distillation strategy comprises the steps of firstly, defining a teacher model and a student model, wherein the teacher model refers to an integral formed by a cascade model and a description in a semantic reasoning and symbolizing module, which are deployed on the current line, and a cross-modal trans-former model for structure perception in the semantic reasoning and symbolizing module, the student model is a complete copy of the teacher model on structure, initial and internal learnable parameters of the student model are completely copied from the current learnable parameters of the teacher model, then, on the student model, according to an adjustment suggestion output by a strategy network, performing multi-step offline optimization on the learnable parameters by minimizing a combined loss function, generating and optimizing the combined loss function for the semantic reasoning and symbolizing module and the description, respectively, wherein, for the combined loss function of the semantic reasoning and symbolizing module, the value of the combined loss function is generated by taking a negative value of a layered rewards value corresponding to the semantic reasoning and symbolizing module as a first loss item, and for the combined loss function is generated for the given a given cascade model in the semantic reasoning and symbolizing module, the combined loss value is added as a weighted value of the first loss item, for the combined loss item is generated for the student model, and the combined loss value is aligned with the first model is added as a weighted value of the first loss item, the KL divergence used for measuring the difference between output distribution of a cross-modal transducer model for sensing the structure in the student model and a corresponding model in the teacher model under the same given input condition is taken as a second loss term, and the two loss terms are obtained through weighted addition; In each optimization iteration, according to the numerical value of the responsibility proportion in the credit allocation vector, selecting the semantic reasoning and symbolizing module or the description generating and aligning module to execute the knowledge distillation optimization, wherein in the combined loss function, a first loss term is multiplied by a first balance coefficient, and a second loss term is multiplied by a second balance coefficient; And synchronizing the learnable parameters of the student model which are stable after optimization with corresponding cascade models and structure-aware trans-former models in a teacher model, thereby finishing stable adjustment of the learnable parameters of the cascade models and the structure-aware trans-former models.
  10. 10. An automatic generation method of MCP service based on program semantic understanding is applied to an automatic generation system of MCP service based on program semantic understanding as claimed in any one of claims 1 to 9, and is characterized by comprising the following steps: Step S1, responding to a received target program code, extracting and fusing three types of heterogeneous metadata by analyzing static, dynamic and contextual semantics of the target program code in parallel, and constructing an original program semantic knowledge graph; Step S2, performing cross-level semantic reasoning and intention abstraction through a cascaded heterogeneous graph neural network and a multi-hop reasoning unit based on the original program semantic knowledge graph to generate an intention symbolizing graph taking symbolizing intention units as nodes; S3, taking the intention symbolization map as input, and generating a corresponding natural language description draft through a structure-aware cross-mode transducer model and a dual-attention alignment mechanism; And S4, monitoring the result of the MCP service constructed based on the description draft in actual calling, converting the result into a semantic feedback signal, and optimizing the learnable parameters of the cascade model and the trans-modal model through a progressive knowledge distillation strategy based on the signal.

Description

MCP service automatic generation system and method based on program semantic understanding Technical Field The invention relates to the field of semantic understanding, in particular to an automatic generation system and method of MCP service based on program semantic understanding. Background With the rapid development of artificial intelligence technology, intelligent agents with large language models as cores are gradually going deep into all layers of a software ecosystem to become important interaction and execution intermediaries in an operating system, basic software and industrial application, in order to enable the intelligent agents to safely and reliably call and control existing and massive software functions, the industry proposes middle layer protocol standards such as model context protocols and the like, and the core prospect is that, the left binary program, library function or source code module is automatically packaged and released as a callable service with a standardized natural language interface, so that an intelligent bridge for connecting an intelligent body and a bottom software resource is constructed, and the process is a key path for realizing ecological intelligent upgrading of software, and particularly has urgent application requirements in the fields of basic software and industrial software with high safety and high reliability requirements, such as integration and calling of an operating system kernel module and an industrial simulation core algorithm. However, the current implementation of automatic generation from program codes to standardized service interfaces faces a fundamental technical bottleneck, namely, serious understanding of deep logic semantics of the program codes is insufficient, the existing technical scheme mainly depends on two types of approaches, namely, a static program analysis tool based on rule and symbol execution, such as a disassembly framework Ghidra, which can parse and control flow analysis on codes, but is difficult to penetrate complex data flow and indirect call, complete intention and side effect of functions cannot be accurately inferred, a code characterization model based on statistical learning, such as CodeBERT, which can capture vocabulary and local grammar patterns through a large number of code corpus training, but shows obvious limitation when understanding complex logic semantics of cross functions and cross files, especially related to algorithm fine intention, abnormal processing paths, concurrent synchronization mechanism and specific field constraint, the deep layer methods are widely focused on surface grammar characteristics or local context of codes, lack of capability of efficient modeling and semantic reasoning on whole function behaviors, state transition and interaction with external environment, automatic consequences are direct effect, the fact that can directly generate error-prone interface, and cause error-prone conditions, such as critical error-prone to be caused by the fact that the critical error-prone software is not well-described, and the critical error-related to the critical information is introduced to the critical information, so that the critical information is well-being developed, the critical and the critical information is well-being developed, in particular, complex system codes, which can be deeply, accurately and interpretable for semantic understanding, become a core problem to be overcome in the technical field. Disclosure of Invention The invention aims at the technical problems in the prior art and provides an automatic generation system and method of MCP service based on program semantic understanding, which solves the problems in the background art through a data extraction and map construction module, a semantic reasoning and symbolization module, a description generation and alignment module and a feedback learning and optimization module. The invention solves the technical problems as follows, and particularly relates to an automatic generation system of an MCP service based on program semantic understanding, which comprises a data extraction and map construction module, a semantic reasoning and symbolizing module, a description generation and alignment module and a feedback learning and optimizing module which are connected in sequence, wherein the data extraction and map construction module is used for extracting data from the data extraction and map construction module; The data extraction and map construction module is used for respectively extracting grammar structure information, running track information and associated document information of the target program code through a static semantic analyzer, a dynamic behavior analyzer and a context information collector which are executed in parallel in response to receiving the target program code, and fusing and constructing the three heterogeneous information into an original program semantic knowledge map containing various node