MCP service publishing method, device and system and storage medium

By editing the MCP service code through a web interface, tools can be dynamically generated and deployed instantly, solving the problems of poor flexibility and complex deployment of MCP service toolsets, and enabling flexible definition and efficient deployment.

CN121680918APending Publication Date: 2026-03-17GUANGDONG ESHORE TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-07
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

The existing MCP service toolset is inflexible, difficult to develop and deploy, and costly and complex to deploy in an intranet environment, making it impossible to achieve flexible tool customization and real-time updates.

Method used

Edit the code of the MCP service through a web interface, parse the code to obtain functions, build tools, and associate them with the MCP service instance to dynamically generate routes and request processing functions. This enables online editing and instant publishing of the MCP service, supporting streaming HTTP and SSE protocols.

Benefits of technology

It enables flexible definition and instant updates of MCP service tools, reduces development and deployment difficulty, improves release efficiency, supports private deployment on intranet and real-time data interaction, and adapts to rapidly changing project needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121680918A_ABST
    Figure CN121680918A_ABST
Patent Text Reader

Abstract

The invention relates to an MCP service publishing method, device and system and a storage medium. The method comprises the following steps of: obtaining a code of an MCP service edited through a Web interface; analyzing the code to obtain a function of the code; according to the function, constructing a tool of the MCP service; creating an MCP service instance of the MCP service, associating the tool with the function, registering the tool and the function in the MCP service instance, and assembling the MCP service; and issuing the MCP service according to the service metadata of the MCP service. According to the scheme provided by the invention, the tool of the MCP service can be flexibly defined, the difficulty and cost of MCP service development and deployment are reduced, and the efficiency of MCP service release is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer software engineering technology, and in particular to an MCP service publishing method, apparatus, system and storage medium. Background Technology

[0002] While related technologies' MCP services (MCP Servers) can provide pre-built tools (such as weather queries and data calculations) online via MCP (Model Context Protocol), they have significant limitations in practical applications. The toolsets for these MCP services are pre-developed and fixed by the MCP service provider or a third party. If specific business logic needs to be implemented (e.g., data queries in enterprise resource planning systems or customized data analysis models), it's impossible to directly write code to create tools; one can only rely on updates to the MCP service, resulting in extremely poor tool flexibility. Furthermore, updates to these MCP services after release require a server restart to take effect, leading to service interruptions and impacting the user experience.

[0003] The development and deployment of MCP services for related technologies require developers to install the Python (high-level programming language) SDK (Software Development Kit) locally, configure dependencies, write server-side code, and then deploy it to the server via command line. The entire process involves multiple steps such as environment setup, version compatibility, and service startup and shutdown, which is extremely difficult for non-professional operations and maintenance personnel.

[0004] While MCP services based on related technologies support local deployment via stdio (standard input / output), many public MCP marketplaces or markets primarily offer MCP services to the public internet. For enterprises or projects that need to deploy and use MCP services in an intranet environment, the intranet support capabilities of related technologies are insufficient, and the MCP services provided on the public internet are either unsuitable or require complex network configurations and security policies, resulting in high deployment costs and complex operations.

[0005] Therefore, the release of related technologies' MCP services suffers from poor tool flexibility, and development and deployment are difficult and costly. Summary of the Invention

[0006] To address or partially address the problems existing in related technologies, this application provides an MCP service publishing method, apparatus, system, and storage medium, which can flexibly define MCP services, reduce the difficulty and cost of MCP service development and deployment, and improve the efficiency of MCP service publishing.

[0007] The first aspect of this application provides a method for publishing MCP services, the method comprising: Obtain the code for the MCP service edited via the web interface; Parse the code to obtain its functions; Based on the function, a tool for constructing the MCP service is provided; Create an MCP service instance of the MCP service, associate the tool with the function and register it with the MCP service instance, and assemble the MCP service; The MCP service is published based on its service metadata.

[0008] In one implementation, parsing the code and obtaining the function of the code includes: Parse the code and construct its syntax structure tree; Traverse the syntax structure tree to obtain the functions of the code and the function information of the functions.

[0009] In one implementation, the tool for constructing the MCP service based on the function includes: A tool for constructing the MCP service based on the functions in the code and the function information of the functions.

[0010] In one implementation, creating an MCP service instance, associating the tool with the function and registering it with the MCP service instance, and assembling the MCP service includes: Create an MCP service instance of the aforementioned MCP service; Based on the function name and the tool name, the tool is associated with the function and registered with the MCP service instance to assemble the MCP service.

[0011] In one implementation, publishing the MCP service based on the service metadata of the MCP service includes: Based on the service metadata of the MCP service, the MCP service is published. The service metadata includes the service name, tool name, and protocol type of the MCP service.

[0012] In one implementation, publishing the MCP service based on the service metadata of the MCP service includes: Generate a route for the tool based on the service name, tool name, and protocol type; Create a request processing function for the tool based on the function corresponding to the tool; Associate the route with the request processing function, register it with the server, and publish the MCP service.

