Turn Your Internal REST APIs into MCP: With FastMCP's OpenAPI Integration, AI Can Use Them Without Writing a Single Tool
How to turn an existing internal REST API into an MCP server with FastMCP's OpenAPI integration, without writing any tool implementation code, and query it from Claude Code. Also covers how to show the AI only the endpoints it should see.
Hello! This is the Qualiteg product development team.

- Developer"We have dozens of internal APIs. Do I rewrite each one as an MCP tool?"
- Senior"No rewriting. Can that API output an OpenAPI schema?"
- Developer"Yes, at /openapi.json. So we feed that to FastMCP."
- Senior"Right. It generates the tools from the schema. Zero lines of tool code."
You want AI to be able to use the REST APIs your company already has. An API that returns sales, an API that returns customer records. Every company has APIs built up over years of work.
Building an MCP server makes them usable from AI. That much is clear. But there are dozens of endpoints. The thought of rewriting each one as an MCP tool is where people stop.
The short answer: no rewriting is needed. In this article we
use FastMCP's OpenAPI integration to turn an existing REST API into an MCP server with no tool implementation code, and then query it in natural language from Claude Code
with working code all the way through. The script that does the conversion is 38 lines for the whole file, comments included, and zero of those lines implement a tool. Ask "Which GPU sold the most in 2025? Show me the top 3 by sales amount" (we asked in Japanese in our demo) and the AI calls the API on its own and returns the aggregated answer.
We added the code to the sample repository used in this blog's MCP series.
qualiteg/mcp-server-tutorial | Sample code and README (GitHub)

