Method and system, device, and medium for automatically generating code based on mcp protocol

The MCP protocol-based code generation engine dynamically processes project information to generate accurate and consistent Java code, addressing the limitations of existing solutions by integrating it into the business layer, thereby enhancing development efficiency and reducing errors.

HK40135041APending Publication Date: 2026-07-17BEIJING QINGSONG YIKANG INFORMATION TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
HK · HK
Patent Type
Applications
Current Assignee / Owner
BEIJING QINGSONG YIKANG INFORMATION TECHNOLOGY CO LTD
Filing Date
2026-05-27
Publication Date
2026-07-17

AI Technical Summary

Technical Problem

Existing code generation solutions struggle with poor accuracy, adaptability, and flexibility when dealing with complex projects, leading to inconsistent code styles, logical errors, and increased development time due to the reliance on predefined template scripts and artificial intelligence that cannot accurately understand project requirements.

Method used

A method and system utilizing a server-side code generation engine based on the MCP protocol to process data table structures, service names, and business names, generating Java code text that matches project specifications, and integrating it into the business layer using a large model, without relying on predefined templates, ensuring dynamic adaptation and accurate code generation.

Benefits of technology

The solution improves code generation efficiency and quality by reducing manual intervention, ensuring code consistency with project specifications, and facilitating seamless integration, thus accelerating project development and reducing errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The invention discloses a method, system and device for automatically generating codes based on an MCP protocol and a medium. The method comprises the steps of constructing a server-side code generation engine based on an MCP protocol, responding to a code generation request input by a user, analyzing the code generation request to obtain a data table structure, a service name and a service name, and triggering and generating a calling instruction to call the server-side code generation engine to process the data table structure, the service name and the service name, the method comprises the following steps: acquiring first dimension information, second dimension information and third dimension information, triggering to generate a Java code text matched with a project based on the three dimension information, then sending the Java code text to a client, calling a large model at the client to integrate the Java code text into a service level corresponding to a service name, and acquiring a target code. The method supports dynamic analysis and integration of project structures and business semantic hierarchies, codes matched with projects can be dynamically, accurately and efficiently generated, and actual requirements are met.
Need to check novelty before this filing date? Find Prior Art

Description

(19) State Intellectual Property Office (12) Invention Patent Application (10) Application Publication Number (43) Application Publication Date (21) Application Number 202511460898.5 (22) Application Date 2025.10.14 (71) Applicant Beijing Qingsong Yikang Information Technology Co., Ltd. Address 7th Floor, Block F, Yonghe Building, No. 28 Andingmen East Street, Dongcheng District, Beijing 100007 (72) Inventors Mei Zaoyang, Liu Junpei, Huang Xiandong, Zhang Da, Gao Yushi (74) Patent Agency Beijing Youyijia Intellectual Property Agency (General Partnership) 16075 Patent Attorney Sun Jianfeng (51) Int.Cl. G06F 8 / 30 (2018.01) G06F 8 / 36 (2018.01) G06F 8 / 71 (2018.01) G06F 8 / 73 (2018.01) G06F 8 / 76 (2018.01) (54) Invention Title: Method, System, Apparatus, and Medium for Automatically Generating Code Based on MCP Protocol (57) Abstract: This application discloses a method, system, apparatus, and medium for automatically generating code based on the MCP protocol. The method includes: constructing a server-side code generation engine based on the MCP protocol; responding to a user-inputted code generation request; parsing the code generation request to obtain the data table structure, service name, and business name; triggering a generation call instruction to call the server-side code generation engine to process the data table structure, service name, and business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; and triggering the generation of Java code text matching the project based on these three dimensions of information; then sending it to the client; and on the client, calling a large model to integrate the Java code text into the business level corresponding to the business name to obtain the target code. This method supports dynamic analysis and integration of project structure and business semantic levels, and can dynamically, accurately, and efficiently generate code matching the project, meeting practical needs. Claims 2 pages, Description 13 pages, Drawings 2 pages, CN 121300756 A 2026.01.09 CN 1 21 30 07 56 A 1. A method for automatically generating code based on the MCP protocol, characterized in that it includes: constructing a server-side code generation engine based on the MCP protocol; responding to a code generation request, parsing the code generation request to obtain a data table structure, service name, and business name, and triggering a generation call instruction; based on the call instruction, calling the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; based on the first-dimensional information, the second-dimensional information, and the third-dimensional information, triggering the generation of Java code text matching the project; and sending the Java code text to the client;In response to the client receiving the Java code text, the large model is invoked to integrate the Java code text into the business layer corresponding to the business name, thereby obtaining the target code. 2. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that, the construction of a server-side code generation engine based on the MCP protocol includes: developing an MCP protocol server using the Java language and establishing a connection with the client based on standard IO communication; configuring a code generation engine within the MCP protocol server, the code generation engine being used to parse information and generate hierarchical code files according to predefined project templates and rules. 3. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that configuring the code generation engine in the MCP protocol server includes: configuring the mapping relationship between different services and different project structures, project code generation rules, multiple sets of code templates supporting different project requirements, and a unified metadata parsing interface; wherein the code templates adopt the FreeMarker template engine, and the metadata parsing interface supports table structure parsing from multiple data sources; determining the query database framework, wherein the database framework is one of Mybatis, Mybatis-Plus, or Hibernate; reserving the business layer package name parameter, and dynamically specifying the business layer according to the input business layer. 4. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that, the step of calling the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information includes: parsing the data table structure to obtain one or more of the following: table name, field name, field type, primary key data, and foreign key data; converting the table name into a class name conforming to the project specification according to the configured naming rules; converting the field name into a parameterized attribute name and mapping it to a Java data type according to the field type; automatically generating association information based on the primary key data and the foreign key data; calling the corresponding project structure from a preset database based on the service name, denoted as the target project structure; wherein, the preset database contains several sets of mapping relationships between service names and project structures; if the business name exists in the target project structure, obtaining the hierarchical structure corresponding to the business name; the first-dimensional information includes the class name, attribute name, data type, and association relationship corresponding to the target project, the second-dimensional information includes the target project structure, and the third-dimensional information includes the hierarchical structure corresponding to the business name. 5. The method for automatically generating code based on the MCP protocol according to claim 4, characterized in that the step of automatically generating code based on the MCP protocol...The method for automatically generating code based on the MCP protocol according to claim 5 is characterized in that obtaining integrated information based on the first dimension information, the second dimension information, and the third dimension information includes: obtaining integrated information based on the first dimension information, the second dimension information, and the third dimension information; obtaining Java code text matching the project based on the integrated information and the second dimension information; and generating Java code text matching the project based on the Java code text and the third dimension information. 6. The method for automatically generating code based on the MCP protocol according to claim 5 is characterized in that obtaining integrated information based on the first dimension information, the second dimension information, and the third dimension information includes: integrating the class name, the attribute name, the data type, the association relationship, the target project structure, and the hierarchical structure corresponding to the target project to form an integrated information set containing complete information about the class and its hierarchical and structural position in the project. 7. The method for automatically generating code based on the MCP protocol according to claim 5, characterized in that, obtaining Java code text matching the project based on the integrated information and the second dimension information includes: determining a preset code generation template corresponding to the project; filling the integrated information into the preset code generation template to obtain Java code text matching the project, wherein the code generation template contains the basic structure and logic of Java code. 8. The method for automatically generating code based on the MCP protocol according to claim 5, characterized in that, generating Java code text matching the project based on the Java code text and the third dimension information includes: organizing the Java code text according to the target project structure and packaging it into a code package, wherein the structure of the code package matches the project's specifications and requirements. 9. The method for automatically generating code based on the MCP protocol according to claim 4, characterized in that, in response to the client receiving the signal of the Java code text, calling the large model to integrate the Java code text into the business layer corresponding to the business name to obtain the target code, includes: in response to the client receiving the signal of the Java code text, calling the large model, and according to the hierarchical structure information, inserting the Java code text into the business module and class corresponding to the hierarchical structure to obtain integrated code; performing correctness and completeness checks on the integrated code, and if the check conditions are met, using the integrated code that meets the conditions as the target code; if the check conditions are not met, dynamically triggering the correction of the integrated code, and using the corrected integrated code as the target code. 10. A system for automatically generating code based on the MCP protocol, characterized in that it includes: a construction module for constructing a server-side code generation engine based on the MCP protocol;A parsing module is used to respond to a user-inputted code generation request, parse the code generation request to obtain a data table structure, service name, and business name, and trigger a generation call instruction; a processing module is used to, based on the call instruction, call the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; a code text generation module is used to, based on the first-dimensional information, the second-dimensional information, and the third-dimensional information, trigger the generation of Java code text matching the project; a sending module is used to send the Java code text to the client; an integration module is used to, in response to the client receiving the signal of the Java code text, call the large model to integrate the Java code text into the business layer corresponding to the business name, and obtain the target code. Claims 2 / 2 Page 3 CN 121300756 A Method, System, Apparatus, and Medium for Automatically Generating Code Based on MCP Protocol Technical Field