[0013] In one embodiment, the method further includes: The MCP service is tested, and if the tool performs as expected, the MCP service is released. If the tool does not perform as expected, the code is adjusted through the web interface, and the following steps are performed: obtaining the code of the MCP service edited through the web interface.

[0014] A second aspect of this application provides an MCP service publishing apparatus, the apparatus comprising: The code acquisition module is used to acquire the code of the MCP service that can be edited through the web interface; The code parsing module is used to parse the code obtained by the code acquisition module and obtain the functions of the code; The tool building module is used to build tools for the MCP service based on the functions obtained by the code parsing module; The service assembly module is used to create an MCP service instance of the MCP service, associate the tool built by the tool building module with the function obtained by the code parsing module and register them with the MCP service instance, and assemble the MCP service. The publishing management module is used to publish the MCP service based on the service metadata of the MCP service obtained by the service assembly module.

[0015] A third aspect of this application provides an MCP service publishing system, the system comprising a front-end and a back-end, the back-end comprising: Processor; and A memory that stores executable code, which, when executed by the processor, causes the processor to perform the method described above.

[0016] A fourth aspect of this application provides a computer-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to perform the method described above.

[0017] The fifth aspect of this application provides a computer program product comprising computer instructions that, when executed by a processor, implement the method described above.

[0018] The technical solution provided in this application may include the following beneficial results: The technical solution of this application is based on the code of MCP service edited by the web interface, and the tool for creating MCP service that meets the requirements. The tool can flexibly define MCP service, reduce the difficulty and cost of MCP service development and deployment, and improve the efficiency of MCP service release.

[0019] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0020] The above and other objects, features and advantages of this application will become more apparent from the more detailed description of exemplary embodiments thereof in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments thereof.

[0021] Figure 1 This is a flowchart illustrating the MCP service publishing method according to an embodiment of this application; Figure 2 This is another flowchart illustrating the MCP service publishing method shown in the embodiments of this application; Figure 3 This is a schematic diagram of the structure of the MCP service publishing device shown in the embodiments of this application; Figure 4 This is a functional schematic diagram of the MCP service publishing system shown in the embodiments of this application; Figure 5 This is a schematic diagram illustrating the process of implementing MCP service publishing in the MCP service publishing system as shown in the embodiments of this application; Figure 6 This is another schematic diagram illustrating the process of implementing MCP service publishing in the MCP service publishing system shown in the embodiments of this application; Figure 7 This is a schematic diagram of the backend structure shown in an embodiment of this application. Detailed Implementation

[0022] Embodiments of this application will now be described in more detail with reference to the accompanying drawings. While embodiments of this application are shown in the drawings, it should be understood that this application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to make this application more thorough and complete, and to fully convey the scope of this application to those skilled in the art.

[0023] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

[0024] It should be understood that although the terms "first," "second," "third," etc., may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.

[0025] This application provides an MCP service publishing method that can flexibly define tools for MCP services, reduce the difficulty and cost of MCP service development and deployment, and improve the efficiency of MCP service publishing.

[0026] The technical solutions of the embodiments of this application are described in detail below with reference to the accompanying drawings.

[0027] Figure 1 This is a flowchart illustrating the MCP service publishing method in an embodiment of this application.

[0028] See Figure 1 A method for publishing MCP services, comprising: Step 101: Obtain the code for the MCP service edited via the web interface.

[0029] In one embodiment, a user can dynamically edit the code of an MCP service through a web interface. The code of the MCP service, dynamically edited via the web interface, can be obtained through the web interface.

[0030] Step 102: parse the code of the MCP service and obtain the functions in the code.

[0031] In one embodiment, the code of the MCP service can be parsed to extract each function defined in the code.

[0032] Step 103: Based on the function, construct the tool for the MCP service.

[0033] In one embodiment, each tool of the MCP service corresponding to each function can be constructed based on each function defined in the code and the description requirements of the tool in the MCP protocol.

[0034] Step 104: Create an MCP service instance, associate and register tools and functions with the MCP service instance, and assemble the MCP service.

[0035] In one embodiment, an independent MCP service instance can be created for the MCP service. Based on the tool name of each tool and the function name of each function in the code, the tool is associated with the corresponding function. The associated tools and functions are then registered in the MCP service instance to assemble the MCP service.

[0036] Step 105: Publish the MCP service based on the service metadata of the MCP service.

[0037] In one embodiment, when creating an MCP service instance, service metadata of the MCP service can be configured; based on the service metadata of the MCP service, routing and request handling functions of the MCP service are generated, and the routing and request handling functions of the MCP service are associated with and registered with the relevant servers to complete the publication of the MCP service.

[0038] The MCP service publishing method of this application embodiment is based on the code of the MCP service edited by the web interface, and creates a tool for the MCP service that meets the requirements. The tool can flexibly define the MCP service, reduce the difficulty and cost of MCP service development and deployment, and improve the efficiency of MCP service publishing.

[0039] Figure 2 This is another flowchart illustrating the MCP service publishing method in an embodiment of this application. Figure 2 Compared to Figure 1 The technical solution of this application is described in more detail.