Write by hand, or convert
In How to Build an MCP Server (Part 1) of this blog's series, we defined tools one at a time with FastMCP and built an MCP server connected directly to a SQLite sales database. The OpenAPI integration in this article is the opposite approach.
| Part 1 (handwritten) | This article (OpenAPI integration) | |
|---|---|---|
| Defining tools | Write each one as a Python function | Generated from the OpenAPI schema |
| Path to the data | Directly to the database | Calls the existing API over HTTP |
| Where it fits | When you want tools designed for AI | When the existing API is already rich |
| Authentication and permissions | Design and implement them yourself | Uses the existing API's authentication and permissions (you still configure credentials on the HTTP client) |
An existing API already contains business logic, validation, and permission checks. Bypassing all of that to connect straight to the database again would be a waste. If the API is already an asset, conversion is the quick way in.
Step 1: Prepare a stand-in for "the existing internal API"
Your company has real internal APIs, but so that this article works on a single machine, we use a sales API written in FastAPI as the sample. The data is the fictional PC parts shop sales database familiar from the series (500 customers, 72 products, 4,000 sales records. The seed is fixed, so you get the same numbers on your machine).
To run it locally, clone the repository, install the dependencies, and prepare the database (the database file is not in the repository. db_setup.py generates it).
git clone https://github.com/qualiteg/mcp-server-tutorial.git
cd mcp-server-tutorial
python -m pip install -r requirements.txt
python db_setup.pyOur test environment is Windows 11, Python 3.13, FastMCP 4.2.6, and FastAPI 0.165.1.
sales_api.py (full code of the stand-in internal API (GitHub), excerpt)
Category = Literal[
"CPU", "GPU", "Memory", "SSD", "HDD", "Motherboard", "PowerSupply", "PCCase"
]
@app.get(
"/api/sales/ranking",
operation_id="get_sales_ranking",
summary="商品別の売上ランキングを取得",
description=(
"商品ごとの売上金額ランキングを返します。年やカテゴリで絞り込めます。"
"カテゴリの日本語対応: Memory=メモリ、Motherboard=マザーボード、"
"PowerSupply=電源ユニット、PCCase=PCケース。"
),
)
def get_sales_ranking(
year: int | None = None, category: Category | None = None, limit: int = 10
):
...The sample's summary and description strings are written in Japanese. This summary means "Get the sales ranking by product." The description says the ranking can be filtered by year or category, and lists the Japanese word for each category value (Memory, Motherboard, PowerSupply, PCCase).
There are six endpoints. Four are GET: sales summary, sales ranking, product list, and customer lookup. As an internal API would, it also has customer creation (POST) and deletion (DELETE). Writing the category as a Literal type is setup for later. It puts the allowed values into the OpenAPI schema as an enum, and that pays off once the schema reaches the AI.
Start it.
python sales_api.py
Step 2: Check the OpenAPI schema
FastAPI generates the OpenAPI schema from the endpoint definitions. With the API running, open http://127.0.0.1:9905/openapi.json and you get the definitions of all six endpoints as JSON. An excerpt looks like this.
{
"operationId": "get_sales_ranking",
"summary": "商品別の売上ランキングを取得",
"description": "商品ごとの売上金額ランキングを返します。年やカテゴリで絞り込めます。...",
"parameters": [
...
{
"name": "category",
"in": "query",
"required": false,
"schema": {
"anyOf": [
{
"enum": ["CPU", "GPU", "Memory", "SSD", "HDD", "Motherboard", "PowerSupply", "PCCase"],
"type": "string"
},
{ "type": "null" }
],
"title": "Category"
}
},
...
]
}The allowed category values we wrote as a Literal type in Step 1 are there as an enum.
This schema is the input to the conversion. An API built with something other than FastAPI stands on the same ground as long as it can output an OpenAPI schema (a Swagger definition). Spring Boot has springdoc's /v3/api-docs, Express has swagger-jsdoc, and the major frameworks all have a way to emit the schema. Check first whether the APIs running in your company have one.
Step 3: Make it an MCP server in 38 lines
This is the main part. You pass the schema and an HTTP client to FastMCP's from_openapi(). That is all.
mcp_sales_api.py (full code of the conversion (GitHub), leading comment omitted. The comments in the repository are in Japanese and are translated here)
import httpx2
from fastmcp import FastMCP
from fastmcp.server.providers.openapi import MCPType, RouteMap
API_BASE = "http://127.0.0.1:9905"
# Fetch the OpenAPI schema from the existing API
openapi_spec = httpx2.get(f"{API_BASE}/openapi.json").json()
# The client that sends the actual HTTP request when an MCP tool is called
client = httpx2.AsyncClient(base_url=API_BASE)
mcp = FastMCP.from_openapi(
openapi_spec=openapi_spec,
client=client,
name="sales-api",
route_maps=[
# Show only the GET endpoints to the AI as tools
RouteMap(methods=["GET"], mcp_type=MCPType.TOOL),
# Everything else (POST / DELETE and so on) is not exposed as an MCP tool
RouteMap(mcp_type=MCPType.EXCLUDE),
],
)
if __name__ == "__main__":
mcp.run()That is everything. We did not write a single tool implementation function.
Here is how it works. When the AI calls a tool, FastMCP builds the matching HTTP request, sends it to the existing API, and returns the response to the AI. Tool names come basically from the OpenAPI operationId, tool descriptions from summary and description, and argument definitions from the parameter definitions. All of it is generated.
If the target API needs authentication, set the credentials, such as an Authorization header, on this httpx2.AsyncClient. This means you can use the existing API's authentication and permission mechanisms as they are. It does not mean FastMCP logs in for you. Also keep in mind when designing: if the MCP server calls the API with one service account, the permissions of each AI user are not carried over automatically.
If fetching the OpenAPI schema also needs authentication, pass the same credentials to the httpx2.get() that fetches the schema.
We tested with FastMCP 4.2.6. For the HTTP client, use httpx2, which is installed together with FastMCP (passing the older httpx.AsyncClient produces a deprecation warning).
Step 4: Ask from Claude Code
Registering with Claude Code is the same single line as in Part 1. Leave the existing API (sales_api.py) running, open another terminal, and run it there.
claude mcp add sales-api -- python /path/to/mcp-server-tutorial/mcp_sales_api.py
claude mcp listpython is the Python you installed the dependencies into in Step 1. On Windows, write the script path like C:\path\to\mcp-server-tutorial\mcp_sales_api.py.
When claude mcp list shows sales-api: ... ✔ Connected, you are ready. Claude Code starts the MCP server (mcp_sales_api.py), so you do not need to start it yourself.
Pass a question to claude -p and ask.
claude -p "2025年でいちばん売れたGPUはどれ?売上金額トップ3を教えて"The question is in Japanese: "Which GPU sold the most in 2025? Show me the top 3 by sales amount."