[0001] This disclosure relates to the field of automatic software code generation technology, and particularly to a method, system, apparatus, and medium for automatically generating code based on the MCP protocol. Background Technology

[0002] The MCP protocol was launched and open-sourced by Anthrop. Its core objective is to build a secure bidirectional connection mechanism between large language models and external data sources and tools. This mechanism is of great significance for achieving efficient integration of large language models with external systems, enabling large language models to obtain data and tool support from external systems, thereby improving the breadth and depth of their applications.

[0003] In the field of code generation, most existing code generation solutions rely on predefined template scripts. This approach can meet the code generation needs of simple projects to a certain extent. Code with a basic structure can be quickly generated through preset templates. However, its limitations become apparent when facing complex project structures with multiple modules and services. Complex projects often have multiple interrelated modules and services, each with its own unique functions and requirements. Predefined template scripts are difficult to flexibly adapt to these diverse situations. They cannot be dynamically adjusted according to the specific needs of the project, resulting in generated code that cannot accurately reflect the actual architecture and functions of the project.

[0004] To compensate for the shortcomings of predefined template scripts, some solutions attempt to introduce artificial intelligence (AI) technology to assist in code generation. AI has powerful learning and reasoning capabilities and, theoretically, can generate code that meets the requirements based on the input. However, inconsistent code styles are a significant problem. Different developers have different coding styles, and AI-generated code cannot follow a unified style specification, which brings difficulties to subsequent code maintenance and team collaboration. Secondly, the accuracy of generated code is low; AI struggles to understand complex business requirements and technical details.There may be deviations, resulting in generated code that cannot fully meet actual needs. In many cases, the generated code has problems such as logical errors, syntax errors, or missing functions. In addition, due to the low accuracy of the generated code, developers often need to interact with artificial intelligence multiple times to correct and improve the generated code, which not only increases the development time cost but also reduces development efficiency. Therefore, existing code generation solutions still cannot meet the requirements for efficient and accurate code generation when dealing with complex projects. Summary of the Invention

[0005] In view of this, the embodiments of this disclosure provide a method, system, device, and medium for automatically generating code based on the MCP protocol, which can solve the problems of poor accuracy of generated code, poor adaptability to projects, high requirements for human experience, and poor flexibility in the prior art.

[0006] In a first aspect, embodiments of this disclosure provide a method for automatically generating code based on the MCP protocol, comprising: constructing a server-side code generation engine based on the MCP protocol; responding to a code generation request, parsing the code generation request to obtain a data table structure, a service name, and a business name, and triggering a generation call instruction; based on the call instruction, calling the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; triggering the generation of Java code text matching the project based on the first-dimensional information, the second-dimensional information, and the third-dimensional information; sending the Java code text to a client; responding to a signal from the client receiving the Java code text, calling a large model to integrate the Java code text into the business layer corresponding to the business name to obtain target code.

[0007] In a second aspect, embodiments of this disclosure also provide a system for automatically generating code based on the MCP protocol, comprising: a construction module, configured to construct a server-side code generation engine based on the MCP protocol; a parsing module, configured to respond to a code generation request, parse the code generation request to obtain a data table structure, a service name, and a business name, and trigger a generation call instruction; a processing module, configured to, based on the call instruction, call the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; a code text generation module, configured to, based on the first-dimensional information, the second-dimensional information, and the third-dimensional information, trigger the generation of Java code text matching the project; a sending module, configured to send the Java code text to a client; and an integration module, configured to, in response to a signal from the client receiving the Java code text, call a large model to integrate the Java code text into the business layer corresponding to the business name to obtain target code.

[0008] In a third aspect, embodiments of this disclosure also provide a computer device, employing the following technical solution: The computer device 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, the instructions being executed by the at least one processor to enable the at least one processor to execute any of the above-described methods for automatically generating code based on the MCP protocol.

