OpenAPI & MCP: The Yin-Yang of Modern Intelligent Applications

MCP, or Model Context Protocol, is a hot topic in the developers' community. If you haven't heard of it, you can check out the MCP specification or search for "MCP" on YouTube; you'll find many videos about it!

Many developers, at least at first glance, think that MCP is overrated and just another way to refer to APIs. That’s partially correct, but it is much more than that. It standardizes how LLMs communicate with applications; it is the "Natural Language" of models and makes them more accessible to developers.

That's precisely why I want to discuss it. MCP is a protocol that allows developers to integrate AI models into their applications in a standardized way, making it easier to build and maintain AI-powered applications. It provides a common language for models to communicate with applications, enabling developers to focus on building features instead of worrying about the underlying model implementation.

Swagger, or OpenAPI Specifications, is familiar to most people. The OpenAPI and MCP specifications are two sides of the same coin. Both define how APIs should be designed and documented, but serve different purposes. OpenAPI focuses on RESTful APIs, while MCP centers around LLMs integration.

I have implemented a holistic solution called hapi (headless API) to facilitate the implementation of both OpenAPI and MCP specifications. Let me show you how to use it with a practical example.

My VM instances run on Contabo (affiliate link), a VPS provider. Using the hapi CLI tool, I will demonstrate how to integrate MCP without writing a single line of code.

First, download or save your OpenAPI specification file. In this example, it's contabo.json, which describes the API of the Contabo VPS provider. You can find it in the Contabo API documentation.

The file must be saved in the $APICOVE_HOME/specs, which by default is the user's home directory: ~/.apicove/specs/contabo.json, or in your current working directory (where you run the hapi command). With the list argument, the tool shows the available specifications using the hapi CLI tool:

$ hapi list
List of APIs
- petstore
- contabo
- oci-registry
- agentico
- petstore-oasv2

In a Greenfield project, you can create a new project using the hapi init command:

$ hapi init contabo

This command will use the Swagger specification file contabo.json (or contabo.yaml) to generate the controller’s scaffolding and save the file in the $APICOVE_HOME/src/contabo directory.

There are two ways to run the hapi command: using the "headless mode" or the "MCP mode."

In the "MCP mode", you can run the command as follows:

$ hapi run contabo --mcp

This command prints some API stats, like the number of endpoints and models. Then, it starts a web server with the entire MCP implementation, including the OpenAPI specification, the MCP specification, and the controllers scaffolding. If you test the endpoints using a tool like Postman or the built-in Swagger UI, you will see that the endpoints are already implemented and ready to use, without any business logic yet. You can then implement the business logic in the controllers located in the $APICOVE_HOME/src/contabo directory.

The "headless mode" is intended for brownfield projects, where you already have an existing backend application and want to integrate the MCP part. The "head" part is the current backend application, and the server defined in the OpenAPI specification consumes its business logic.

In this mode, you can run the command as follows:

$ hapi run contabo --headless

This command will start a web server with the MCP implementation but will not use the controller scaffolding. Instead, it will consume the business logic using the existing backend application at https://api.contabo.com/.

In the demo video, you can see how I use the hapi CLI tool to run the MCP implementation in both modes and test the endpoints using Postman and Swagger UI. I retrieve the list of VPS instances via MCP and finally show the actual Contabo Admin Panel, where I list the same VPS instances, to prove that the MCP implementation is working correctly.

Would you like to see more examples of how to use hapi MCP? Or do you have any questions about the implementation? Let me know in the comments below!

Connect with me on Twitter or LinkedIn to stay updated on the latest developments by "La Rebelion".

Want to download the hapi CLI tool? Comment on LinkedIn or Twitter, and I will send you the link to download it.

Be “HAPI” and Go Rebels! ✊🏽

0
Subscribe to my newsletter

Read articles from La Rebelion Labs directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

La Rebelion Labs
La Rebelion Labs

I was thinking about it, I feel that the concept of entrepreneurship is quite similar to the idea of being a Rebel. As a 'rebel,' I am passionate about experimenting and creating novel solutions to large problems.