The AI chose the get_sales_ranking tool on its own, called it, and returned the 2025 top 3 GPUs by sales amount. The numbers in the table match the result of calling the API directly with curl. The AI even added a thoughtful note: GeForce RTX Pro164 sold one more unit, but Arc 9204 is at the top by sales amount.
This is the command we used for the comparison (in PowerShell, write curl.exe).
curl "http://127.0.0.1:9905/api/sales/ranking?year=2025&category=GPU&limit=3"We did not write one line of tool implementation, and the experience is the same as when we wrote the tools by hand in Part 1.
Show only the endpoints that are safe to show

- Developer"Converted! All six internal API endpoints are now AI tools."
- Senior"All of them? The AI can now call the DELETE that removes customers."
- Developer"I used RouteMap to expose only GET as tools and exclude the rest."
- Senior"Good. Excluded endpoints never appear in the MCP tool list."
In the Step 3 code, the most important part is actually the two lines of route_maps.
This API also has customer creation (POST) and deletion (DELETE). If you specify nothing, FastMCP converts every endpoint into a tool. In other words, you end up with an MCP server where the AI can call even the DELETE endpoint. In this sample, for safety, both creation (POST) and deletion (DELETE) only return 501 (Not Implemented). But if these are implemented in a production API, they become callable through MCP. When you connect an internal API to AI, this is how accidents happen.
That is where RouteMap comes in. Here we set "make only GET into tools, exclude the rest." An excluded endpoint is not rejected when called. It never appears in the tool list this MCP server shows the AI.
Let's actually ask for a deletion.

The AI checked the list of tools it can use (the four read-only ones) and answered that it cannot delete. We are not asking it "please don't delete" and hoping it complies. Through this MCP server, we simply do not hand it the tool for deleting. It is the same idea as opening SQLite in read-only mode in Part 1.
Besides the method, RouteMap can also filter by a regular expression on the path or by OpenAPI tags. For example, you can exclude only what is under /admin/, or make tools only from endpoints tagged analytics. Rules are evaluated from the top and the first match wins, so the order matters (in this code, "GET becomes a tool" comes first and "exclude the rest" comes after).
Note that RouteMap controls what is exposed as MCP. In production, do not make it your only authorization boundary. Use the existing API's authentication and authorization together with it.
The key to automatic conversion is the quality of the original API documentation
The steps so far give you something that works. Here are two points that matter when you do this for real.
The first is that the quality of the tools is decided by the quality of the original OpenAPI schema. As we saw in Step 2, tool descriptions are generated from each endpoint's summary and description. This description is what the AI uses to decide which tool to use and when. If the existing API's documentation is just "Get data," the AI is handed a tool without knowing what the data is. In this sample, we made the category a Literal type so that the allowed values (CPU / GPU / Memory...) are in the OpenAPI schema itself, and we wrote the Japanese word for each value in the description. With this in place, the AI can read the allowed category values and how they map to Japanese from the tool definition. When we actually asked in Japanese "Which memory sold the most in 2025?", the AI specified category="Memory" and filtered correctly.
The second is that automatic conversion suits APIs that are fine to show as they are. FastMCP's official documentation itself says that a server with tools designed for AI performs better than an OpenAPI-converted server. When endpoints are so fine-grained that the AI has to call them again and again, or responses are so large that they crowd the context, the practical answer is to handwrite thin tools, the Part 1 way, for only the frequent operations and lay them on top. We recommend this order: get it working by conversion first, watch how the AI uses it, and then replace only the key parts with handwritten tools.
Call this MCP server safely from outside AI with WireCanal
The MCP server so far is set up to be used by MCP clients running on the same PC, such as Claude Code. That is because mcp.run() is for local use (stdio).
To ask the internal API from web-based Claude or ChatGPT as well, use our WireCanal.
WireCanal is a secure tunnel service. With one tunnel opened outbound from inside your network, it gives your internal MCP server a public HTTPS URL. You open no inbound ports and need no VPN.
It is our own service, and the setup in this section can be built on the free plan (0 yen), which needs no credit card.
WireCanal official site (wirecanal.com)