[0009] In a fourth aspect, embodiments of this disclosure also provide a computer-readable storage medium storing computer instructions for causing a computer to execute any of the above-described methods for automatically generating code based on the MCP protocol.

[0010] In a fifth aspect, embodiments of this disclosure also provide a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of any of the above-described methods.

[0011] The method for automatically generating code based on the MCP protocol disclosed in this application firstly constructs a server-side code generation engine based on the MCP protocol. In response to the code generation request input by the user, the engine parses the code generation request to obtain the data table structure, service name, and business name, and triggers a generation call instruction. Then, based on the call instruction, the server-side code generation engine is called to process the data table structure, service name, and business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information. Based on these three-dimensional information, the engine triggers the generation of Java code text that matches the project and sends the Java code text to the client. Finally, in response to the client receiving the Java code text signal, the engine calls the large model to integrate the Java code text into the business level corresponding to the business name to obtain the target code. This method supports dynamic analysis and integration of project structure and business semantic level, does not rely on predefined templates, and can dynamically and flexibly adapt to the project structure corresponding to the requirements. At the same time, based on the secure bidirectional connection feature of the MCP protocol, the method realizes the automated process from user input of code generation request to final generation and integration of target code, effectively improving the efficiency and quality of code generation, reducing manual intervention, and accelerating the project development progress. Specification 2 / 13 pages 5 CN 121300756 A

[0012] The above description is only an overview of the technical solution of this disclosure. In order to better understand the technical means of this disclosure and to implement it according to the content of the specification, and to make the above and other objects, features and advantages of this disclosure more obvious and understandable, preferred embodiments are given below, and detailed description is provided in conjunction with the accompanying drawings. Description of Drawings

[0013] In order to more clearly illustrate the technical solution of the embodiments of this disclosure, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure, and are for those in the artFor ordinary technicians, other drawings can be obtained from these drawings without creative effort.

[0014] Figure 1 is a flowchart of the method for automatically generating code based on the MCP protocol provided in the embodiment of this disclosure.

[0015] Figure 2 is a schematic diagram of the method for obtaining first-dimensional information, second-dimensional information, and third-dimensional information provided in the embodiment of this disclosure.

[0016] Figure 3 is a structural schematic diagram of a computer device provided in the embodiment of this disclosure. Detailed Description

[0017] The embodiments of this disclosure will be described in detail below with reference to the accompanying drawings.

[0018] It should be clear that the following describes the implementation of this disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of this disclosure from the content disclosed in this specification. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. This disclosure can also be implemented or applied through other different specific implementations, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this disclosure. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this disclosure, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this disclosure.

[0019] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art should understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. In addition, other structures and / or functionalities besides one or more of the aspects set forth herein can be used to implement this device and / or practice this method.

[0020] It should also be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this disclosure. The drawings only show components related to this disclosure and are not drawn according to the actual number, shape, and size of the components in the actual implementation. In the actual implementation, the form, quantity, and proportion of each component can be arbitrarily changed, and the component layout may also be more complex.

[0021] In addition, specific details are provided in the following description to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that the aspects described can be practiced without these specific details.

[0022] Referring to FIG1, this application discloses a method for automatically generating code based on the MCP protocol, including: S100, constructing a server-side code generation engine based on the MCP protocol.

[0023] Specifically, it includes: S110, developing an MCP protocol server using Java language, and establishing a connection with the client based on standard IO communication; S120, configuring a code generation engine within the MCP protocol server, the code generation engine being used to parse information and, according to the predefined project template and rules, generate hierarchical code files.

[0024] For S110, specifically, it includes utilizing the secure bidirectional connection characteristics of the MCP protocol to build a communication channel between the server, the client, and external data sources, ensuring the security and integrity of data during transmission, for example, using encryption algorithms to encrypt the data to prevent data from being stolen or tampered with.

[0025] Further, a server socket is created using Java's ServerSocket class, listening on a specific port (e.g., 8080); when the client initiates a connection request, the server accepts the connection through the accept() method, establishing a standard IO communication channel with the client; the client and server can perform data read and write operations through InputStream and OutputStream. Java is a cross-platform programming language. Using Java to develop the server can ensure that the server can run stably on different operating systems. Standard IO communication is a universal communication method, which facilitates connection with various types of clients and enhances system compatibility.

[0026] For S120, developers can use open-source template engines (such as Freemarker) to implement the code generation engine. Predefined project templates (such as Java class templates, interface templates, etc.) are stored in a specified directory on the server. When a client's code generation request is received, the code generation engine generates Java code files that conform to the project specifications based on the business information in the request (such as data table structure, service name, business name), combined with the template and predefined rules. The code generation engine is an independent module, which is easy to maintain and extend. When the project specifications or templates change, only the templates and rules in the code generation engine need to be modified, without large-scale modifications to the entire server. Using predefined templates and rules can ensure that the generated code conforms to the project's unified specifications.

[0027] In this step, a server application is developed using the Java language. This application implements the MCP (Model-Code Protocol) protocol to receive code generation requests sent by the client. The server integrates a code generation engine, which can generate Java code that conforms to project specifications based on the input business information (such as data table structure, service name, and business name).

[0028] Through the MCP protocol, the communication between the client and the server is ensured to be unified and stable, facilitating cross-platform and cross-language integration.The code generation engine, as an independent module, is easy to maintain and extend; it utilizes Java's rich class libraries and frameworks to improve development efficiency and system stability.

[0029] S200, in response to the user's input code generation request, the code generation request is parsed to obtain the data table structure, service name, and business name, and a generation call instruction is triggered.

[0030] S300, based on the call instruction, the server-side code generation engine is called to process the data table structure, service name, and business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information.

[0031] S400, based on the first-dimensional information, second-dimensional information, and third-dimensional information, Java code text matching the project is triggered to be generated.

[0032] S500, the Java code text is sent to the client.

[0033] S600, in response to the client receiving the signal of the Java code text, the large model is called to integrate the Java code text into the business level corresponding to the business name to obtain the target code.

[0034] After receiving the Java code text, the client does not save the file directly. Instead, it calls a "large model" (referring to the intelligent integration module of the project structure). This module understands the directory structure of the current project (such as MVC layering and module division), automatically places the generated code into the correct package path, and updates the relevant configuration files (such as Spring's @ComponentScan and MyBatis' Mapper scanning path). For example, OrderServiceImpl is placed in the com.company.project.service.impl package and automatically registered in the Spring configuration. This step effectively avoids manual copying and pasting, prevents misplacement, and automatically updates the configuration to ensure that new code is loaded correctly. Even beginners do not need to be familiar with the project structure to correctly add code.

