Skip to main content

Your REST API as MCP tools: openapi-to-mcp on a Route, step by step

An OpenAPI document as MCP tools on one Route with openapi-to-mcp: five fields, the tool list a client sees, one call and its record, and the mcp-bridge form.

By Akif F. Güven AI Gateway

What you will have at the end

A Route, orders-mcp, that an MCP client connects to and finds four tools, one per operation of the orders API’s OpenAPI document, without a line of code written for them. The client authenticates with a key-auth credential like any other caller, each tool call is a request record with the Consumer’s name and the key masked, and the Route’s rate limit counts the calls. This is the form-first counterpart of OpenAPI to MCP, which explains what an agent does with the tools; Securing MCP tools covers the limits and the roles.

Prerequisites

  • An API with an OpenAPI document the gateway can fetch. The lab’s orders service serves its own at /openapi-v2.json, with four operations: list, read, create and cancel an order.
  • A Route for the MCP endpoint. orders-mcp serves /mcp/orders with key-auth and limit-count; the Consumer orders_assistant holds the key.
  • Traffic logging turned on under Traffic Explorer › Settings, and a role that may manage Routes. The screenshots below were taken as nora.becker.

Five fields

Open the Route, Plugins, Add plugin, openapi-to-mcp. Under Basics, OpenAPI document URL is where the document is read from, and Service base URL is where the described operations are called. Under Behavior, Transport is how the client and the endpoint exchange messages, sse by default or streamable_http, the one current clients use; Headers are sent with every call to the service, for an API that wants a key of its own; Flatten parameters puts query and path parameters at the top of each tool’s input instead of nesting them by kind, which is how agents expect them.

The openapi-to-mcp form on orders-mcp: OpenAPI document URL http://orders-svc:8080/openapi-v2.json, Service base URL http://orders-svc:8080, Transport streamable_http, Headers empty and Flatten parameters on The document and the service. Everything the tools know comes from the document.

Select Add plugin. The Plugins tab draws the request path: key-auth first, then limit-count, then the Plugin, and no Upstream, because the Plugin answers the MCP protocol itself and calls the service on the agent’s behalf.

The Plugins tab of orders-mcp: the Request path rail with /mcp/orders for DELETE, GET and POST, the two global rules, key-auth at 2500, limit-count and openapi-to-mcp, and Upstream None The same rail as any Route. Authentication and the limit run before the protocol.

What an MCP client sees

With the streamable HTTP transport the client sends JSON-RPC over POST. Without the key, nothing:

### initialize without a key
HTTP 401

With the key, the three calls every client makes:

### initialize
{"id":1,"result":{"capabilities":{"tools":{}},"protocolVersion":"2025-03-26","serverInfo":{"name":"openapi2mcp","version":"0.0.1"}},"jsonrpc":"2.0"}
### tools/list
  - listOrders   · Lists orders, newest first. Filter by status.       · input: status
  - createOrder  · Creates an order for a customer with one or more lines. · input: requestBody
  - getOrder     · Reads one order by its id.                          · input: orderId
  - cancelOrder  · Cancels an open order. Shipped orders cannot be cancelled. · input: orderId
### tools/call getOrder {"orderId":"ord-10421"}
{"id":3,"jsonrpc":"2.0","result":{"content":[{"type":"text","text":"{ \"data\": { \"status\": \"open\", \"customer\": \"cust-8831\", \"currency\": \"EUR\", \"total\": 249.9, \"id\": \"ord-10421\" … }, \"status\": 200 … }"}]}}

The tool names are the document’s operation ids, the descriptions the operations’ description fields, not their shorter summaries, the inputs its parameters, flattened: orderId sits at the top of getOrder’s input, and the one operation with a body, createOrder, takes it under requestBody. A tool call’s result is the service’s answer, status and body, as text for the agent to read.

What Traffic Explorer shows

Each JSON-RPC call is a request record on the Route, with the Consumer’s name beside it, because key-auth identified the caller; the one without a key is a 401. The Upstream node reads gateway for all of them: the Plugin answered the protocol, and its own call to the service is not a request on this Route.

Traffic Explorer filtered to the path /mcp/orders: three 200 POST records for orders-mcp · orders_assistant answered by gateway in 44 to 65 ms, a 401 without a Consumer, and earlier records including a 429 Initialize, list, call: three records, one Consumer. The 429 further down is the Route’s limit from an earlier run.

The record of the tool call holds the JSON-RPC body, the tool and its arguments, and the headers with the key masked before it was stored:

The Request tab of the tools/call record: eleven headers with apikey as asterisks, x-consumer-username orders_assistant, and the body with method tools/call, name getOrder and arguments orderId ord-10421 Which tool, which argument, which Consumer. The key is the one value that is not there.

mcp-bridge, for an MCP server you already have

For a server that speaks MCP over standard input and output, a filesystem server or one your team wrote, the Plugin mcp-bridge runs it on the gateway host and serves it on the Route. Command is the program started for each session, npx for example; Arguments is a JSON list, each item one argument; Base URI is the path prefix the Plugin answers, serving /sse and /message under it and 404 elsewhere on the Route. The note under Command is the operational fact to weigh first: every session starts its own process on the gateway host, and the process keeps running after the client leaves.

The mcp-bridge form: Command empty with the note that every session starts its own process on the gateway host, Arguments as a JSON list with the example of a filesystem server, and Base URI A process per session on the gateway host. The form was opened and not saved: the lab has no such server to run.

What the audit log keeps

Every change to the Route is a record with the Plugin blocks in the diff: the document URL, the service URL, the transport, the limit. No value in this article’s openapi-to-mcp block is a secret; whether a Headers entry carrying a key for the service is masked was not checked here.

The Change section of an audit record of the orders-mcp Route update: the before and after sides with the openapi-to-mcp block, its openapi_url, base_url, transport and flatten_parameters, the limit-count block and the key-auth block The tools’ source, in the log. A new document URL is a new record, and a new tool list.

What to do next

Written by
Akif F. Güven
Engineer, G8
Was this helpful?
Next step

See G8 in a demo

We’ll show you the console with APIs and AI traffic like yours, and answer the questions these articles leave open.

  1. 01Demo
  2. 02Proof of conceptOn Docker for a quick start, or on the infrastructure you plan to run G8 on.
  3. 03LicenseWe prepare a quote for your edition and nodes, and you receive a signed license file.