[0040] See Figure 2 A method for publishing MCP services, comprising: Step 201: Obtain the code for the MCP service edited via the web interface.

[0041] In one embodiment, an online code editor with a web interface can be built based on vue-codemirror6 (a code editor component). This online code editor supports syntax highlighting, auto-completion, error reporting, type annotation suggestions, and real-time syntax checking based on a Python syntax parser. Users can dynamically edit the Python code of the MCP service online through the web interface of the online code editor, according to the business logic of the MCP service.

[0042] In one embodiment, the Python code for the MCP service can be edited via an online code editor's web interface, based on the service's business logic. This Python code can be Python functions (e.g., data calculations, API calls, etc.) containing the service's business logic. Type annotations can be used to define the function's parameters and return values, and docstrings can be added to describe the function's functionality. Once the MCP service's Python code is complete, it can be submitted to the backend via the online code editor. The backend then publishes the MCP service using this Python code, eliminating the need for local development environment configuration, thus reducing development complexity and improving efficiency.

[0043] Step 202: Parse the code of the MCP service, obtain the functions in the code, and build the tool for the MCP service based on the functions.

[0044] In one embodiment, the code of the MCP service can be parsed to construct a syntax structure tree of the code; the syntax structure tree can be traversed to obtain the functions of the code and the function information of the functions; and a tool for constructing the MCP service can be built based on the functions of the code and the function information of the functions.

[0045] In one embodiment, the Python code of the MCP service can be statically analyzed using an Abstract Syntax Tree (AST) to construct a syntax tree structure for the Python code, identify the Python function definition nodes, and extract the Python functions and their function information, including but not limited to the function name, parameter list (args), and docstring. Based on the function information, a tool conforming to the MCP protocol specification is generated for the MCP service. The tool's metadata includes, but is not limited to, the tool name, tool description, input schema, and output schema.

[0046] In one embodiment, the function name of the Python function can be determined as the tool name; the input schema and output schema of the tool can be determined based on the parameter list (args) of the Python function; and the docstring of the Python function can be determined as the tool description. Generating tools for the MCP service from Python code automates the code-to-tool conversion, eliminating the limitations of pre-built tools, creating custom tools that meet specific needs, without requiring backend knowledge or manually writing tool configuration files. This reduces manual configuration errors, lowers the development difficulty of the MCP service, supports rapid iteration of the MCP service, and improves the release efficiency of the MCP service.

[0047] For example, for the Python function `def get_weather(city: str) ->str`, the function name "get_weather" can be extracted as the tool's name, the input schema can be determined based on "city (string type)", and the tool description can be determined based on the Python function's docstring.

[0048] In one embodiment, the backend receives Python code submitted through an online code editor on the frontend; it uses Python's AST module or other code analysis libraries to statically parse the Python code and construct a syntax structure tree; it traverses the syntax structure tree, identifies all function definition nodes in the Python code (e.g., nodes of type ast.FunctionDef), obtains all Python functions defined in the Python code, and extracts function information for each Python function, including but not limited to function name, parameter list (args), docstring, and function body; it then organizes the extracted function information for each Python function into structured tool metadata according to the description requirements of the MCP service tools in the MCP protocol. Tool metadata may include, but is not limited to, tool name, tool description, input schema, and output schema.

[0049] In one embodiment, the function name (name) of a Python function and the tool name (name) of a tool can be represented by an ID.

[0050] In one embodiment, the docstring of the Python function and the detailed description of the parameters and return values ​​contained in the docstring can be extracted together; based on the docstring of the Python function and the detailed description of the parameters and return values ​​contained in the docstring, the tool description of the tool can be determined.

[0051] In one embodiment, the parameter list (args) of the Python function, the type annotations or default values ​​included in the parameter list (args), and the return object class of the Python function can be extracted simultaneously. Based on the parameter list (args), the type annotations or default values ​​included in the parameter list (args), and the return object class of the Python function, the tool's input schema (inputSchema) and output schema (outputSchema) are constructed respectively. The input schema (inputSchema) describes the input parameter types and constraints. The output schema (outputSchema) describes the structure of the returned result.

[0052] In one embodiment, the syntactic correctness of the function body of each Python function is a prerequisite for the normal operation of each tool in the MCP service. A syntax check can be performed on the function body of each Python function to determine its syntactic correctness. If a syntax error exists in the function body, the Python code of the Python function is corrected through the web interface of the online code editor, the corrected Python code is saved and submitted, and step 201 continues. If no syntax error exists in the function body, step 203 is executed.

[0053] Step 203: Create an MCP service instance, associate the tools and functions of the MCP service, and assemble the MCP service.

[0054] In one embodiment, an MCP service instance can be created; the tool and function are associated according to the tool name and the function name, and the associated tool and function are registered in the MCP service instance to assemble the MCP service.