[0035] The method for automatically generating code based on the MCP protocol disclosed in this application, and the code generation system based on the MCP protocol implemented in Java, provide a complete end-to-end automated generation process from natural language input - AI intent recognition - code generation - code integration. It does not rely on specific AI programming tools, communicates with the client only through the MCP protocol, and has good compatibility and scalability. The generated code strictly follows project specifications and structure, reducing manual modification costs. It automatically writes the code to the specified location in the project, supports just-in-time compilation and execution. While simple AI generation takes 20-30 minutes, this solution only takes 3-5 minutes.

[0036] The method for automatically generating code based on the MCP protocol disclosed in this application effectively reduces the workload of manually writing code through automated code generation and integration processes, greatly shortening the development cycle. Developers can spend more time...The focus is on implementing and optimizing business logic. Using dynamically matched predefined templates and rules to generate code ensures that the generated code conforms to the project's unified specifications. The large model's code integration function avoids errors that may occur during manual code integration, improving code accuracy and stability. The server-client communication method based on the MCP protocol guarantees the system's cross-platform and cross-language integration capabilities. Clients can use different programming languages ​​and operating systems to communicate with the server, improving system applicability. Furthermore, the code generation engine and large model are independent modules, facilitating system maintenance and expansion. When project specifications or requirements change, only the corresponding modules need to be modified, without requiring large-scale modifications to the entire system.

[0037] This application implements an MCP protocol server using Java, without relying on third-party AI programming tools. It builds its own server using Java, ensuring stability and controllability, making it suitable for enterprise intranet deployment. The input is abstracted as "data model + business logic + project structure," making code generation more intelligent and closer to actual projects. Simultaneously, through large-scale model-level project integration, it not only generates code but also "understands" the project hierarchy, automatically completing file placement and configuration updates, achieving "generation in place." From request initiation to code deployment, the entire process is based on the MCP protocol, forming a reusable automated pipeline. This solution, through Java + MCP protocol + intelligent code generation + automatic project integration, constructs a complete automated link from "business input" to "usable code." It not only improves development efficiency but also fundamentally solves persistent problems such as "inconsistent code standards," "difficulty for beginners," and "excessive repetitive work." For Java project teams pursuing high quality, high efficiency, and sustainable evolution, it is an excellent, replicable, implementable, and scalable solution.

[0038] The method of S120 "Configuring the code generation engine in the MCP protocol server" specifically includes: S121, configuring the mapping relationship between different services and different project structures based on the database table.

[0039] Through this step, when a code generation request for different services is received, the corresponding project structure can be quickly determined according to the mapping relationship, thereby generating code that meets the requirements of the service in a targeted manner, avoiding code structure chaos, and improving the accuracy and adaptability of code generation.

[0040] S122, configuring project code generation rules.

[0041] The rules can involve code naming conventions, commenting conventions, code structure layout, etc. For example, it can be stipulated that the name of entity class must end with "Entity", the method name should use camelCase naming, and each method should be given a brief comment explaining its function. These rules can be stored in the configuration file, and the code generation engine will operate according to these rules when generating code; through this step, it can be ensured that the generated code conforms to the unified standard and improve the readability of the code.And maintainability, team members can more easily understand and modify the code, reducing communication costs and errors caused by inconsistent coding styles.

[0042] S123, configure multiple sets of code templates to support different project requirements. The code templates use the FreeMarker template engine. Manual 5 / 13 page 8 CN 121300756 A

[0043] For different types of projects, such as Web projects, desktop application projects and mobile application projects, different code templates are created respectively. Taking Web projects as an example, there may be templates for the controller layer, service layer and data access layer; desktop application projects may have templates for interface design and business logic processing. Each template is written using FreeMarker syntax and contains placeholders. These placeholders will be replaced according to specific business information during code generation. Through this step, the diverse needs of different projects can be met, the flexibility of code generation can be improved, and developers can choose the appropriate template according to the specific project to quickly generate code that conforms to the characteristics of the project and reduce the workload of repetitive code writing.

[0044] S124, configure a unified metadata parsing interface. The metadata parsing interface supports table structure parsing of multiple data sources.

[0045] Specifically, supported data sources can include common relational databases such as MySQL, Oracle, SQL Server, and PostgreSQL; developers implement a unified interface and write different implementation classes for different data sources; for example, for MySQL data sources, the implementation class will use the MySQL JDBC driver to connect to the database and query table structure information; for Oracle data sources, the Oracle JDBC driver will be used to perform corresponding operations. Regardless of which data source the project uses, the code generation engine can parse the table structure information through a unified interface, improving the system's compatibility and scalability. Developers do not need to write different parsing logic for different data sources, reducing development difficulty and maintenance costs.

[0046] S125, determine the query database framework, which is Mybatis, Mybatis-Plus, or Hibernate.

[0047] Specifically, the appropriate database framework should be selected based on the project's requirements and the team's technology stack. If the project has high requirements for control over SQL statements and the team is familiar with MyBatis, MyBatis can be selected; if it is desirable to simplify development and improve development efficiency based on MyBatis, MyBatis-Plus can be selected; if the project emphasizes Object-Relational Mapping (ORM) and has high requirements for the level of abstraction of database operations, Hibernate is preferred.

[0048] Different database frameworks have different characteristics and advantages. Selecting a suitable framework can improve the efficiency of database operations.Efficiency and ease of development; at the same time, the code generation engine can generate corresponding code according to the selected framework, so that the generated code matches the database operation method of the project.

[0049] S126, reserve the business layer package name parameter, and dynamically specify the business layer according to the input business layer.

[0050] In the code generation request, the user can input the package name of the business layer, such as "com.example.business.order"; when generating code, the code generation engine will determine the storage location and namespace of the business layer code according to this package name. For example, the generated order business logic class will be stored under the "com.example.business.order" package. Through this step, the flexibility of code generation is effectively increased. The user can dynamically specify the business layer according to the actual needs of the project, so that the generated code can better adapt to the architecture and organization of the project.