As Figure 2 shows, the Agent placed inside your network connects outbound to WireCanal. Calls from outside AI travel through that tunnel to the MCP server, and the MCP server calls the internal API.
Make the MCP server listen over HTTP
In mcp_sales_api.py, you change only the last line.
if __name__ == "__main__":
mcp.run(transport="http", host="127.0.0.1", port=9906)Leave the existing API (sales_api.py) running and start the MCP server in another terminal. This time you start it yourself instead of leaving it to Claude Code.
python mcp_sales_api.pyThe MCP endpoint is now http://127.0.0.1:9906/mcp. It still listens on 127.0.0.1, so at this point nothing outside can reach it.
On our machine, we connected to the MCP server in this HTTP mode and confirmed that listing the four read-only tools and calling get_sales_ranking both work.
Create a canal and connect with the Agent
In the WireCanal dashboard, create a canal (a public route) of type "MCP." Check the AI services you will use (Claude, ChatGPT), set the forward target to 127.0.0.1:9906, and a public URL of the form https://<name>.wirecanal.com is issued.
Next, in the connection file (wirecanal.json), write the tools you are willing to show to outside AI.
{
"access_key": "ck_(connection key issued per canal)",
"forward_target": "127.0.0.1:9906",
"mode": "mcp",
"tools": {
"default": "deny",
"allow": ["get_sales_summary", "get_sales_ranking", "list_products"]
},
"lang": "ja"
}The default is to deny every tool. Only the tools written in allow are visible to outside AI. In the example above, get_customer, which returns customer information, is not listed, so it does not appear in the tool list of the web-based AI.
Then start the Agent on the machine where the MCP server is running. How to install it is in the canal's setup tab and in the WireCanal setup guide (wirecanal.com).
Finally, take the public URL with /mcp appended and register it as a custom connector in Claude, or as an app created in ChatGPT's developer mode. Approve on WireCanal's authorization screen, select the registered connector or app in the conversation, and you can ask "Which GPU sold the most in 2025? Show me the top 3 by sales amount" from the AI in your browser.
The steps with screenshots are in Part 2 of the series. Replace the MCP server in Part 2 with this article's mcp_sales_api.py and the steps are the same.
Why it is safe to put it outside
You are putting a server that leads to an internal API outside, so it needs protection. WireCanal takes on that protection on the route side.
The entrance is protected by OAuth.
Unauthenticated access is stopped with a 401 before it reaches your server. Connections from Claude or ChatGPT get through only when approved on WireCanal's authorization screen.
Your side decides which tools outside AI can see.
The master copy of the allowlist is the wirecanal.json on your side. From the dashboard, all anyone can do is propose a change. Unless it is approved on your side, the published tools do not increase.
The forward target is fixed.
The Agent does not connect anywhere other than the configured forward target (127.0.0.1:9906 here). The tunnel does not become a path to other servers in your network.
You can limit users by company ID.
On the Lite plan and above, you can link with your company's identity provider, such as Google Workspace. Only organization accounts in the domains the administrator allowed can connect, and when the company suspends an account, for example when someone leaves, that person's connection also expires within one hour.
The relay infrastructure runs on servers in Japan. The access log for each canal lets you check afterward when and from where connections came.
RouteMap narrows "the tools the MCP server has," and WireCanal's allowlist narrows "the tools outside AI can see." You decide how much of the internal API is exposed in two layers.
WireCanal MCP and AI integration | Show the AI only the tools it should see (wirecanal.com)
Summary
Existing internal REST APIs can be turned into MCP without rewriting them. Pass the OpenAPI schema and an HTTP client to FastMCP's from_openapi() and they become usable from AI with zero lines of tool implementation. In this sample, a 38-line script was enough to make natural-language queries against the sales API work.
When you do, always narrow what is shown with RouteMap. By default every endpoint becomes a tool, so write and admin endpoints are handed to the AI as well. This sample allowed only GET, but GET is not automatically safe either. In production, use not only the method but also the path and OpenAPI tags, and make an allowlist of only the endpoints you need.
And for use from outside AI, there is WireCanal. Change the last line to HTTP mode, create one canal, and the same MCP server can be called safely from web-based Claude and ChatGPT too.
You can start with WireCanal for free.
Sign up for WireCanal for free (app.wirecanal.com)
See you next time!
Sources and references
- FastMCP official documentation | OpenAPI Integration (gofastmcp.com)
- FastAPI official documentation (fastapi.tiangolo.com)
- Model Context Protocol specification (modelcontextprotocol.io)
- qualiteg/mcp-server-tutorial | Sample code for this article (GitHub)
- WireCanal official site | Secure tunnel with MCP support (wirecanal.com)