[0055] In one embodiment, the MCP service can be dynamically assembled within an MCP service instance based on functions in the MCP service's Python code and tools. The MCP Python SDK can be invoked to initialize the MCP service instance based on these functions and tools. The `register_tool` method of the MCP Python SDK (a method for registering custom tools) associates the Python function with the tool's metadata and the Python function's function information, binding the tool and Python function together. This registers the Python function as a tool for the MCP service and configures the service metadata, including but not limited to service name, service version, host address, and port. Initializing the MCP service instance through the MCP Python SDK automates the assembly of the MCP service and automatically encapsulates the underlying logic of the MCP protocol (e.g., request processing, response format). This eliminates the need to focus on the details of the MCP protocol, generating an MCP service that conforms to the MCP protocol specification. Users only need to focus on the core logic of the tools, reducing the development difficulty of the MCP service and improving its compatibility and development efficiency with clients. The MCP Python SDK also facilitates future upgrades, reducing the maintenance cost of the MCP service.

[0056] In one embodiment, the backend can use a pre-integrated or custom MCP Python SDK to create a FastMCP instance, which is then used as an object to host the tools for the MCP service. Based on the tool name (name) of each tool and the function name (name) of each Python function, the Python function corresponding to the tool name (name) is loaded into the current execution environment using importlib (Python's standard library module) or other mechanisms. Using the register_tool provided by the FastMCP instance, the Python functions in the Python code are associated with the tools of the MCP service and registered with the FastMCP instance. Calls to the Python functions are encapsulated into processing logic conforming to the MCP protocol. The FastMCP instance is configured accordingly, setting the service metadata of the MCP service, including but not limited to service name (name), service version (version), host address (host), and port (port). All tools for the MCP service are registered with the FastMCP instance, completing the FastMCP instantiation and assembling the MCP service.

[0057] In one embodiment, service metadata for the MCP service can be supplemented through the web configuration interface of the MCP service configuration unit. This supplemented service metadata includes, but is not limited to, tool name, protocol type, and service path. The ProtocolType enumeration can distinguish between the SSE protocol and streaming HTTP; the sse_url field stores the service path.

[0058] In one embodiment, the SSE (Server-Sent Events) protocol, based on the HTTP (Hypertext Transfer Protocol) protocol, pushes data unidirectionally from the server to the client, which is suitable for real-time update scenarios. The MCP service can use it to realize the transmission of streaming tool call results.

[0059] In one embodiment, Streamable HTTP (Streamable Hypertext Transfer Protocol), an enhanced transport protocol based on HTTP in the MCP protocol suite, is an upgraded and optimized version of the HTTP+SSE protocol. Streamable HTTP is based on ordinary HTTP requests, supporting clients to initiate requests using POST or GET, and the server can upgrade the response to streaming transmission as needed. Streamable HTTP features decentralization and non-forced long-connection characteristics, supports stateless mode to reduce server load, while retaining the advantages of streaming responses, is compatible with HTTP infrastructure, and is suitable for model interaction data transmission in high-concurrency scenarios.

[0060] Step 204: Publish the MCP service based on the service metadata of the MCP service.

[0061] In one embodiment, an MCP service can be published based on the service metadata of the MCP service, which includes the service name, tool name, and protocol type of the MCP service.

[0062] In one embodiment, a route for the tool is generated based on the service name, tool name, and protocol type of the MCP service; a request processing function for the tool is created based on the function corresponding to the tool; the tool's route is associated with the request processing function and registered with the server to publish the MCP service.

[0063] In one embodiment, API (Application Programming Interface) endpoint URLs (Uniform Resource Locators) for tools within the MCP service can be generated based on the service metadata of the MCP service. These API endpoint URLs are then dynamically registered with the Starlette (a lightweight ASGI framework) service, enabling dynamic publishing of the MCP service. Based on the protocol type of the MCP service (e.g., streaming HTTP or SSE), a unique API endpoint URL is generated for each tool. This API endpoint URL is used as the tool's route, and a request handling function is created for each tool. Using the Starlette framework, the `add_route` method is used to associate each tool's route with its request handling function, dynamically registering the route with the Starlette framework service. The MCP service takes effect without requiring a restart of the Starlette framework service, enabling online editing and publishing of the MCP service. Dynamic route registration and flexible publishing of the MCP service allow for immediate service activation, achieving "hot reloading" and ensuring continuous availability of the MCP service.

[0064] In one embodiment, publishing an MCP service based on the service metadata of the MCP service may include: Step 2041: Obtain the service metadata and tools for the MCP service.

[0065] Step 2042: Determine the communication protocol of the MCP service based on the protocol type of the MCP service.

[0066] In one embodiment, the communication protocol of the MCP service can be determined based on the protocol type of the MCP service. For example, the SSE protocol and streaming HTTP can be distinguished by enumerating the protocol type of the MCP service; the communication protocol (SSE or streaming HTTP) of the MCP service can be determined based on the protocol type of the MCP service.

[0067] Step 2043: Generate the tool route based on the communication protocol of the MCP service, the service name of the MCP service, and the tool name of the tool.

[0068] In one embodiment, based on the communication protocol of the MCP service, the service name (name), and the tool name (name) of each tool in the MCP service, an API endpoint URL conforming to the API routing rules is generated for each tool in the MCP service. The API endpoint URL of each tool is unique and standardized.

[0069] In one embodiment, the routing specification for streaming HTTP is as follows: StreamableHTTP: / mcp / {service_id}-{uuid6} / stream.

[0070] The routing specifications for the SSE protocol are as follows: SSE: / mcp / {service_id}-{uuid6} / sse, / mcp / {service_id}-{uuid6} / message.

[0071] service_id represents the service name; uuid6 represents a random 6-digit character that can be used to distinguish MCP services.

[0072] Step 2044: Create the request handling function for the tool that provides the MCP service.

[0073] In one embodiment, for each tool in the MCP service, an asynchronous or synchronous request handling function conforming to the Starlette framework requirements is created. The request handling function can receive HTTP requests from the MCP client or other HTTP clients, invoke the corresponding tool in the MCP service based on the HTTP request, and return the tool's execution result according to the communication protocol.

[0074] In one embodiment, the processing logic of the request handling function may include extracting parameters from the HTTP request, including path parameters, query parameters, and request body parameters. The function then calls the handle method of the corresponding tool in the MCP service, or a similar API provided by the SDK, passing the extracted parameters to the called handle method or similar API to obtain the tool's execution result. The execution result is then encapsulated into an HTTP response according to the MCP protocol and the MCP service communication protocol (streaming HTTP or SSE protocol). If the MCP service's communication protocol is SSE, the request handling function needs to be able to continuously push event streams to the client.

[0075] Step 2045: Associate the tool's route with the request handling function and register it with the Starlette server.

[0076] In one embodiment, the tool's route is dynamically associated with the corresponding request handling function through the API provided by the Starlette framework (e.g., app.add_route()), and registered with the core router of the Starlette framework application, thus completing the publication of the MCP service.

[0077] Step 2046: MCP service activation and access.

[0078] In one embodiment, the tools of the MCP service are invoked by the MCP client or other HTTP clients through the tool's routing. The Starlette framework server Uvicorn (a high-performance web server based on the ASGI standard) receives the HTTP request, matches it with the routing of the tools of the MCP service, dispatches the HTTP request to the request handling function associated with the route based on the route, invokes the tools of the MCP service through the request handling function, and returns the result according to the communication protocol of the MCP service.

[0079] In one embodiment, the tools and functions of the MCP service are dynamically assembled into an MCP service using the MCP Python SDK, and dynamic routes are generated based on the Starlette framework. This supports the simultaneous publication of MCP services using both streaming HTTP and SSE protocols, and the service takes effect without restarting. The MCP service can be published and updated in real time, adapting to real-time data push scenarios, thus solving the problems of MCP service publication requiring restart and limited protocol support in related technologies.

[0080] Step 205: Test and debug the MCP service.

[0081] In one embodiment, the MCP service can be tested. If the execution of the MCP service tool is as expected, the MCP service is determined to be published. If the execution of the tool is not as expected, the code of the MCP service is adjusted through the web interface, and the next step is to obtain the code of the MCP service edited through the web interface.

[0082] In one embodiment, the functionality of the tool for testing the published MCP service can be tested by directly inputting test parameters through a web testing interface, forming a closed loop of "edit-publish-test".

[0083] The MCP service publishing method in this application embodiment utilizes an online Python code editor for MCP services to create a tool for customizing MCP services, enabling dynamic assembly and publishing of MCP services. This transforms the MCP service publishing process from a development and deployment model requiring significant manual intervention into a highly automated, online, and real-time workflow. The web-interface-based code implementation for MCP services allows for "compile and publish" of MCP services, significantly improving tool customization flexibility and reducing the difficulty of MCP service development and deployment. This not only drastically shortens the cycle from idea to a working MCP service but also makes MCP service applications more flexible and easier to iterate, enabling MCP services to better adapt to rapidly changing project needs. By publishing MCP services using both the SSE protocol and streaming HTTP, and simultaneously supporting private intranet deployment of MCP services, the method meets enterprise data security and real-time interaction requirements. The MCP service's compatibility with both the SSE protocol and streaming HTTP enhances its applicability and improves server resource utilization.

[0084] The MCP service publishing method of this application dynamically transforms Python code into MCP services, achieving a highly efficient "code-as-a-service" experience through automated processing. This method allows users to directly write Python code using an online Python code editor within a web interface. It automatically parses the Python code, extracting function names, parameters, and docstrings. Based on these information, it dynamically generates tool metadata conforming to the MCP specification, enabling online Python code editing and dynamic tool generation via a web interface. Custom Python functions and tool metadata are automatically registered in the MCP Server instance. The SDK encapsulates the underlying logic of the MCP protocol and manages the tool lifecycle. The Starlette framework is used as the underlying foundation to dynamically generate API routes for each tool in the MCP service. A request handling function is created for each tool, and the API routes and request handling functions are registered in real-time with the running web service via Starlette's API. Supporting StreamableHTTP and SSE protocols, MCP service publishing can be achieved without restarting the web service, enabling dynamic route registration and flexible MCP service publishing.

[0085] Corresponding to the aforementioned application function implementation method embodiments, this application also provides an MCP service publishing device, system, and corresponding embodiments.

[0086] Figure 3 This is a schematic diagram of the structure of the MCP service publishing device shown in the embodiments of this application.

[0087] See Figure 3 An MCP service publishing device includes a code acquisition module 301, a code parsing module 302, a tool building module 303, a service assembly module 304, and a publishing management module 305.

[0088] The code acquisition module 301 is used to acquire the code of the MCP service edited through the web interface.

[0089] In one embodiment, a user can dynamically edit the code of an MCP service through a web interface. The code acquisition module 301 acquires the dynamically edited MCP service code through the web interface.

[0090] The code parsing module 302 is used to parse the code obtained by the code acquisition module 301 and to acquire the code functions.

[0091] In one embodiment, the code parsing module 302 can parse the code of the MCP service obtained by the code acquisition module 301 and extract each function defined in the code.

[0092] Tool building module 303 is used to build a tool for MCP service based on the functions obtained by code parsing module 302.

[0093] In one embodiment, the tool building module 303 can build each tool of the MCP service corresponding to each function according to each function defined in the code and the description requirements of the MCP protocol for the tool.

[0094] Service assembly module 304 is used to create an MCP service instance, associate the tools built by the tool building module with the functions obtained by the code parsing module and register them with the MCP service instance, and assemble the MCP service.

[0095] In one embodiment, the service assembly module 304 can create an independent MCP service instance for the MCP service, associate the tool with the corresponding function according to the tool name of each tool and the function name of each function in the code, register the associated tool and function with the MCP service instance, and assemble the MCP service.

[0096] The publishing management module 305 is used to publish the MCP service based on the service metadata of the MCP service obtained by the service assembly module 304.

[0097] In one embodiment, when creating an MCP service instance, the service metadata of the MCP service can be configured; the publishing management module 305 generates the routing and request processing functions of the MCP service based on the service metadata of the MCP service, associates the routing and request processing functions of the MCP service with the relevant servers, and completes the publishing of the MCP service.

[0098] The technical solution of this application embodiment is based on the code of MCP service edited by the Web interface, creating a tool that meets the requirements of MCP service. This tool can flexibly define MCP service, reduce the difficulty and cost of MCP service development and deployment, and improve the efficiency of MCP service release.

[0099] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated further here.

[0100] Figure 4 This is a functional schematic diagram of the MCP service publishing system shown in the embodiments of this application; Figure 5 This is a schematic diagram illustrating the process of implementing MCP service publishing in the MCP service publishing system as shown in the embodiments of this application; Figure 6 This is another schematic diagram illustrating the process of implementing MCP service publishing in the MCP service publishing system shown in the embodiments of this application.

[0101] See Figure 4 This is an MCP service publishing system, comprising a front-end and a back-end. The front-end provides an interactive interface via a web interface, enabling MCP service configuration, online code editing, MCP service publishing management, and tool testing and debugging. The back-end may include a Uvicorm server running on the Starlette framework, core services, and a FastMCP container. The Uvicorm server can use SSE protocol and streaming HTTP for communication. The core services include a Python execution environment and sandbox, code parsing, MCP tool extraction, MCP service assembly, MCP dynamic route registration, and MCP testing and debugging.

[0102] See Figure 5 and Figure 6 The MCP service publishing system can implement the entire process of creating, editing, publishing, and testing a custom MCP service based on Python code. The steps include: Step 501: Select or create an MCP service instance.

[0103] In one embodiment, an MCP service instance can be selected or created based on a template through the front-end MCP service configuration web interface. By selecting an MCP service instance with similar business logic to the MCP service as a starting point on the web interface and clicking "Create based on this template" or a similar button, a new MCP service instance is created and pre-populated with the MCP service instance's code and configuration.

[0104] In one embodiment, users can select "Create a new MCP service" or "Blank template" in the MCP service configuration web interface to create a new MCP service instance and pre-populate the code and configuration of the MCP service instance.

[0105] Step 502: Edit the code for the MCP service online to define the tool for the MCP service.

[0106] In one embodiment, the online code editing web interface of the front-end online code editor can be accessed through "MCP Square - Code Editor," which is a built-in web-based Python code editor. In the web interface, Python code implementing the business logic of the MCP service can be written or modified. For example, a Python function named `calculate_discount(price: float, rate: float) ->float` can be written to calculate the discounted price. A docstring describing the function's functionality and parameters can be added above the function. The Python code for this function is as follows: def calculate_discount(price: float, rate: float) ->float: """ Calculate the discounted price. Args: price (float): The original price. rate (float): The discount rate (eg, 0.1 for 10% off). Returns: float: The discounted price. """ if rate < 0 or rate > 1: raise ValueError("Discount rate must be between 0 and 1.") return price * (1 - rate).

[0107] In one embodiment, after the Python code is written, you can click the "Save" button on the web interface to save the current version of the Python code to the draft area.

[0108] Step 503: Configure the service metadata of the MCP service and the tool metadata of the tools.

[0109] In one embodiment, upon entering the web interface for configuring the front-end MCP service, the front-end sends the Python code of the MCP service to the back-end. Based on the Python code of the MCP service, the back-end automatically parses the Python functions defined when editing the Python code in the online code editor and displays them as tools of the MCP service to be configured. The back-end then displays the tool metadata extracted from the Python code through the web interface for configuring the MCP service. The tool metadata includes, but is not limited to, tool name, tool description, input schema, and output schema.

[0110] In one embodiment, tool metadata can be confirmed or supplemented through a web interface configured by the MCP service.

[0111] For example, the tool description can be directly used as the tool description if the docstring in the Python code is clear enough. Alternatively, the description can be modified or supplemented through the web interface configured in the MCP service.

[0112] InputSchema parameter types and constraints: Although Python is a dynamically typed language, it allows specifying parameter types (e.g., number, string, boolean, etc., types supported by MCP) via type annotations (e.g., float in the example) or explicitly through the web interface configured in the MCP service. For the utility `calculate_discount` (a tool for calculating discounted prices), `price` and `rate` should be configured as type `number`. Constraints such as whether parameters are required, default values, and value ranges (e.g., `rate` should be between 0 and 1) can also be set.

[0113] The output schema describes the data structure of the tool's output. For `calculate_discount`, the output is a float type number.

[0114] In one embodiment, the service metadata of the MCP service, such as service name, service version, and protocol type, can be configured through the web interface configured for the MCP service.

[0115] In one embodiment, an MCP service can be assembled in an MCP service instance based on the service metadata of the MCP service, the tool metadata of the tool, and the function of the tool.

[0116] Step 504: Publish the MCP service.

[0117] In one embodiment, the web interface for managing the front-end MCP service publishing can be accessed through "MCP Square - Publishing Service". Clicking the "Publish" or "Deploy" button on the web interface triggers a publishing request for the MCP service. Upon receiving the publishing request, the backend can parse the submitted Python code of the MCP service again to ensure the latest tool definitions are obtained. Using the integrated MCPPython SDK, the parsed Python functions (e.g., the `calculate_discount` function) and tool metadata are registered with the MCP service instance to assemble the MCP service. A unique API route (e.g., ` / mcp / DiscountCalculatorService-3es0d1 / sse`) for the MCP service's tools is generated based on the MCP service's service name (e.g., an automatically generated UUID or a specified service name), tool name (e.g., `calculate_discount`), and publishing protocol (the communication protocol of the MCP service). The tool route and the tool's request handling function (calling the request handling logic of the `calculate_discount` tool in the MCP service) are dynamically registered in the underlying Starlette service. Tools of the MCP service (such as calculate_discount) can be invoked through routes registered in the underlying Starlette service.

[0118] In one embodiment, the backend can select the publishing protocol of the MCP service (SSE protocol and streaming HTTP) based on the protocol type of the MCP service.

[0119] Step 505: Testing and debugging of tools for the MCP service.

[0120] In one embodiment, the web interface for testing and debugging front-end tools can be accessed through "MCP Square - Tool Testing." Clicking "Run Test" or a similar button sends a test request to the backend for testing and debugging tools of the MCP service. The backend selects a tool (e.g., calculate_discount) from the published MCP service based on the test request, and obtains the required test parameters (e.g., price and rate required by the calculate_discount tool) through the web interface. It then calls the tool of the MCP service (e.g., calculate_discount tool), returns the execution results and log information of the tool to the web interface, and determines whether the execution of the tool meets expectations. If the execution meets expectations, the MCP service is released. If the execution does not meet expectations, step 502 is executed, returning to the online code editing web interface to modify the MCP service code until the execution of the tool meets expectations (implementing the set business logic).

[0121] The MCP service publishing system of this application embodiment allows direct online editing of MCP service Python code via a web interface. The business logic of the MCP service is encapsulated into Python functions through Python code, and the tools for the MCP service are flexibly defined through Python functions. The Python functions are then transformed into callable tools for the MCP service, greatly expanding the source and diversity of MCP service tools. This makes the tools for MCP services no longer limited to the fixed set of tools provided, and can better serve the needs of various projects. It solves the problems of insufficient customization capabilities, cumbersome deployment, and single interaction mode of related technologies' MCP service tools.

[0122] The MCP service publishing system of this application integrates functions such as code editing, tool management, service publishing, and testing and debugging into a unified web interface. All operations in the lifecycle of the MCP service can be completed through the web interface, improving the experience and operational efficiency of MCP service publishing.

[0123] The MCP service publishing system of this application embodiment dynamically publishes MCP services based on Python code. Through full-process automation of "online editing - automatic parsing - dynamic assembly - instant publishing," it solves the problems of insufficient customization capabilities and cumbersome deployment of related MCP service tools. The MCP service publishing system adopts a front-end and back-end separation architecture, collaboratively realizing end-to-end management of MCP services from code to usable service. It achieves online editing, dynamic parsing, SDK assembly, and dynamic routing publishing of MCP services. Based on the web interface for editing MCP service code, tools for creating MCP services that meet requirements can be flexibly defined, reducing the difficulty and cost of MCP service development and deployment, and improving the efficiency of MCP service publishing.

[0124] Regarding the MCP service publishing system in the above embodiments, the specific methods by which each unit or module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated further here.

[0125] Figure 7 This is a schematic diagram of the structure of the 7-back end shown in the embodiment of this application.

[0126] See Figure 7 The back-end 1000 includes a memory 1010 and a processor 1020.

[0127] The processor 1020 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0128] Memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. ROM may store static data or instructions required by processor 1020 or other modules of the computer. Permanent storage devices may be read-write storage devices. Permanent storage devices may be non-volatile storage devices that retain stored instructions and data even when the computer is powered off. In some embodiments, permanent storage devices use mass storage devices (e.g., magnetic or optical disks, flash memory) as permanent storage devices. In other embodiments, permanent storage devices may be removable storage devices (e.g., floppy disks, optical drives). System memory may be a read-write storage device or a volatile read-write storage device, such as dynamic random access memory. System memory may store some or all of the instructions and data required by the processor during operation. Furthermore, memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (e.g., DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, memory 1010 may include a removable storage device that is readable and / or writable, such as a laser disc (CD), a read-only digital multifunction optical disc (e.g., DVD-ROM, dual-layer DVD-ROM), a read-only Blu-ray disc, an ultra-high density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not contain carrier waves or transient electronic signals transmitted wirelessly or via wired connections.

[0129] The memory 1010 stores executable code, which, when processed by the processor 1020, can cause the processor 1020 to execute part or all of the methods described above.

[0130] Furthermore, the method according to this application can also be implemented as a computer program or computer program product, which includes computer program code instructions for performing some or all of the steps in the method described above.

[0131] Alternatively, this application may also be implemented as a computer-readable storage medium (or a non-transitory machine-readable storage medium or a machine-readable storage medium) storing executable code (or computer program or computer instruction code) that, when executed by a processor in a back-end (or electronic device, or server, etc.), causes the processor to perform part or all of the steps of the methods described above according to this application.

[0132] This application also provides a computer program product, which includes computer instructions that, when executed by a processor, implement the above-described method.

[0133] The various embodiments of this application have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A method for publishing MCP services, characterized in that, The method comprises: acquiring code of an MCP service edited through a web interface; parsing the code to acquire functions of the code; constructing tools of the MCP service according to the functions; creating an MCP service instance of the MCP service, associating the tools with the functions and registering the tools with the MCP service instance to assemble the MCP service; publishing the MCP service according to service metadata of the MCP service.

2. The method of claim 1, wherein, The parsing the code to acquire functions of the code comprises: parsing the code to construct a syntax structure tree of the code; traversing the syntax structure tree to acquire the functions of the code and function information of the functions.

3. The method of claim 2, wherein, The constructing tools of the MCP service according to the functions comprises: constructing the tools of the MCP service according to the functions of the code and the function information of the functions.

4. The method of claim 3, wherein, The creating an MCP service instance of the MCP service, associating the tools with the functions and registering the tools with the MCP service instance to assemble the MCP service comprises: creating an MCP service instance of the MCP service; associating the tools with the functions and registering the tools with the MCP service instance according to function names of the functions and tool names of the tools to assemble the MCP service.

5. The method of claim 4, wherein, The publishing the MCP service according to service metadata of the MCP service comprises: publishing the MCP service according to service metadata of the MCP service, the service metadata comprising a service name, tool names and a protocol type of the MCP service.

6. The method of claim 5, wherein, The publishing the MCP service according to service metadata of the MCP service comprises: generating a route of the tools according to the service name, the tool names and the protocol type; creating a request processing function of the tools according to the functions corresponding to the tools; associating the route with the request processing function and registering the route with a server to publish the MCP service.

7. The method of claim 1, wherein, The method further comprises: testing the MCP service, and determining the publishing of the MCP service if execution of the tools is as expected; if the execution of the tools is not as expected, adjusting the code through the web interface and continuing to acquire code of an MCP service edited through a web interface.

8. An MCP service publishing apparatus characterized by comprising: The method comprises: a code acquisition module configured to acquire code of an MCP service edited through a web interface; a code parsing module configured to parse the code acquired by the code acquisition module to acquire functions of the code; a tool construction module configured to construct tools of the MCP service according to the functions acquired by the code parsing module; a service assembly module configured to create an MCP service instance of the MCP service, associate the tools constructed by the tool construction module with the functions acquired by the code parsing module and register the tools with the MCP service instance to assemble the MCP service; a publishing management module configured to publish the MCP service according to service metadata of the MCP service acquired by the service assembly module.

9. A MCP service publishing system, characterized by, The method comprises: a front end and a back end, the back end comprising: a processor; and a memory. a memory having stored thereon executable code that, when executed by the processor, is to cause the processor to carry out the method of any of claims 1-7.

10. A computer-readable storage medium, characterized in that, a memory having stored thereon executable code that, when executed by the processor, is to cause the processor to carry out the method of any of claims 1-7.