[0051] S121-S126 are all executed within the MCP protocol server. In this embodiment, by configuring the mapping relationship between different services and project structures, multiple code templates, and dynamically specifying business levels, customized code can be generated according to the specific needs of different projects to meet diverse business scenarios. The unified metadata parsing interface and clear code generation rules reduce the manual operation and repetitive work of developers in the code generation process, and speed up the code generation speed. At the same time, choosing a suitable database framework can improve the development efficiency of database operations. Following unified code generation rules and specifications, the generated code has good readability and consistency, which is convenient for team members to maintain and extend. The clear mapping relationship between different services and project structures also helps in the organization and management of code. It supports multiple data sources and different database frameworks, enabling the system to adapt to different technical environments. The reserved business layer package name parameters and modular configuration methods facilitate future functional expansion and upgrades of the system. Instruction manual, page 6 / 13, CN 121300756 A

[0052] The method of S200, "responding to the user's input code generation request, parsing the code generation request to obtain the data table structure, service name, business name, and triggering the generation call instruction," specifically includes: S210, obtaining the user's input code generation request on the client; S220, calling the large model in the client to parse the code generation request, obtaining the data table structure, service name, business name, and triggering the generation call instruction, which contains information such as the data table structure, service name, and business name, and is used to call the server-side code generation engine.

[0053] For example, the user inputs a prompt word on the client, such as "There is a data table structure that needs to be generated in the current project.""Generate code, business name, and integrate it into the current project." The client will hand the prompt word to the large model for recognition.

[0054] By parsing the user's input request information, the business information required for code generation can be accurately obtained. This information is passed as input to the code generation engine, which can generate code that meets the user's needs. Triggering the generation call instruction can automate code generation and improve development efficiency.

[0055] Referring to Figure 2, the method of "calling the server-side code generation engine to process the data table structure, service name, and business name to obtain the first dimension information, the second dimension information, and the third dimension information" in S300, that is, the method of obtaining the first dimension information, the second dimension information, and the third dimension information specifically includes: A100, parsing the data table structure to obtain the table name, field name, field type, primary key data, and foreign key data.

[0056] Suppose we have a database with a table named orders, which is used to record order information. Through the database's metadata query function (e.g., using SQL's SHOW) Statements such as TABLES and DESCRIBE can be used to obtain the table name "orders" and field names such as "order_id", "customer_id", and "order_date", with field types of INT, VARCHAR, and DATE, respectively. Simultaneously, by querying the database's system tables (such as MySQL's information_schema), it can be determined that "order_id" is the primary key and "customer_id" is a foreign key, linked to the "customer_id" field in the "customers" table. Accurately obtaining the basic information of the data table is fundamental to subsequent code generation. This information will be used to generate entity classes, database operation code, etc., ensuring that the generated code is consistent with the database structure and avoiding data access errors due to inaccurate information.

[0057] A200, according to the configured naming rules, the table name is converted into a class name conforming to the project specifications.

[0058] If the project uses camelCase as the class naming convention, the table name "orders" is converted to "Orders" according to the rules; if the table name is "customer_orders", it is converted to "CustomerOrders". The naming rules can be defined in the configuration file, and the code generation engine converts according to the rules. Through this step, the generated class names can conform to the project's unified naming convention, improving the readability and maintainability of the code. Team members can more easily understand the business meaning represented by the classes, reducing communication costs caused by non-standard naming.

[0059] A300, convert the field names to attribute names that conform to the standard, and map them to Java data types according to the field types.

[0060] For example, the field name order_id is converted to orderId according to camelCase; the field name order_date is converted to orderDate. For the field type, the INT type in the database is mapped to the Java Integer type, the VARCHAR type is mapped to the String type, and the DATE type is mapped to the java.util.Date type. The mapping rules can be pre-configured in the code generation engine. Through this step, it is ensured that the generated entity class attribute names conform to the project specifications, and the database field types are correctly converted to Java data types, so that the entity class can correctly interact with the database, improving the accuracy and compatibility of the code.

[0061] A400, automatically generate association information based on primary key data and foreign key data.

[0062] Specifically, it is known that the customer_id in the orders table is a foreign key, which is associated with the customer_id field in the customers table; the code generation engine will automatically generate the association information between the Orders class and the Customers class, for example, by adding a Customers type property in the Orders class and adding corresponding annotations (such as the @ManyToOne annotation of JPA) to the property to represent the many-to-one association relationship. Automatically generating association information can reduce the workload of developers in manually writing association code, avoid errors that may occur when manually writing association code, and improve the accuracy of the code and development efficiency.

[0063] A500, call the corresponding project structure from the preset database based on the service name, denoted as the target project structure.

[0064] Wherein, the preset database contains several sets of mapping relationships between service names and project structures.

[0065] For example, the following mapping relationship is stored in the preset database: the project structure corresponding to the service name "e-commerce service" is "controller layer, service layer, data access layer, entity layer"; the project structure corresponding to the service name "financial service" is "account management module, transaction management module, risk assessment module"; when the service name is "e-commerce service", the corresponding project structure "controller layer, service layer, data access layer, entity layer" is called from the preset database as the target project structure. The corresponding project structure is quickly obtained according to the service name, so that the generated code can conform to the overall architecture of the project, improve the organization and maintainability of the code, and at the same time, the preset mapping relationship can facilitate the unified management and adjustment of the project structure of different services.

[0066] A600, if there is a business name in the target project structure, obtain the hierarchical structure corresponding to the business name.

[0067] Assume that the target project structure is "controller layer, service layer, data access layer, entity layer", and the business name is "order"."Business"; In this project structure, the hierarchical structure corresponding to "order business" is "controller layer / order controller, service layer / order service, data access layer / order data access, entity layer / order entity"; the code generation engine will extract these hierarchical structure information related to "order business" from the target project structure. In this step, the hierarchical structure of code generation is further refined, so that the generated code can accurately locate the specific layer corresponding to the business, improve the relevance and maintainability of the code, and allow developers to more clearly understand the position and role of the code in the project.

[0068] The method disclosed in this embodiment ensures that the generated code is highly consistent with the database structure and project specifications through detailed analysis of the data table structure, application of naming rules, and automatic generation of association relationships, reducing errors caused by mismatch between code and actual business; it obtains the hierarchical structure corresponding to the target project structure and business name, enabling the generated code to be organized according to the overall architecture and business logic of the project, facilitating code maintenance and expansion by team members; the automated information processing and code generation process reduces the workload of developers manually writing code, speeds up code generation, and allows developers to devote more energy to the implementation and optimization of business logic; the preset mapping relationship between service names and project structures and the dynamic acquisition of the hierarchical structure of business names enable the system to adapt to different service and business needs, facilitating functional expansion and architecture adjustment during project development.

