The utility is here to convert existing OpenAPI in bulk to MCP Server
ChengTan & Wang Chen
|
Apr 10, 2025
|
Convert existing OpenAPI into MCP Server in batches. This is the latest open-source capability from Higress, helping developers efficiently build MCP Server. [1]
Table of Contents
01. Relevant Concepts of OpenAPI
02. Common Practices for Converting Existing OpenAPI into MCP Server
03. Batch Conversion of OpenAPI to MCP Server
04. Tuning Configuration for MCP Server
05. Conclusion
01 Relevant Concepts of OpenAPI
OpenAPI is written in YAML or JSON and defines a language-agnostic HTTP API interface, providing a unified way to transmit information across all stages of the API life cycle. APIs allow developers to discover and use corresponding services without having to access the source code. For example, a social app wanting to obtain the geographical location information of both parties does not need to build its own Gaode Map or obtain its source code, but can instead receive geographical location information functionality through the Gaode Map API interface.
Classic internet applications such as Gaode Map and Alipay provide API services externally through an open platform. Public cloud services, such as Alibaba Cloud, offer API services to users through OpenAPI Explorer, allowing developers to manage cloud resources, data, and services through these APIs. Additionally, AI large models such as Tongyi, DeepSeek, and OpenAI offer access to large models via APIs. These APIs all comply with the OpenAPI specification; having standards enables efficient collaboration.
02 Common Practices for Converting Existing OpenAPI into MCP Server
MCP allows LLM to access external resources, data, and services in a standardized way. Converting existing OpenAPI into MCP Server is a useful reuse strategy and an economically efficient path that aims to enable external AI applications to invoke your services, thereby enhancing the value of existing services. For instance, Gaode Map provides the capability to convert existing OpenAPI services such as IP positioning and geocoding into MCP Server, allowing external applications to utilize Gaode Map capabilities, thus increasing service activity.
Although MCP has significantly reduced the complexity of accessing and invoking external resources, data, and services for large model applications, if you adopt reuse of existing infrastructure as a development strategy for MCP, you will face a new challenge: converting existing OpenAPI into MCP Server is a "repetitive manual task" that requires daily maintenance, including interface updates and server stability assurances. MCP provides SDK toolkits such as TypeScript and Java for developing MCP Server, exposing existing OpenAPI as regular HTTP services through MCP protocol. This process includes: [1]
Reading and parsing the existing OpenAPI documents, extracting key information such as API paths, request methods, request parameters, response formats, etc.
Transforming into new descriptions according to MCP protocol specifications, including tool functionality description and tool parameter description, returning the
tool/list
results to the client.When the MCP client wants to call the MCP server, it parses the Json RPC request from
tool/call
, generates the backend HTTP call request using the mapped parameter configuration, Path, backend address, etc., and executes the call. After the call is completed, it wraps the backend call result to return the result for the standardtool/call
interface.
03 Batch Conversion of OpenAPI to MCP Server
1.1 Installation
1.2 Usage
Instructions
--input
: The path to the OpenAPI specification file (in JSON or YAML format), required.--output
: The path for the output MCP configuration file (in YAML format), required.--server-name
: The name of the MCP server, default value is "openapi-server".--tool-prefix
: The prefix for tool names, default value is empty.--format
: Output format (yaml or json), default value is "yaml".--validate
: Whether to validate the OpenAPI specification, default value is false.--template
: The path to the template file used for fixing the output, default value is empty.
1.3 Example
This example converts petstore.json
into the petstore-mcp.yaml
file and sets the MCP server name to petstore
.
Here is the complete example.
a. Start with an OpenAPI specification (petstore.json):
b. Convert it into Higress REST-to-MCP configuration:
c. Generate petstore-mcp.yaml file:
Note that the tool will automatically set the position field based on the location of each parameter in the OpenAPI specification:
The
petId
parameter is set toposition: path
, as it is defined asin: path
in the OpenAPI specification.The
limit
parameter is set toposition: query
, as it is defined asin: query
in the OpenAPI specification.The request body properties (
name
andtag
) are set toposition: body
.
The MCP server will automatically handle these parameters in the correct position when initiating API requests. For more information on how to use this configuration with Higress REST-to-MCP, please refer to the Higress REST-to-MCP documentation. [2]
1.4 Functionality
Convert OpenAPI paths to MCP tools.
Support OpenAPI specifications in JSON and YAML formats.
Generate MCP configuration containing server and tool definitions.
Preserve parameter descriptions and types.
Automatically set parameter positions based on OpenAPI parameter positions (path, query, header, cookie, request body).
Handle path, query, header, cookie, and request body parameters.
Generate response templates with field descriptions and improved formats for better understanding by large language models (LLMs).
Optional validation of the OpenAPI specification (disabled by default).
1.4 Configure MCP Server Plugin
Next, we will import the generated file into the Higress console, add the MCP Server plugin, and configure it for use together with Higress.
Example of plugin configuration:
Note: For the MCP streamable HTTP protocol dated 2025-03-26, this plugin can be used directly without global ConfigMap configuration.
1.5 Calling MCP Server
Configure the SSE connection for MCP Server in the AI Agent, taking Cursor as an example:
Database-type MCP Server: Use path + sse_path_suffix configured in ConfigMap
REST API-type MCP Server: Use routing path + sse_path_suffix configured in the console
Configuration completed in Cursor:

Through the MCP Server, you can quickly add various data source support for AI agents, improving development efficiency. Any REST API can be transformed into MCP Server with simple configuration without writing additional code.
04 Tuning Configuration for MCP Server
In the previous chapters, we have learned how the OpenAPI to MCP tool helps us quickly convert existing APIs into tools that can be invoked by AI assistants. This automated conversion greatly improves development efficiency, allowing us to accomplish what would originally take hours or even days in just a few minutes.
However, although the automatically generated configuration is functionally complete, it is often not precise enough. Particularly when APIs return complex data structures, if the configuration is not manually tuned, it may lead to large language models (LLMs) not accurately understanding the data, thus affecting user experience.
4.1 Why Tune MCP Configurations?
Automatically generated MCP configurations usually include all fields returned by APIs and present them in a flat manner. This may be sufficient for simple APIs, but for complex APIs that return a large amount of nested data, it brings several issues:
Information Overload: LLM's context window is limited, and excessive irrelevant information dilutes important content.
Lack of Structure: Complex nested relationships are easily lost in flat descriptions.
Lack of Semantics: Technical codes and specialized terms remain unconverted, making it difficult for LLM to understand correctly.
Hallucination Risk: Faced with unfamiliar data structures, LLM might make incorrect inferences.
By manually tuning MCP configurations, we can significantly enhance LLM's understanding of the data returned by APIs, reducing misinterpretations and hallucinations, thereby providing users with more accurate and valuable responses.
4.2 Tuning Case Study: E-commerce Product Search API
Let’s illustrate the importance of MCP configuration tuning through a specific case. Suppose we have a product search API from an e-commerce platform, which returns complex product information laden with technical details.
4.2.1 Automatically Generated Basic Configuration
The configuration automatically generated using the OpenAPI to MCP tool might look like this:
When LLM receives API responses under this configuration, it will face the following challenges:
Data Structure Confusion: Unable to clearly understand the internal structure of nested objects (e.g., metadata, attributes).
Ambiguous Field Meaning: Uncertain about the possible values and meanings of the "availability" field.
Unclear Information Priority: Difficult to determine which information is most important to users.
Context Window Occupation: Large amounts of raw JSON occupy LLM's context window, crowding out other important information.
These problems might lead LLM to misinterpret various aspects:
Confusing product main body with variant information: “This watch comes in black, silver, and rose gold at prices of 899 yuan, 899 yuan, and 949 yuan respectively.” (Mistaking variant information as main information)
Incorrectly linking technical details: “The warranty period for this TechFit Pro smart watch is TF-SW-P10.” (Confusing SKU with the warranty period)
Generating hallucinations based on incomplete information: “This watch is available in all electronic shops.” (Incorrect inference based on shipping.locations)
4.2.2 Manually Tuned Configuration
Higress supports fine-tuning request and response templates by combining go template and gjson expressions (for detailed capabilities, please refer to the documentation: https://higress.cn/en/ai/mcp-server), through careful tuning, we can optimize the configuration as follows:
Here is a real response example for a smart watch product showcasing how the tuned template handles raw data:
With this structured response format, LLM can clearly identify each product's key information without being overwhelmed by excessive technical details and raw JSON structures.
4.3 How Tuning Improves LLM Understanding
Tuned configurations can significantly enhance LLM's data understanding:
4.3.1 Understanding Issues Before Tuning
Structural Confusion: Unable to distinguish main products from variants, potentially mislabeling variant attributes as main features.
Incorrect Focus: May overemphasize details (like SKU, barcode) rather than product features that interest users.
Misinterpreting Field Meaning: Cannot accurately grasp specialized terminology and encoded values.
Generating Hallucinations: Influenced by irrelevant content in, for example, product details, leading to hallucinations.
4.3.2 Improved Understanding After Tuning
Clear Structure: Accurately understands each product's basic information, price, brand, stock status, and rating.
Highlighted Key Information: Can identify key information such as price discounts and product descriptions and features.
Clear Semantics: Correctly interprets the meaning of stock status without ambiguity.
Complete Context: Grasp the full picture of search results (“Found 128 matching items, showing 10”).
4.4 Summary of Tuning Strategies
Based on the above case, we can extract the following MCP configuration tuning strategies:
Identify and extract core fields: Analyze the information users truly need, removing technical details and internal data.
Transform specialized terminology: Convert technical codes and specialized terms into descriptions that are easier for LLMs to comprehend.
Add contextual information: Help LLM understand the integrity and scope of the data.
Structure key information: Use hierarchies to make the importance and relationships of the information clear.
05 Conclusion
The OpenAPI to MCP tool provides us with the ability to quickly convert APIs into AI tools, while manual tuning is a crucial step in enhancing AI understanding and user experience. Through carefully designed response templates, we can guide LLM to more accurately understand the data returned by APIs, reducing misinterpretation and hallucinations, thereby offering users more valuable services.
In practical applications, it is recommended to first use the OpenAPI to MCP tool to generate the basic configuration and then tune it based on the complexity of the API and user needs. For simple APIs, the automatically generated configuration may already be sufficient; however, for complex APIs, particularly those that return large amounts of nested data, manual tuning will significantly enhance the experience.
It should be emphasized that high-quality MCP configuration tuning often relies on data feedback and iterative optimization. A single configuration is unlikely to meet all user scenarios at once, thus requiring a gray testing approach based on multiple configuration versions to create a feedback loop for evaluation and continuous improvement. Higress will combine with the powerful capabilities of the Nacos configuration center to provide more refined configuration management features for MCP server maintainers, including version control, gray publishing, configuration rollback, and effect analysis, making configuration tuning a continuous optimization process driven by data rather than a one-off task.
Through a complete chain of "automatic conversion + manual tuning + data feedback," we can enjoy the efficiency gains brought by automation while ensuring that AI assistants deliver a high-quality user experience, concurrently optimizing configurations based on actual usage data, so that the capabilities of AI assistants continually evolve with use.
Preview: Higress will launch the first MCP Marketplace based on API gateway in the country, including 50 meticulously tuned MCP services.
[1] https://github.com/higress-group/openapi-to-mcpserver
[2] https://mp.weixin.qq.com/s/bgDd82lj0jBUWifLMNByjw
[3] https://higress.cn/en/ai/mcp-quick-start/#configuring-rest-api-mcp-server