Large model data report generation tool and method based on MCP
Through the MCP-Server architecture and SSE protocol, combined with the database module, tool module and chart generation module, the problem of large-scale language models not understanding the database structure is solved, and an automated process from database query to reporting is realized, which improves data analysis efficiency and user experience.
Patent Information
- Application Number
- CN202511196117.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-26
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-08-26
AI Technical Summary
Large language models lack understanding of database structure, resulting in a low probability of calling database query tools, and it is difficult to accurately understand the query results and generate corresponding reports.
It adopts the MCP-Server architecture, communicates with the MCP-Client through the SSE protocol, uses the database module to obtain table names and comments, the tool module generates simplified strings, and the chart generation module generates interactive chart links, realizing an automated process from database query to report.
It enhances the large model's ability to recognize database structure, improves the accuracy and initiative of database queries, simplifies data understanding, and improves data analysis efficiency and user interaction experience.
Smart Images

Figure CN120687467A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network technology, and in particular to a tool and method for generating a large model data report based on MCP. Background Art
[0002] With the rapid development of artificial intelligence (AI), large language models (LLMs) have demonstrated remarkable capabilities in natural language processing. However, relying solely on the model's internal knowledge has limitations, especially when processing real-time data, performing specific tasks, or interacting with external systems. To address these issues, the function calling mechanism was introduced, enabling LLMs to interact with external tools and APIs, thereby expanding their capabilities.
[0003] Currently, MCP supports tools for querying MySQL databases, but it still faces some challenges in practical applications: First, the large model lacks understanding of the database structure, so the probability of calling the database query tool is low, and it is difficult to accurately understand the results returned after the call. As a result, the large model cannot generate corresponding reports based on the results by date, and can only simply return the queried data. Summary of the Invention
[0004] In view of this, the object of the present invention is to provide a tool and method for generating large model data reports based on MCP.
[0005] In a first aspect, an embodiment of the present invention provides a large model data report generation tool based on MCP, which adopts the MCP-Server architecture and communicates with the MCP-Client via the SSE protocol. The tool includes: The database module is configured with database connection parameters. The database module is used to execute SQL queries to obtain all table names and Chinese comments in the current database, format the query results into specified structured data, and then embed them into the tool description text. The database module is also used to query table structure and table data based on table name. The tool module is connected to the database module. The tool module includes a tool declaration module and a tool call module. The tool declaration module is used to respond to the MCP-Client's tool discovery request and return an optimized tool description text. The tool description text includes a table annotation and table name mapping string generated by the database module. The tool call module is used to respond to the MCP-Client's tool call request, query the target table data according to the table name in the request parameter, and convert the target table data into a simplified string with Chinese annotations. The chart generation module is connected to the tool module and is used to parse the key-value pair data in the simplified string; and generate interactive chart links based on the key-value pair data.
[0006] In combination with the first aspect, the generation of tool description text includes: Extract the database name from the database connection parameters; Execute table metadata query to obtain the table name-comment mapping relationship for each list; Format the mapping relationship into a specified string format; Embeds a string into a preset tool description template.
[0007] Combined with the first aspect, the simplified string generation includes: Execute field metadata query to obtain numeric fields, date fields, and field comments in the target list; For each target field, convert the target field and the corresponding field annotation into a key-value pair in the specified format; Combine all key-value pairs to get a simplified string with Chinese comments.
[0008] Combined with the first aspect, the generation of simplified strings also includes: Based on the order of the fields in the target list, the key-value pairs are sorted and separated by semicolons.
[0009] In conjunction with the first aspect, the generation of interactive chart links includes: Use the date field in the key-value pair data as the horizontal axis label, the numeric field as the vertical axis data, and trace back the annotation containing the target list corresponding to the key-value pair data as the chart title; Generates an interactive chart link based on the chart type parameter in the request.
[0010] In combination with the first aspect, the system further includes a communication interface module for receiving a tool discovery request from an MCP-Client; the communication interface module is further configured to return the optimized tool description text output by the tool declaration module to the MCP-Client for large-model tool integration; and the communication interface module is further configured to return the interactive chart link generated by the chart generation module to the MCP-Client for generating a final response.
[0011] In combination with the first aspect, the database connection parameters include at least a URL, a user, a password, and a driver name.
[0012] In a second aspect, an embodiment of the present application further provides a method for generating a large model data report based on MCP, which is applied to the above-mentioned tool; the method comprises: The tool declaration module receives tool discovery requests from the MCP-Client, drives the database module to extract the database name based on the preconfigured database connection parameters, performs table metadata queries to generate optimized MCP tool descriptions, and returns them to the MCP-Client for the large model integration toolset; The tool call module receives the tool call request forwarded by MCP-Client, parses the target table name in the request, and generates a simplified string in non-JSON format; and calls the chart generation module to parse the simplified string to generate an interactive chart and return the value to MCP-Client.
[0013] In conjunction with the second aspect, the steps of parsing the target table name in the request and generating a simplified string in a non-JSON format include: Execute field metadata query to obtain numeric fields, date fields, and field comments in the target list; For each target field, convert the target field and the corresponding field annotation into a key-value pair in the specified format; Combine all key-value pairs to get a simplified string with Chinese comments.
[0014] In conjunction with the second aspect, the step of calling the chart generation module to parse the simplified string to generate an interactive chart includes: Use the date field in the key-value pair data as the horizontal axis label and the numeric field as the vertical axis data, and use the annotation of the target list corresponding to the key-value pair data as the chart title. Generates an interactive chart link based on the chart type parameter in the request.
[0015] Embodiments of the present invention bring the following beneficial effects: The present invention provides a tool and method for generating large-model data reports based on MCP. The tool adopts an MCP-Server architecture and communicates with an MCP-Client via an SSE protocol. The tool includes: a database module configured with database connection parameters; the database module is used to execute an SQL query to obtain all table names and Chinese comments in the current library, format the query results into structured data in a specified form, and then embed a tool description text; the database module is further used to query table structures and table data based on table names; a tool module is connected to the database module; the tool module includes a tool declaration module and a tool call module; the tool declaration module is used to respond to tool discovery requests from the MCP-Client and return optimized tool description text, the tool description text including a table comment and table name mapping string generated by the database module; the tool call module is used to respond to tool call requests from the MCP-Client, query target table data based on the table name in the request parameters, and convert the target table data into a simplified string with Chinese comments; and a chart generation module is connected to the tool module to parse key-value pair data in the simplified string and generate interactive chart links based on the key-value pair data.
[0016] This application first enhances the large model's ability to recognize the underlying database structure by dynamically embedding the database table name and its corresponding Chinese annotation into the tool description text, effectively improving its accuracy and initiative in calling database query tools; secondly, it introduces a simplified string format conversion mechanism to convert the original query results into semantically clear data in the form of key-value pairs, stripping out redundant information, making it easier for the large model to understand and utilize these key data contents; finally, the simplified data is automatically parsed through the chart generation module, and interactive chart links are generated, realizing an end-to-end automated process from original database query to visual report, greatly improving data analysis efficiency, ease of use and user interaction experience.
[0017] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or understood by practicing the present invention. The purposes and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0018] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 A schematic diagram of the composition of a large model data report generation tool based on MCP provided in an embodiment of the present invention; Figure 2 An example diagram of a chart generated by the MCP-based large model data report generation tool provided in an embodiment of the present invention; Figure 3 A flow chart of a method for generating a large model data report based on MCP provided in an embodiment of the present invention; Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0022] To facilitate understanding of this embodiment, the following is a brief introduction to the technical terms used in this application.
[0023] The Model Context Protocol (MCP), an open-source protocol developed by Anthropic, aims to integrate large models with external data sources and tools, establishing secure, bidirectional connections between them. Through MCP, large models can better access and utilize external data sources, such as databases and APIs, thereby enhancing their functionality and application scenarios.
[0024] After introducing the technical terms involved in this application, the application scenarios and design concepts of the embodiments of this application are briefly introduced.
[0025] The large model lacks understanding of the database structure, so the probability of calling the database query tool is low, and it is difficult to accurately understand the results returned after the call. As a result, the large model cannot generate corresponding reports based on the results by date, and can only simply return the queried data.
[0026] Based on this, an embodiment of the present application provides a tool and method for generating large model data reports based on MCP.
[0027] Example 1 This application provides a large model data report generation tool based on MCP, which adopts MCP-Server architecture and communicates with MCP-Client through SSE protocol. Figure 1 As shown, the tool includes: a database module 10 , a tool module 20 and a chart generation module 30 .
[0028] The database module 10 is configured with database connection parameters; the database module 10 is used to execute SQL queries to obtain all table names and Chinese comments in the current library, format the query results into specified structured data and then embed them into tool description text; the database module 10 is also used to query table structure and table data based on table name.
[0029] The tool module 20 is connected to the database module 10. The tool module 20 includes a tool declaration module and a tool call module. The tool declaration module is used to respond to the MCP-Client's tool discovery request and return an optimized tool description text. The tool description text includes a table annotation and table name mapping string generated by the database module 10. The tool call module is used to respond to the MCP-Client's tool call request, query the target table data according to the table name in the request parameter, and convert the target table data into a simplified string with Chinese annotations.
[0030] The chart generation module 30 is connected to the tool module 20 and is used to parse the key-value pair data in the simplified character string; and generate interactive chart links based on the key-value pair data.
[0031] This application significantly improves the intelligence level and practicality of MCP in database report generation tasks through innovative designs of system architecture and data processing methods. First, at the tool calling level, by dynamically embedding the database table name and its corresponding Chinese annotation into the tool description text, the large model's ability to recognize the underlying database structure is enhanced, and its accuracy and initiative in calling database query tools are effectively improved. Secondly, at the data parsing level, a simplified string format conversion mechanism is introduced to convert the original query results into semantically clear data in the form of key-value pairs, stripping off redundant information, making it easier for the large model to understand and utilize these key data contents. Finally, at the output presentation level, the simplified data is automatically parsed through the chart generation module, and interactive chart links are generated, realizing an end-to-end automated process from original database query to visual report, greatly improving data analysis efficiency, ease of use and user interaction experience. This design not only solves the problem of lack of report generation capabilities in the existing technology, but also provides an extensible technical foundation for subsequent complex data-driven tasks.
[0032] In combination with the first aspect, the generation of tool description text includes: S110: Extract the database name from the database connection parameters.
[0033] S120: Execute table metadata query to obtain the table name-comment mapping relationship of each list.
[0034] S130: Format the mapping relationship into a specified format string.
[0035] S140: embed the character string into a preset tool description template.
[0036] The database module 10 is a key component in the system responsible for interacting with the database. It contains the necessary database connection parameters. These parameters typically include the database address (IP or URL), port number, database name, username, and password, and are used to establish a secure connection with the target database.
[0037] In actual operations, when metadata about the current database is needed, the database module extracts the "Database Name" field from these connection parameters. The database name refers to the name of the specific database instance currently connected, and serves as the fundamental identifier for subsequent database queries and operations. By extracting the database name, subsequent operations are guaranteed to target the correct database instance, thus ensuring the accuracy and effectiveness of data queries. As can be seen, the database connection parameters allow you to quickly identify the database source of the data you are processing.
[0038] Then, by performing a table metadata query, we can obtain all the table names and the corresponding comments of each table name in the specified database, and thus obtain the table name-comment mapping relationship of each list. Specifically, we can query all the table names and their comments in the database "zone_llm_summary" through the following table metadata: SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA, TABLES WHERE TABLE_SCHEMA='zone_llm_summary' ORDER BY TABLE_NAME.
[0039] The table name-comment mapping relationship queried in the above example is shown in Table 1.
[0040] Table 1 is the table name-comment mapping table in the "zone_llm_summary" database.
[0041]
[0042] Then, format the above results. Combining the above example, format Table 1 to obtain: Weekly statistics table for the number of people entering and exiting: “people_in_exit_record_every_week”; monthly statistics table for the import and export volume of the bonded area: “zone_in_export_statistics_month_report”; monthly statistics table for the import and export volume of the xx bonded area: “zone_in_export_statistics_month_report_xx”.
[0043] Finally, the above string is embedded into the preset tool description template to quickly identify the tool through the tool description, and then obtain the target report data through the identified tool. For example, when the user asks about bonded area bonded report analysis, it is convenient for the large model to quickly identify and call the corresponding tool.
[0044] In actual application, after receiving a call request, the target table is queried based on the table name in the request parameter. For example, if the database parameter in the request parameter is "zone_llm_summary" and the table name is "zone_in_export_statistics_month_report_xx", the table metadata query is executed as follows: select*from one_llm_summary.zone_in_export_statistics_month_report_xx.
[0045] The resulting query combinations are shown in Table 2.
[0046] Table 2 shows an example of the result of searching the zone_in_export_statistics_month_report_xx table in the zone_llm_summary database.
[0047]
[0048] It can be seen that the returned data is ultimately an object collection. When there are many data fields, the naming is not intuitive, or there are escape characters, directly returning the object collection will significantly reduce the large model's ability to understand the data, resulting in parameter errors or reliance on false data when generating charts.
[0049] Specifically, if this collection is directly used as the return value of a tool call, the large model will have difficulty understanding the data for the chart being generated when calling the next chart generation tool. This causes the large model to create its own set of fake data when given the chart generation tool parameters, rather than using the data from the query database report. This difficulty can be caused by field names being in English, and the meaning of English being inaccurate.
[0050] Secondly, if the report query has a large number of fields, the large model cannot know which fields to generate the report for. If the collection is returned directly, it will be serialized in JSON, resulting in a large number of escape characters in the text, affecting the overall understanding and integration of the text.
[0051] Therefore, this application processes the returned data to simplify the annotation fields, selectively extract key fields, and avoid JSON sequence interference, so as to provide the chart generation module 30 with the necessary context information for generating charts (such as horizontal axis fields, vertical axis fields, chart types, etc.), which can help the large model accurately understand how to use the data, avoid writing false data, and ensure the accuracy of parameters.
[0052] First, simplifying string generation includes: S210, executing a field metadata query to obtain numeric fields, date fields, and field comments in a target list.
[0053] S220 , for each target field, convert the target field and the corresponding field annotation into a key-value pair in a specified format.
[0054] S230: Combine all key-value pairs to obtain a simplified string with Chinese annotations.
[0055] After identifying the specific table, first perform a field metadata query to obtain the names and comments of all fields in the table, and then filter to obtain numeric fields, date fields, and field comments.
[0056] As an example, by executing the following field metadata query: SELECT COLUMN_NAME,COLUMN-TYPE,COLUMN_COMMENT FROM INFORMATION_SCHEMA,COLUMNS WHERE TABLE_SCHEMA='zone_llm_summary'AND TABLE_NAME='zone_in_export_statistics_month_report_xx' ORDER BY ORDINAL_POSITON.
[0057] Based on the above field metadata query, the results obtained are shown in Table 3.
[0058] Table 3 shows an example of field metadata results.
[0059]
[0060] Among them, "bigint(20)" indicates that this is a large integer field; "varchar(100)" indicates that this is a string field with a length of no more than 100 characters; "decimal(10,0)" indicates that this is a decimal numeric field with a total of 10 digits and 0 decimal places (that is, an integer); "date" indicates that this is a date type field.
[0061] Then, we filter the fields in Table 3 to remove fields without Chinese annotations or fields whose types are not specified above (numeric or date). For example, the data set returned after filtering is: [{ "id":4, "in_value": 120, "export_value":1200, "total_value":271202, “date”: “20241201” }, { "id":11, "in_value": 110, "export_value":1100, "total_value":271202, “date”: “20241101” }].
[0062] Then format it into a string, specifically converting each target field into a key-value pair in the specified format. For example, based on the above example, "date": "20241101" is converted into "Report date: 2024-11-01", or "in_value": "110" is converted into "Import amount: 110".
[0063] In combination with the first aspect, based on the order of the fields in the target list, the key-value pairs are arranged in sequence and separated by semicolons.
[0064] It is understandable that in order to maintain the order consistency with the original data, the key-value pairs are sorted according to the order of the fields in the original list, and the key-value pairs are connected with a unified separator (such as a semicolon), so that the generated simplified string structure is regular, which is convenient for subsequent programs or systems to parse and process according to fixed rules, thereby improving the efficiency of automated processing.
[0065] In addition, since the field order remains consistent with the original list, users can more intuitively correspond to the original data structure when viewing the simplified string, reducing the cost of understanding and improving the user experience.
[0066] Based on the above example, the "simplified string" is: Import amount: 120, Export amount: 1200, Total amount: 271202, Report date: 2024-12-01; Import amount: 110, Export amount: 1100, Total amount: 271202, Report date: 2024-11-01.
[0067] In conjunction with the first aspect, the generation of interactive chart links includes: S310 , using the date field in the key-value pair data as the horizontal axis label, the numeric field as the vertical axis data, and retrieving the annotation containing the target list corresponding to the key-value pair data as the chart title.
[0068] S320: Generate an interactive chart link based on the chart type parameter in the request.
[0069] The date field in the key-value pair data is used as the horizontal axis label, the numeric field as the vertical axis data, and the annotation information in the target list is combined as the chart title, so that the generated chart has clear semantic expression and intuitive visual presentation, which facilitates users to understand the data background and trends. By dynamically generating interactive chart links based on the chart type parameters in the request, it achieves rapid support and switching for different chart types (such as bar charts, line charts, pie charts, etc.), improving the system's ability to adapt to diverse data display needs.
[0070] It is understandable that in actual application, users ask questions to the big model, and the big model accurately understands the purpose of each tool, data processing scenarios, etc. through the tool description text added by the database module 10 for each tool, so that it can accurately select the tool suitable for the current work needs, and then call the tool module 20 to perform table query and data processing, and then build a visual chart based on the simplified character string obtained by the tool module 20 (select tables, bar charts, line charts, pie charts, etc. according to the scenario) and publish the report push corresponding web page link.
[0071] In combination with the first aspect, the tool further includes a communication interface module.
[0072] The communication interface module is responsible for receiving tool discovery requests from the MCP-Client so that the MCP-Client can obtain information about available tools and select appropriate tools for integration and use.
[0073] After receiving the tool discovery request, the communication interface module will obtain the optimized tool description text from the tool declaration module and return it to the MCP-Client. This helps the MCP-Client better understand and integrate large model tools.
[0074] The communication interface module is also responsible for returning the interactive chart links generated by the chart generation module to the MCP-Client. These links can be used to generate the final answer, providing a more intuitive data display and interactive experience.
[0075] In combination with the first aspect, the database connection parameters include at least a URL, a user, a password, and a driver name.
[0076] The URL is the connection address, which is used to specify the network location and connection information of the database server, usually including the protocol, host, port, and database name.
[0077] The user is the database authentication account name and must have access permissions.
[0078] The driver name specifies the fully qualified name of the database driver class to ensure that the program can load the correct driver.
[0079] In the second aspect, the present application provides a method for generating a large model data report based on MCP, combined with Figure 3 As shown, the method includes: S010, the tool declaration module receives the tool discovery request sent by the MCP-Client, drives the database module to extract the database name based on the preconfigured database connection parameters, performs table metadata query to generate the optimized MCP tool description and returns it to the MCP-Client for the large model integration toolset.
[0080] S020, the tool calling module receives the tool calling request forwarded by the MCP-Client, parses the target table name in the request, generates a simplified string in a non-JSON format, and calls the chart generation module to parse the simplified string to generate an interactive chart and return a value to the MCP-Client.
[0081] This application responds to the MCP-Client's tool discovery request through the tool declaration module, providing a standardized tool description. The tool call module responds to the tool call request. Through the synergy between the modules, the optimized MCP tool description is automatically generated based on metadata-driven automatic generation. Then, the interactive chart is automatically generated and returned based on the simplified string of the tool call module. This solves the problem of tool call errors in traditional report generation and greatly improves data analysis efficiency, ease of use and user interaction experience.
[0082] In conjunction with the second aspect, the steps of parsing the target table name in the request and generating a simplified string in a non-JSON format include: Execute field metadata query to obtain numeric fields, date fields, and field comments in the target list.
[0083] For each target field, convert the target field and the corresponding field annotation into a key-value pair of the specified form.
[0084] Combine all key-value pairs to get a simplified string with Chinese comments.
[0085] Specifically, the field metadata of the target table is extracted from the database, including the field name, data type, and comments; then the field is filtered and all filtered fields (numeric and date types) are traversed. For each field, the field name, Chinese comment, and field type are extracted, and the qualified fields and comments are converted into key-value pairs in the specified format. Finally, all key-value pairs are combined into a single-line string for the tool to call the module for parsing.
[0086] In conjunction with the second aspect, the step of calling the chart generation module to parse the simplified string to generate an interactive chart includes: Use the date field in the key-value pair data as the horizontal axis label, the numeric field as the vertical axis data, and the annotation containing the target list corresponding to the key-value pair data as the chart title.
[0087] Generates an interactive chart link based on the chart type parameter in the request.
[0088] Combine Figure 2 As shown, the generated chart is shown as an example, and a link to an openable web page (i.e., an interactive chart link) is returned.
[0089] In a third aspect, the present application provides an electronic device, Figure 4 As shown, the electronic device includes a memory 131 and a processor 130. The memory 131 is used to store computer programs, and the processor 130 runs the computer programs to enable the electronic device to perform the above method.
[0090] Further, combined with Figure 4 The electronic device shown further includes a bus 132 and a communication interface 133 , and the processor 130 , the communication interface 133 and the memory 131 are connected via the bus 132 .
[0091] The memory 131 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is achieved through at least one communication interface 133 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 132 may be an ISA bus, a PCI bus, or an EISA bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0092] The processor 130 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 130 or by software instructions. The processor 130 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 131, and processor 130 reads information in memory 131 and, in conjunction with its hardware, completes the steps of the method of the aforementioned embodiment.
[0093] In a fourth aspect, an embodiment of the present application provides a readable storage medium, in which computer program instructions are stored. When the computer program instructions are read and executed by a processor, the above-mentioned method is executed.
[0094] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described systems and devices can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0095] In addition, in the description of the embodiments of the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integral connections; they may refer to mechanical connections or electrical connections; they may refer to direct connections or indirect connections through an intermediate medium; and they may refer to internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on the specific circumstances.
[0096] If the functions are implemented as software modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or the portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0097] In the description of the present invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate and simplify the description of the present invention. They are not intended to indicate or imply that the devices or components referred to must have, be constructed, or operate in a specific orientation, and therefore should not be construed as limitations on the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0098] Finally, it should be noted that the above embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A large model data report generation tool based on MCP, characterized in that: Using the MCP-Server architecture and communicating with the MCP-Client via the SSE protocol, the tool includes: A database module configured with database connection parameters; the database module is used to execute SQL queries to obtain all table names and Chinese annotations in the current database, format the query results into specified structured data, and then embed them into the tool description text; the database module is also used to query table structure and table data based on table name; A tool module is connected to the database module; the tool module includes a tool declaration module and a tool call module; the tool declaration module is used to respond to the MCP-Client's tool discovery request and return an optimized tool description text, the tool description text including a table annotation and table name mapping string generated by the database module; the tool call module is used to respond to the MCP-Client's tool call request, query the target table data according to the table name in the request parameter, and convert the target table data into a simplified string with Chinese annotations; The chart generation module is connected to the tool module and is used to parse the key-value pair data in the simplified character string; and generate an interactive chart link based on the key-value pair data.
2. The tool according to claim 1, characterized in that The generation of the tool description text includes: Extracting a database name from the database connection parameters; Execute table metadata query to obtain the table name-comment mapping relationship for each list; Format the mapping relationship into a specified format string; Embed the string into the preset tool description template.
3. The tool according to claim 2, characterized in that The generation of the simplified character string includes: Execute field metadata query to obtain numeric fields, date fields, and field comments in the target list; For each target field, convert the target field and the corresponding field annotation into a key-value pair in a specified format; All the key-value pairs are combined to obtain the simplified character string with Chinese annotations.
4. The tool according to claim 3, characterized in that The generation of the simplified character string further includes: Based on the order of the fields in the target list, the key-value pairs are arranged in sequence and separated by semicolons.
5. The tool according to claim 3, characterized in that Generation of interactive chart links includes: Using the date field in the key-value pair data as the horizontal axis label, the numeric field as the vertical axis data, and retrieving the annotation of the target list corresponding to the key-value pair data as the chart title; The interactive chart link is generated based on the chart type parameter in the request.
6. The tool according to claim 1, characterized in that The system further includes a communication interface module for receiving a tool discovery request from the MCP-Client; the communication interface module is further configured to return the optimized tool description text output by the tool declaration module to the MCP-Client for large-model tool integration; and the communication interface module is further configured to return the interactive chart link generated by the chart generation module to the MCP-Client for generating a final answer.
7. The tool according to claim 1, characterized in that The database connection parameters include at least URL, user, password and driver name.
8. A method for generating a large model data report based on MCP, characterized in that: Applicable to the tool according to any one of claims 1 to 7; the method comprising: The tool declaration module receives the tool discovery request sent by the MCP-Client, drives the database module to extract the database name based on the pre-configured database connection parameters, performs table metadata query to generate an optimized MCP tool description, and returns it to the MCP-Client for the large model integration tool set; The tool calling module receives a tool calling request forwarded by the MCP-Client, parses the target table name in the request, and generates a simplified string in a non-JSON format; and calls the chart generating module to parse the simplified string to generate an interactive chart and return the value to the MCP-Client.
9. The method according to claim 8, characterized in that The step of parsing the target table name in the request and generating a simplified string in a non-JSON format includes: Execute field metadata query to obtain numeric fields, date fields, and field comments in the target list; For each target field, convert the target field and the corresponding field annotation into a key-value pair in a specified format; All the key-value pairs are combined to obtain the simplified character string with Chinese annotations.
10. The method according to claim 9, characterized in that The step of calling the chart generation module to parse the simplified character string to generate an interactive chart includes: Using the date field in the key-value pair data as the horizontal axis label, the numeric field as the vertical axis data, and retrieving the annotation of the target list corresponding to the key-value pair data as the chart title; The interactive chart link is generated based on the chart type parameter in the request.
Citation Information
Patent Citations
Database table structure exporting method and device and terminal equipment
CN111352986A
Intelligent financial field database interaction method driven by large language model
CN117971867A
Report generation method and device based on large language model and storage medium
CN118917296A
Power field SQL intelligent agent construction method based on KMDI chain
CN119166662A
Function interface calling method and device, equipment and medium
CN120407049A