[0069] Specifically, if a business name exists in the target project structure, it means that the hierarchical structure corresponding to the current business name exists in the current project structure.

[0070] The first dimension information includes the class name, attribute name, data type, and association relationship corresponding to the target project; the second dimension information includes the target project structure; and the third dimension information includes the hierarchical structure corresponding to the business name.

[0071] Dividing business information into dimensions allows for clearer organization and processing of the information required for code generation. Information of different dimensions can be used in different code generation stages, improving the accuracy and flexibility of code generation.

[0072] The method of S400, "triggering the generation of Java code text matching the project based on the first dimension information, the second dimension information, and the third dimension information," specifically includes: S410, obtaining integrated information based on the first dimension information, the second dimension information, and the third dimension information; specifically, integrating the class name, attribute name, data type, association relationship, target project structure, and hierarchical structure corresponding to the target project to obtain integrated information. Specification 8 / 13 pages 11 CN 121300756 A

[0073] Assuming that in the target project, the class name is Order, the attribute names are orderId, orderDate, etc., the data types are Integer and Date respectively, and the association relationship is Order class andThe Customer class has a many-to-one relationship; the target project structure is "controller layer, service layer, data access layer, entity layer", and the hierarchical structure is "controller layer / order controller, service layer / order service, data access layer / order data access, entity layer / order entity". Integrating this information together forms a set of integrated information containing complete information about the class and its level and structure in the project. The integrated information brings together various key elements required for code generation, providing a comprehensive and orderly data foundation for subsequent filling into the code template, avoiding the confusion and errors that may be caused by the scattered processing of different information in subsequent steps, and improving the accuracy and efficiency of code generation.

[0074] S420, based on the integrated information and the second dimension information, obtain the Java code text that matches the project; specifically, fill the integrated information into the preset code generation template to obtain the Java code text that matches the project. The code generation template contains the basic structure and logic of the Java code.

[0075] The preset code generation template may be a general Java entity class template, which contains placeholders, such as ${className} representing the class name, ${propertyName} representing the property name, and ${dataType} representing the data type, etc. The class name, property name, data type, etc., information from the integrated information are filled into the corresponding placeholders. For example, the class name Order is filled into ${className}, the property name orderId is filled into ${propertyName}, and the data type Integer is filled into ${dataType}, generating Java entity class code text that meets the project requirements. A similar filling method is used for code templates of other layers such as the controller layer and service layer. The preset code generation template provides the basic framework and logic of Java code. By filling in the integrated information, Java code that meets the project specifications and business requirements can be quickly generated, reducing the workload of developers manually writing repetitive code, while ensuring the standardization and consistency of the code.

[0076] S430, Based on the Java code text and third-dimensional information, generate Java code text that matches the project; specifically, organize the Java code text according to the target project structure and package it into a code package, the structure of which matches the project's specifications and requirements.

[0077] Based on the target project structure of "controller layer, service layer, data access layer, entity layer", place the generated controller code text into the directory corresponding to the controller layer, the service layer code text into the directory corresponding to the service layer, the data access layer code text into the directory corresponding to the data access layer, and the entity layer code text into the directory corresponding to the entity layer, and then...The directory and code text are packaged into a compressed file, such as a ZIP package, and the structure of this code package matches the project's specifications and requirements. Organizing and packaging the code text according to the target project structure allows the generated code to be directly applied to the project, conforming to the overall architecture and organization of the project, making it convenient for developers to integrate the code into the project, reducing the difficulty of code deployment and debugging, and improving the efficiency of project development.

[0078] The method disclosed in this embodiment realizes the automated generation of Java code through the process of integrating information, filling templates, and organizing packaging, which greatly improves the speed of code generation and saves development time and manpower costs; using a preset code generation template and organizing the code according to the project structure ensures that the generated Java code has good standardization and consistency, conforms to the project's development standards, and facilitates collaboration among team members and code maintenance; the generated code package structure matches the project's specifications and requirements, and can be seamlessly integrated into the project, reducing integration problems caused by code structure mismatch, and improving the success rate and stability of project development; the clear project structure and standardized code organization make the generated code easy to understand and maintain, and can be more easily modified and extended in the subsequent development and upgrade process of the project.

[0079] Regarding S500 "sending Java code text to the client", specifically, the server encapsulates the generated Java code text in JSON format and sends it to the client through the previously established standard IO communication channel; after receiving the code text, the client stores it in a designated directory locally.

[0080] A standard IO communication channel has been established between the server and the client. The server sends the encapsulated JSON data to the client through this channel. The server converts the JSON data into a byte stream and then sends it out through the output stream. The client receives these byte streams through the input stream. The standard IO communication channel provides a reliable data transmission method, ensuring that data can be accurately transmitted from the server to the client. This method is widely used in network programming, has high stability and versatility, and can adapt to different network environments.

[0081] After receiving the JSON data sent by the server, the client first parses the JSON object and extracts the filename and corresponding code text of each Java code file; then, the client creates a designated directory locally and stores each Java code file in that directory according to its filename. The received Java code text is stored in a specified local directory, making it convenient for developers to view, modify, and use the generated code. Developers can directly open these code files in their local development environment to perform subsequent development work, thus improving development efficiency.

[0082] The S600 method, which "responds to the signal that the client receives Java code text, calls the large model to integrate the Java code text into the corresponding business layer of the hierarchical structure to obtain the target code," specifically includes: S610, responding to the signal that the client receives Java code text, calling the large model, and inserting the Java code text into the corresponding business module and class according to the hierarchical structure information to obtain the integrated code; S620, performing correctness and completeness checks on the integrated code. If the check conditions are met, the integrated code that meets the conditions is used as the target code; if the check conditions are not met, dynamically triggering the correction of the integrated code, and using the corrected integrated code as the target code.

[0083] Assuming the hierarchical structure information indicates a controller layer, service layer, and entity layer, after the client receives the Java code text, it sends a signal to the system; the system calls the large model, which makes a judgment based on the class name, function, and other information in the code text, combined with the hierarchical structure information; for example, if the code text is an order-related controller class code, the large model will insert it into the corresponding business module of the controller layer, find the appropriate class file, and accurately add the code text to the appropriate position of the class to complete the integration and generate integrated code. With the help of the intelligent analysis capability of the large model, the Java code text can be automatically and accurately integrated into the corresponding business module and class according to the hierarchical structure information, reducing the tediousness and errors of manual operation, improving the efficiency and accuracy of code integration, and the large model can understand the semantics and logic of the code, better completing the insertion and fusion of the code.

