How to Turn Any API Into an MCP Server Posted in Design J Simpson May 27, 2025 Model Context Protocol (MCP) has generated a lot of buzz since Anthropic first released it in November 2024. Intended as a way to extend the functionality of AI tools like large language models (LLMs), MCP is an open-source protocol that allows AI agents to connect with external resources and data. If AI were a smartphone, MCP servers would be the apps. MCP can be broken down into two main components: the host application and an MCP server. A host application could be a local AI tool, like Cursor or Claude Desktop, for example. MCP servers are external resources that perform a specific function. Best of all, once an MCP server exists, any number of external tools or AI agents can connect to it. With MCP becoming so popular so quickly, there’s been a rush of new tools for creating your own MCP server. Many of these tools offer readymade solutions for transforming APIs into MCP servers, like MCP Link from Automation AI Lab, but they do most of the work for you, limiting the usefulness in creating your own MCP servers. For this tutorial, we’re going to show you how to create an MCP server from an OpenAPI specification and then integrate it into an LLM. We’ll be using Cursor and APIDog, but you can use any AI tool that allows you to customize its servers. How to Transform an API Into an MCP Server Let’s start by preparing for our project. To start, download APIDog, a tool for managing and testing APIs. We’ll be using it to create an API key and token. You’ll also want to download Cursor, an AI-enabled IDE, which we’ll be using to create our MCP server. Create an API Access Token with APIDog To start, create a new folder for your project. We’ll call ours mcp-server, but you can pick any name you like. Navigate into the new directory. Once inside the directory, create a virtual environment, as it will help ensure that all your libraries and dependencies are up to date. Start by creating the virtual environment by running the following code: python -m venv myenv Then activate the script by running the following code in a command prompt, if you’re on Windows, or Terminal if you’re using Mac OSX: myenv\Scripts\activate Next, we’re going to create an API for our project using APIDog. The first step in APIDog is to create a new API access token. To create an API access token, hover over your profile picture in the top-right corner and then select Account Settings from the dropdown menu. Then select the New Access Token option. You’ll be given a prompt to name your access token, which you can name whatever you like. You can also specify how long the access token remains active. After generating your access token, write down the secret key, as you’ll need it to configure your MCP server. Make sure to keep a copy of the secret key somewhere secure, as you won’t be able to see it again once it’s hidden. On the APIDog home menu, find the +New Project button in the top-right corner. Give your project a name and click Create New Project. We’ve called ours mcp-server, but you can choose whatever name you like. After creating your project, write down the Project ID, which you’ll need to configure your MCP server. Configure MCP Server in Cursor Now, we’re going to switch over to Cursor to create your MCP server. Start by opening your development folder using the Open Folder option from the File menu. This isn’t absolutely necessary, as you can also create a Global MCP server. Still, it’s a good idea, as it will give you some practice in implementing different MCP servers for specific projects. Once your development folder is open, select the Settings option from the top-right corner. In the Settings menu, select the MCP option. In the new MCP Servers window, select the + Add new global MCP server button. You’ll be given access to MCP.json, which you can configure to set up your MCP server. In MCP.json, input the following code: { "mcpServers": { "API specification": { "command": "npx", "args": [ "-y", "apidog-mcp-server@latest", "--project=<project-id>" ], "env": { "APIDOG_ACCESS_TOKEN": "<access-token>" } } } } Now, replace <project-id> and <access-token> with your project number and secret key you wrote down earlier. Once you’ve replaced the values, select Save from the File dropdown menu. Interact With Your API Specification Your MCP server should now be working properly. This allows you to interact with your API specification using Cursor’s built-in LLM. To see this in action, you’ll need an API specification to explore. For the sake of this tutorial, we’ll use the simple Petstore YAML file, but feel free to try it out with your own API specification to give you an idea how an MCP server might work with your own APIs. In Cursor, open the AI chat if it’s collapsed by selecting one of the Toggle AI Panel icons from the top-right corner. Once the chat window is open, you can engage with the AI about your API specification using natural language. To try it out, you can use a prompt like “Please fetch API specification via MCP and tell me how many endpoints exist in the project.” Cursor’s AI should respond with information about all of the endpoints mentioned in the API specification, including information about each endpoint’s HTTP method. If you want to try out your API endpoints as MCP tools in your browser, start by setting the APIDOG_ACCESS_TOKEN as your environment variable using the following command: set APIDOG_ACCESS_TOKEN=<ACCESS-TOKEN> Then start the server with the following command: npx -y apidog-mcp-server@latest --project=<project-id> --agent The –agent flag starts Cursor in Agent mode, which allows it to execute coding tasks and make changes directly to the code. If you’re using the Petstore YAML, you should see MCP tools for listPets, a tool created from the GET /pets endpoint, createPet, a tool from the POST /pets endpoint, and getPetbyID, a tool created from the GET /pets/{petId} endpoint. You can also check the tools by installing the MCP SDK for your programming language of choice (there are SDKs available for Java, TypeScript, Kotlin, Python, and C#), and input code like the following into your testing environment: const { McpClient } = require('@modelcontextprotocol/sdk/client/mcp.js'); const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js'); async function main() { const transport = new StdioClientTransport(/* options if needed */); const client = new McpClient(transport); // Connect to the MCP server await client.connect(); // Call a tool (endpoint), e.g., listPets const result = await client.callTool('listPets', { limit: 10 }); console.log(result); // Disconnect when done await client.close(); } main(); Final Thoughts on Turning an API Into an MCP Server Software is designed to help make us more productive, eliminating redundancy and busy work so we can focus on more meaningful activities. APIs were already a huge stride forward in transforming menial tasks into reusable products and services. However, these gains are quickly lost when you must recreate each tool every time a new technology becomes available. This makes the ability to automatically transform any API specification into operational MCP servers a major blessing for anyone looking to make the most of their APIs without having to create the same tool over and over again. Also, when using MCP, there are best practices to consider. Risks around MCP environments have emerged lately — namely, tool poisoning, remote command execution, and token leakage. So remember, when exposing MCP servers to keep tokens secure, use proper authentication and authorization, and review what tools your host can call. The latest API insights straight to your inbox