[0084] For the integrated code, the system will check from multiple aspects. For example, grammatical checks include spelling errors, mismatched parentheses, etc.; logical checks include whether method calls are reasonable and data flow is correct; and completeness checks include whether necessary dependencies are missing and whether method implementations are complete. If the integrated code passes all the checks, it is used as the target code. If a problem is found, such as a mismatch in the parameter type of a method call, the system will dynamically trigger the large model to correct the integrated code. The large model analyzes and modifies the code based on the error information and uses the corrected code as the target code. Checking and correcting the integrated code ensures the quality of the target code, prevents defective code from entering subsequent development and use, reduces system failures and debugging costs caused by code problems, and the dynamic correction mechanism can solve the problems found in a timely manner, improving the reliability and stability of the code.

[0085] By automatically calling the large model for code integration, the time-consuming and error-prone problem of manual code integration is avoided, greatly improving the efficiency of code integration and accelerating the development progress of the project. The checking and correction mechanism ensures the correctness and completeness of the target code, improves the quality of the code, reduces the difficulty of subsequent maintenance and debugging, and reduces potential risks.Risk; Dynamically triggering the large model for code correction leverages its intelligent analysis and processing capabilities to quickly and accurately resolve code issues, improving the level of intelligent development. The entire process is highly automated, allowing developers to focus more on business logic innovation and optimization rather than spending significant time on code integration and debugging, thus enhancing their work experience and satisfaction.

[0086] In a second aspect, this application discloses a system for automatically generating code based on the MCP protocol, used to execute the method for automatically generating code based on the MCP protocol disclosed in the first aspect of this application. The system includes: a construction module, used to construct a server-side code generation engine based on the MCP protocol; a parsing module, used to respond to a code generation request input by a user, parse the code generation request to obtain a data table structure, service name, and business name, and trigger a generation call instruction; a processing module, used to call the server-side code generation engine to process the data table structure, service name, and business name based on the call instruction, to obtain first dimension information, second dimension information, and third dimension information; a code text generation module, used to trigger the generation of Java code text matching the project based on the first dimension information, second dimension information, and third dimension information; a sending module, used to send the Java code text to a client; and an integration module, used to respond to a signal from the client receiving the Java code text, call a large model to integrate the Java code text into the business layer corresponding to the business name, and obtain target code.

[0087] A computer device according to an embodiment of this disclosure includes a memory and a processor. The memory is used to store non-transitory computer-readable instructions. Specifically, the memory may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc.

[0088] The processor may be a central processing unit (CPU) or other forms of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the computer device to perform desired functions. In one embodiment of this disclosure, the processor is used to run the computer-readable instructions stored in the memory, causing the computer device to perform all or part of the steps of the method for automatically generating code based on the MCP protocol in the foregoing embodiments of this disclosure.

[0089] Those skilled in the art should understand that in order to solve the technical problem of how to obtain a good user experience, this...The embodiments may also include known structures such as communication buses and interfaces, and these known structures should also be included within the protection scope of this disclosure.

[0090] FIG3 is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. It shows a schematic diagram of the structure suitable for implementing the computer device in the embodiment of this disclosure. The computer device shown in FIG3 is merely an example and should not impose any limitation on the function and scope of use of the embodiments of this disclosure.

[0091] As shown in FIG3, the computer device may include a processor (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 a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the computer device are also stored. The processor, ROM, and RAM are interconnected to each other via a bus. Input / output (I / O) interfaces are also connected to the bus.

[0092] Typically, the following devices can be connected to the I / O interface: including input devices such as sensors or visual information acquisition devices; including output devices such as displays; including storage devices such as magnetic tapes, hard disks, etc.; and communication devices. Communication devices can allow computer devices to communicate wirelessly or wiredly with other devices (such as edge computing devices) to exchange data. Although Figure 3 shows a computer device with various devices, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0093] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory 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 a storage device, or installed from ROM. When the computer program is executed by a processor, all or part of the steps of the method for automatically generating code based on the MCP protocol according to embodiments of this disclosure are performed.

[0094] Detailed descriptions of this embodiment can be found in the corresponding descriptions of the foregoing embodiments, and will not be repeated here.

[0095] A computer-readable storage medium according to an embodiment of the present disclosure stores non-transitory computer-readable instructions thereon. When the non-transitory computer-readable instructions are executed by a processor, all or part of the steps of the methods for automatically generating code based on the MCP protocol according to the foregoing embodiments of the present disclosure are performed.

[0096] The aforementioned computer-readable storage medium includes, but is not limited to: optical storage media (e.g., CD-ROM and DVD), magneto-optical...Storage media (e.g., MO), magnetic storage media (e.g., magnetic tape or portable hard drive), media with built-in rewritable non-volatile memory (e.g., memory card), and media with built-in ROM (e.g., ROM cartridge).

[0097] Detailed descriptions of this embodiment can be found in the corresponding descriptions of the foregoing embodiments, and will not be repeated here.

[0098] The basic principles of this disclosure have been described above in conjunction with specific embodiments. However, it should be noted that the advantages, benefits, effects, etc. mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are only for illustrative and facilitative purposes, and are not limitations. The above details do not limit the implementation of this disclosure to the use of the above specific details.

[0099] In this disclosure, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The block diagrams of devices, apparatuses, devices, and systems involved in this disclosure are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as "comprising," "including," "having," etc., are open-ended terms meaning "including but not limited to," and are used interchangeably with them. The terms "or" and "and" as used herein refer to the terms "and / or," and are used interchangeably with them unless the context clearly indicates otherwise. The term "such as" as used herein refers to the phrase "such as but not limited to," and is used interchangeably with it.

[0100] Additionally, as used herein, the "or" used in a list of items beginning with "at least one" indicates a separate list, such that a list of, for example, "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "exemplary" does not imply that the described example is preferred or better than other examples.

[0101] It should also be noted that in the systems and methods of this disclosure, the components or steps are decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalents of this disclosure.

[0102] Various changes, substitutions, and modifications to the techniques described herein can be made without departing from the techniques taught by the appended claims. Furthermore, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, events, components, means, methods, and actions described above. Currently existing or later-developed components of processes, machines, manufactures, events that perform substantially the same function or achieve substantially the same result as the corresponding aspects described herein can be utilized.Forms, means, methods, or actions. Therefore, the appended claims encompass such processes, machines, manufactures, events, means, methods, or actions within their scope. Specification 12 / 13 pages 15 CN 121300756 A

[0103] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of this disclosure. Therefore, this disclosure is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.

[0104] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although several exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof. Instruction sheet 13 / 13 page 16 CN 121300756 A Figure 1 Instruction drawing 1 / 2 page 17 CN 121300756 A Figure 2 Figure 3 Instruction sheet drawing 2 / 2 page 18 CN 121300756 A {HARTEND-26015-HKSPT / 02500053v1} Abstract The present application discloses a method and system, device, and medium for automatically generating code based on the MCP protocol. Wherein the method includes: constructing a server-side code generation engine based on the MCP protocol, responding to a code generation request input by a user, parsing the code generation request to obtain a data table structure, a service name, and a business name, and triggering the generation of invocation instructions to invoke the server-side codegeneration engine to process the data table structure, service name, and business name so as to obtain first-dimensional information, second-dimensional information, and third-dimensional information, and based on these three-dimensional information, triggering the generation of Java code text matching the project, and then sending it to the client. At the client, a large model is invoked to integrate the Java code text into the business hierarchy corresponding to the business names to obtain the target code. This method supports dynamic analysis and integration of project structure and business semantic hierarchies, and can dynamically, accurately, and efficiently generate code matching the project to meet practical demands.

Claims

1. A method for automatically generating code based on the MCP protocol, characterized in that, include: A server-side code generation engine was built based on the MCP protocol. In response to the code generation request, the code generation request is parsed to obtain the data table structure, service name, and business name, and the generation of the calling instruction is triggered; Based on the invocation instruction, the server-side code generation engine is invoked to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information; Based on the first dimension information, the second dimension information, and the third dimension information, Java code text matching the project is generated. Send the Java code text to the client; In response to the client receiving the Java code text, the large model is invoked to integrate the Java code text into the business layer corresponding to the business name, thereby obtaining the target code.

2. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that, The server-side code generation engine built based on the MCP protocol includes: Develop an MCP protocol server using the Java language and establish a connection with the client based on standard IO communication; A code generation engine is configured within the MCP protocol server. This engine is used to parse information and generate hierarchical code files based on predefined project templates and rules.

3. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that, The configuration of the code generation engine within the MCP protocol server includes: Configure mapping relationships between different services and different project structures, project code generation rules, multiple sets of code templates to support different project requirements, and a unified metadata parsing interface; wherein, the code templates adopt the FreeMarker template engine, and the metadata parsing interface supports table structure parsing from multiple data sources; Determine the database framework for the query, which is one of Mybatis, Mybatis-Plus, or Hibernate; Reserve the business layer package name parameter to dynamically specify the business layer based on the input business layer.

4. The method for automatically generating code based on the MCP protocol according to claim 1, characterized in that, The process of calling the server-side code generation engine to process the data table structure, the service name, and the business name to obtain first-dimensional information, second-dimensional information, and third-dimensional information includes: The data table structure is parsed to obtain one or more of the following: table name, field name, field type, primary key data, and foreign key data. According to the configured naming rules, the table names are converted into class names that conform to the project specifications; Convert the field names into attribute names that conform to the specifications, and map them to Java data types according to the field types; Based on the primary key data and the foreign key data, the association information is automatically generated; The corresponding project structure is retrieved from the preset database based on the service name, and is denoted as the target project structure; wherein, the preset database contains several sets of mapping relationships between service names and project structures; If the business name exists in the target project structure, obtain the hierarchical structure corresponding to the business name; The first dimension information includes the class name, attribute name, data type, and association relationship corresponding to the target project; the second dimension information includes the target project structure; and the third dimension information includes the hierarchical structure corresponding to the business name.

5. The method for automatically generating code based on the MCP protocol according to claim 4, characterized in that, The step of triggering the generation of Java code text matching the project based on the first dimension information, the second dimension information, and the third dimension information includes: Based on the first dimension information, the second dimension information, and the third dimension information, integrated information is obtained; Based on the integrated information and the second dimension information, obtain the Java code text that matches the project; Based on the Java code text and the third-dimensional information, generate Java code text that matches the project.

6. The method for automatically generating code based on the MCP protocol according to claim 5, characterized in that, The step of obtaining integrated information based on the first dimension information, the second dimension information, and the third dimension information includes: The class name, attribute name, data type, association, target project structure, and hierarchical structure corresponding to the target project are integrated to form an integrated information set containing complete information about the class and its level and structure within the project.

7. The method for automatically generating code based on the MCP protocol according to claim 5, characterized in that, The step of obtaining Java code text matching the project based on the integrated information and the second dimension information includes: Determine the preset code generation template corresponding to the project; The integrated information is filled into a preset code generation template to obtain Java code text that matches the project. The code generation template contains the basic structure and logic of the Java code.

8. The method for automatically generating code based on the MCP protocol according to claim 5, characterized in that, The step of generating Java code text matching the project based on the Java code text and the third-dimensional information includes: The Java code text is organized according to the target project structure and packaged into a code package, the structure of which matches the project's specifications and requirements.

9. The method for automatically generating code based on the MCP protocol according to claim 4, characterized in that, The step of responding to the client receiving the Java code text signal, invoking the large model to integrate the Java code text into the business layer corresponding to the business name, and obtaining the target code includes: In response to the client receiving the Java code text, the large model is invoked, and according to the hierarchical structure information, the Java code text is inserted into the business modules and classes corresponding to the hierarchical structure to obtain the integrated code; The integrated code is checked for correctness and completeness. If the check conditions are met, the integrated code that meets the conditions is used as the target code. If the check conditions are not met, the integrated code is dynamically corrected, and the corrected integrated code is used as the target code.

10. A system for automatically generating code based on the MCP protocol, characterized in that, include: The building block is used to build a server-side code generation engine based on the MCP protocol. The parsing module is used to respond to the code generation request input by the user, parse the code generation request to obtain the data table structure, service name, business name, and trigger the generation of call instructions; The processing module is used to call the server-side code generation engine to process the data table structure, the service name, and the business name based on the call instruction, and obtain first-dimensional information, second-dimensional information, and third-dimensional information. The code text generation module is used to trigger the generation of Java code text that matches the project based on the first dimension information, the second dimension information, and the third dimension information. The sending module is used to send the Java code text to the client; The integration module is used to respond to the signal that the client receives the Java code text, and call the large model to integrate the Java code text into the business layer corresponding to the business name to obtain the target code.