# OpenAPI to MCP

The `openapi-to-mcp` plugin turns an API described by an OpenAPI document into an MCP (Model Context Protocol) server without requiring changes to the API. It derives tools from the API operations, handles tool discovery and invocation over Streamable HTTP or Server-Sent Events (SSE), and translates tool calls into upstream HTTP requests.

The plugin is available in APISIX and API7 Gateway, but the products process MCP traffic differently. APISIX runs the MCP implementation inside the gateway. API7 Gateway forwards MCP traffic to a separate OpenAPI-to-MCP service deployed alongside the gateway.

## MCP Request Flow[​](#mcp-request-flow "Direct link to MCP Request Flow")

* APISIX
* API7 Gateway

APISIX fetches the OpenAPI document, generates tools, and sends tool calls to the described API inside the gateway process.

API7 Gateway validates the plugin configuration and forwards MCP traffic to the OpenAPI-to-MCP service. The service fetches the document, generates tools, and calls the described API.

## Demo (API7 Dashboard)[​](#demo-api7-dashboard "Direct link to Demo (API7 Dashboard)")

The interactive demo follows the [Expose Petstore as MCP Tools](#expose-petstore-as-mcp-tools) workflow in the API7 Dashboard. It shows how to configure a service and route, connect an MCP client, and test the generated Petstore tools.

## Examples[​](#examples "Direct link to Examples")

The following examples configure `openapi-to-mcp` for common MCP workflows.

### Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Start Petstore before configuring the plugin. API7 Gateway also requires the separate OpenAPI-to-MCP service.

#### Start the Example Upstream[​](#start-the-example-upstream "Direct link to Start the Example Upstream")

The examples use Petstore as the upstream API. Petstore serves both the OpenAPI document and the API operations exposed as MCP tools. Its container image is available for `linux/amd64`, which the deployment examples select explicitly.

Select the tab for your deployment method:

* Docker
* Kubernetes

Set `GATEWAY_CONTAINER` to the running APISIX or API7 Gateway container. Create a network for the example and connect the gateway to it. Skip a command if the network or connection already exists.

```
export GATEWAY_CONTAINER=replace-with-gateway-container-name



docker network create gateway-petstore-net

docker network connect gateway-petstore-net "$GATEWAY_CONTAINER"
```

Create a Compose file for Petstore on the gateway's shared network:

docker-compose.petstore.yaml

```
services:

  petstore:

    image: swaggerapi/petstore3:1.0.27

    platform: linux/amd64

    networks:

      - gateway-petstore-net

    ports:

      - "18080:8080"



networks:

  gateway-petstore-net:

    external: true
```

Start Petstore:

```
docker compose -f docker-compose.petstore.yaml up -d
```

Once the container has started, confirm that the OpenAPI document is available:

```
curl -fsS "http://127.0.0.1:18080/api/v3/openapi.json" > /dev/null
```

Deploy Petstore in the same namespace as the gateway. The example uses the Ingress Controller namespace `aic`. Replace it with your gateway namespace when needed.

petstore.yaml

```
apiVersion: apps/v1

kind: Deployment

metadata:

  namespace: aic

  name: petstore

spec:

  replicas: 1

  selector:

    matchLabels:

      app: petstore

  template:

    metadata:

      labels:

        app: petstore

    spec:

      nodeSelector:

        kubernetes.io/arch: amd64

      containers:

        - name: petstore

          image: swaggerapi/petstore3:1.0.27

          ports:

            - containerPort: 8080

---

apiVersion: v1

kind: Service

metadata:

  namespace: aic

  name: petstore

spec:

  selector:

    app: petstore

  ports:

    - port: 8080

      targetPort: 8080
```

Apply the manifest:

```
kubectl apply -f petstore.yaml
```

Wait for Petstore to become ready:

```
kubectl rollout status -n aic deployment/petstore
```

#### Deploy the OpenAPI-to-MCP Service for API7 Gateway[​](#deploy-the-openapi-to-mcp-service-for-api7-gateway "Direct link to Deploy the OpenAPI-to-MCP Service for API7 Gateway")

This step applies only to API7 Gateway. APISIX processes MCP requests inside the gateway and does not require a separate service. API7 Gateway forwards MCP requests to the OpenAPI-to-MCP service, which must run in the same network namespace as the gateway.

* Kubernetes
* Docker Compose

Add the following block to the values file used to deploy API7 Gateway. Preserve the existing settings in that file.

dp-values.yaml

```
openapiToMcp:

  enabled: true
```

Apply the updated values. This example uses the release name and namespace from the API7 Gateway Kubernetes deployment guide:

```
helm upgrade api7-ee-3-gateway api7/gateway \

  --namespace api7 \

  --version "~3.10.0" \

  -f dp-values.yaml
```

For API7 Gateway 3.9, change the chart constraint to `--version "~3.9.0"`. Replace the release name, namespace, or values filename if your deployment uses different ones.

Add the OpenAPI-to-MCP service to the `docker-compose.yaml` generated by the API7 Dashboard. Keep the existing gateway service unchanged:

docker-compose.yaml

```
services:

  openapi-to-mcp:

    image: api7/openapi-to-mcp:1.0.9

    network_mode: "service:gateway"

    restart: always
```

The `network_mode` setting lets the plugin reach the service at `127.0.0.1:3000`. If the generated gateway service has another name, replace `gateway` with that name.

Start the services:

```
docker compose up -d
```

### Expose Petstore as MCP Tools[​](#expose-petstore-as-mcp-tools "Direct link to Expose Petstore as MCP Tools")

Configure a Streamable HTTP endpoint on your gateway. For Kubernetes, see [Configure with Ingress Controller](#configure-with-ingress-controller).

* APISIX
* API7 Gateway

Create a route with the `openapi-to-mcp` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "id": "openapi-to-mcp-route",

    "uri": "/mcp",

    "methods": ["POST"],

    "plugins": {

      "openapi-to-mcp": {

        "transport": "streamable_http",

        "base_url": "http://petstore:8080/api/v3",

        "openapi_url": "http://petstore:8080/api/v3/openapi.json"

      }

    }

  }'
```

Configure the service and route in the API7 Dashboard. The [interactive demo](#demo-api7-dashboard) shows the same workflow.

1. In the Dashboard sidebar, open your gateway group and select **Services** in 3.10 or **Published Services** in 3.9.

2. Click **Add Service**, then **Add Manually**.

3. Configure the service:

   | Field                    | Value                    |
   | ------------------------ | ------------------------ |
   | Name                     | `openapi-to-mcp-service` |
   | Upstream Scheme          | `HTTP`                   |
   | How to find the upstream | `Use Nodes`              |

4. Click **Add Node** and configure `petstore` on port `8080` with weight `100`.

5. Click **Add**, open the new service, and click **Add Route**.

6. Configure the route:

   | Field   | Value                  |
   | ------- | ---------------------- |
   | Name    | `openapi-to-mcp-route` |
   | Path    | `/mcp`                 |
   | Methods | `POST`                 |

7. Click **Add**, open the new route, then open **Plugins** and click **Enable Plugin**.

8. Search for `openapi-to-mcp` and configure it with the following values:

   | Field         | Value                                      |
   | ------------- | ------------------------------------------ |
   | `transport`   | `Streamable HTTP`                          |
   | `base_url`    | `http://petstore:8080/api/v3`              |
   | `openapi_url` | `http://petstore:8080/api/v3/openapi.json` |

9. Click **Submit** to enable the plugin.

#### Configure with Ingress Controller[​](#configure-with-ingress-controller "Direct link to Configure with Ingress Controller")

The manifests can be applied with Apache APISIX Ingress Controller or API7 Ingress Controller. Connect the controller to the gateway it manages. For API7 Gateway, [deploy the OpenAPI-to-MCP service](#deploy-the-openapi-to-mcp-service-for-api7-gateway) first because Ingress Controller configures the route but does not deploy that service.

If your installation uses a namespace, Gateway name, or IngressClass name other than those shown, update the manifests to match.

* Gateway API
* APISIX CRD

Create a route with the `openapi-to-mcp` plugin configured as follows:

openapi-to-mcp-ic.yaml

```
apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: openapi-to-mcp-plugin-config

spec:

  plugins:

    - name: openapi-to-mcp

      config:

        transport: streamable_http

        base_url: "http://petstore:8080/api/v3"

        openapi_url: "http://petstore:8080/api/v3/openapi.json"

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /mcp

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: openapi-to-mcp-plugin-config

      backendRefs:

        - name: petstore-external-domain

          port: 8080

---

apiVersion: v1

kind: Service

metadata:

  namespace: aic

  name: petstore-external-domain

spec:

  type: ExternalName

  externalName: petstore.aic.svc.cluster.local

  ports:

    - port: 8080

---

apiVersion: apisix.apache.org/v1alpha1

kind: BackendTrafficPolicy

metadata:

  namespace: aic

  name: petstore-external-domain

spec:

  targetRefs:

    - group: ""

      kind: Service

      name: petstore-external-domain

  passHost: node

  scheme: http
```

Apply the configuration to your cluster:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

Create a route with the `openapi-to-mcp` plugin configured as follows:

openapi-to-mcp-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  ingressClassName: apisix

  http:

    - name: openapi-to-mcp-route

      match:

        paths:

          - /mcp

        methods:

          - POST

      plugins:

        - name: openapi-to-mcp

          enable: true

          config:

            transport: streamable_http

            base_url: "http://petstore:8080/api/v3"

            openapi_url: "http://petstore:8080/api/v3/openapi.json"
```

Apply the configuration to your cluster:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

List the generated tools. Streamable HTTP clients must accept both JSON and event-stream responses:

```
curl -N "http://127.0.0.1:9080/mcp" \

  -H "Content-Type: application/json" \

  -H "Accept: application/json, text/event-stream" \

  -d '{

    "jsonrpc": "2.0",

    "id": 1,

    "method": "tools/list"

  }'
```

The response should contain a tools list that includes `getPetById`. Call that tool to confirm that the gateway can reach Petstore:

```
curl -N "http://127.0.0.1:9080/mcp" \

  -H "Content-Type: application/json" \

  -H "Accept: application/json, text/event-stream" \

  -d '{

    "jsonrpc": "2.0",

    "id": 2,

    "method": "tools/call",

    "params": {

      "name": "getPetById",

      "arguments": {

        "pathParameters": {

          "petId": 1

        }

      }

    }

  }'
```

The tool result should contain the Petstore resource with ID `1`.

Set your MCP client's server URL to the gateway address followed by `/mcp`. The following example uses the local gateway address.

mcp.json

```
{

  "mcpServers": {

    "petstore-mcp": {

      "url": "http://127.0.0.1:9080/mcp"

    }

  }

}
```

After the client connects, confirm that it lists `getPetById`, then ask it to retrieve pet `1`.

![AI client interaction with Petstore](https://static.api7.ai/uploads/2025/09/22/6TE6DgXy_oet.png)

### Connect over SSE[​](#connect-over-sse "Direct link to Connect over SSE")

Use SSE when your MCP client expects a long-lived event stream and a separate message endpoint. For multiple gateway instances, use session affinity so the stream and message requests reach the same instance. See [SSE Session Isolation](https://docs.api7.ai/hub/openapi-to-mcp-security-and-limits.md#isolate-sse-sessions).

Configure the Petstore route for SSE:

* APISIX
* API7 Gateway

Patch the existing route to accept the SSE stream and message requests:

```
curl "http://127.0.0.1:9180/apisix/admin/routes/openapi-to-mcp-route" -X PATCH \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "methods": ["GET", "POST"],

    "plugins": {

      "openapi-to-mcp": {

        "transport": "sse"

      }

    }

  }'
```

1. In the API7 Dashboard, open your gateway group's service list.
2. Open `openapi-to-mcp-service`, then open the `openapi-to-mcp-route` route.
3. Edit the route, enable both `GET` and `POST` methods, and save the route.
4. Open **Plugins** and click **Edit** for `openapi-to-mcp`, then set `transport` to `SSE`.
5. Click **Save** to update the plugin configuration.

#### Configure SSE with Ingress Controller[​](#configure-sse-with-ingress-controller "Direct link to Configure SSE with Ingress Controller")

Update the manifest from [Expose Petstore as MCP Tools](#expose-petstore-as-mcp-tools) and preserve its other resources:

* Gateway API
* APISIX CRD

openapi-to-mcp-ic.yaml (updated resources)

```
apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: openapi-to-mcp-plugin-config

spec:

  plugins:

    - name: openapi-to-mcp

      config:

        transport: sse

        base_url: "http://petstore:8080/api/v3"

        openapi_url: "http://petstore:8080/api/v3/openapi.json"

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /mcp

          method: GET

        - path:

            type: Exact

            value: /mcp

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: openapi-to-mcp-plugin-config

      backendRefs:

        - name: petstore-external-domain

          port: 8080
```

openapi-to-mcp-ic.yaml (updated ApisixRoute)

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  ingressClassName: apisix

  http:

    - name: openapi-to-mcp-route

      match:

        paths:

          - /mcp

        methods:

          - GET

          - POST

      plugins:

        - name: openapi-to-mcp

          enable: true

          config:

            transport: sse

            base_url: "http://petstore:8080/api/v3"

            openapi_url: "http://petstore:8080/api/v3/openapi.json"
```

Reapply the manifest:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

Open the stream and leave it running:

```
curl -N "http://127.0.0.1:9080/mcp"
```

The MCP server sends an `endpoint` event. Copy the path and query string from its `data` line, including the session ID. In a second terminal, append that path and query string to the same gateway address and send a discovery request:

```
export MCP_MESSAGE_PATH="<ENDPOINT_EVENT_DATA>"



curl -i "http://127.0.0.1:9080${MCP_MESSAGE_PATH}" \

  -H "Content-Type: application/json" \

  -d '{

    "jsonrpc": "2.0",

    "id": 1,

    "method": "tools/list"

  }'
```

The POST returns `202 Accepted`. Read the tool list in a `message` event on the original stream. For the rest of the Petstore examples, restore `transport: streamable_http` and the original route methods.

### Configure Authentication for MCP Routes[​](#configure-authentication-for-mcp-routes "Direct link to Configure Authentication for MCP Routes")

Protect the Petstore MCP route with `key-auth`. The client sends the gateway credential with every MCP request. Upstream API credentials remain in the `openapi-to-mcp` plugin's `headers` setting.

* APISIX
* API7 Gateway

Create a consumer `johndoe`:

```
curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "username": "johndoe"

  }'
```

Configure the `key-auth` credential for `johndoe`:

```
curl "http://127.0.0.1:9180/apisix/admin/consumers/johndoe/credentials" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "id": "cred-john-key-auth",

    "plugins": {

      "key-auth": {

        "key": "john-key"

      }

    }

  }'
```

Add `key-auth` to the existing MCP route:

```
curl "http://127.0.0.1:9180/apisix/admin/routes/openapi-to-mcp-route" -X PATCH \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "plugins": {

      "key-auth": {

        "header": "apikey"

      }

    }

  }'
```

1. In the API7 Dashboard sidebar, open your gateway group and select **Consumers**.
2. Click **Create Consumer**, set **Name** to `johndoe`, and click **Submit**.
3. Open the consumer's **Credentials** tab, click **Create Credential**, and select `key-auth`.
4. Set **Name** to `primary-key` and **Key** to `john-key`, then click **Submit**.
5. Return to the gateway group's service list, open `openapi-to-mcp-service`, and select the `openapi-to-mcp-route` route.
6. Open **Plugins**, click **Enable Plugin**, and select `key-auth`.
7. Set `header` to `apikey`, then click **Submit**.

#### Configure Authentication with Ingress Controller[​](#configure-authentication-with-ingress-controller "Direct link to Configure Authentication with Ingress Controller")

Select the Kubernetes API used by your Ingress Controller deployment:

* Gateway API
* APISIX CRD

openapi-to-mcp-ic.yaml

```
apiVersion: apisix.apache.org/v1alpha1

kind: Consumer

metadata:

  namespace: aic

  name: johndoe

spec:

  gatewayRef:

    name: apisix

  credentials:

    - type: key-auth

      name: primary-key

      config:

        key: john-key

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: openapi-to-mcp-plugin-config

spec:

  plugins:

    - name: key-auth

      config:

        header: apikey

    - name: openapi-to-mcp

      config:

        transport: streamable_http

        base_url: "http://petstore:8080/api/v3"

        openapi_url: "http://petstore:8080/api/v3/openapi.json"

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /mcp

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: openapi-to-mcp-plugin-config

      backendRefs:

        - name: petstore-external-domain

          port: 8080

---

apiVersion: v1

kind: Service

metadata:

  namespace: aic

  name: petstore-external-domain

spec:

  type: ExternalName

  externalName: petstore.aic.svc.cluster.local

  ports:

    - port: 8080

---

apiVersion: apisix.apache.org/v1alpha1

kind: BackendTrafficPolicy

metadata:

  namespace: aic

  name: petstore-external-domain

spec:

  targetRefs:

    - group: ""

      kind: Service

      name: petstore-external-domain

  passHost: node

  scheme: http
```

openapi-to-mcp-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixConsumer

metadata:

  namespace: aic

  name: johndoe

spec:

  ingressClassName: apisix

  authParameter:

    keyAuth:

      value:

        key: john-key

---

apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  ingressClassName: apisix

  http:

    - name: openapi-to-mcp-route

      match:

        paths:

          - /mcp

        methods:

          - POST

      plugins:

        - name: key-auth

          enable: true

          config:

            header: apikey

        - name: openapi-to-mcp

          enable: true

          config:

            transport: streamable_http

            base_url: "http://petstore:8080/api/v3"

            openapi_url: "http://petstore:8080/api/v3/openapi.json"
```

Apply the updated manifest:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

Configure the client to send the credential in a request header or, if headers are unsupported, in the MCP server URL query string.

#### If Headers Are Supported[​](#if-headers-are-supported "Direct link to If Headers Are Supported")

For a client that supports request headers, add the `apikey` header to the MCP server configuration:

mcp.json

```
{

  "mcpServers": {

    "petstore-mcp": {

      "url": "http://127.0.0.1:9080/mcp",

      "headers": {

        "apikey": "john-key"

      }

    }

  }

}
```

Connect to the MCP server and confirm that the client can list and call the Petstore tools. A missing or invalid key prevents the client from loading tools.

#### If Headers Are Not Supported[​](#if-headers-are-not-supported "Direct link to If Headers Are Not Supported")

For clients that cannot send headers, `key-auth` reads the `apikey` query parameter by default when the header is absent. Use this option only where URLs containing credentials are protected from logs and other records. The client must include the credential with every MCP request.

Set the MCP server URL to `http://127.0.0.1:9080/mcp?apikey=john-key` for the local example. Verify that the client can list and call the Petstore tools with the credential.

### Flatten Tool Schema Parameters[​](#flatten-tool-schema-parameters "Direct link to Flatten Tool Schema Parameters")

By default, tool arguments are grouped by where the API expects them. The [Petstore example](#expose-petstore-as-mcp-tools) sends `petId` inside `pathParameters`, for example. Set `flatten_parameters` to `true` to put those arguments directly in the tool input. Keep the default when parameters in different locations have the same name.

Enable parameter flattening on the Petstore route:

* APISIX
* API7 Gateway

Patch the existing route:

```
curl "http://127.0.0.1:9180/apisix/admin/routes/openapi-to-mcp-route" -X PATCH \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "plugins": {

      "openapi-to-mcp": {

        "flatten_parameters": true

      }

    }

  }'
```

1. In the API7 Dashboard, open your gateway group's service list.
2. Open `openapi-to-mcp-service`, select the `openapi-to-mcp-route` route, and open **Plugins**.
3. Click **Edit** for `openapi-to-mcp`, set `flatten_parameters` to `true`, and click **Save**.

#### Flatten Parameters with Ingress Controller[​](#flatten-parameters-with-ingress-controller "Direct link to Flatten Parameters with Ingress Controller")

Update the plugin configuration in `openapi-to-mcp-ic.yaml` and preserve the other resources:

* Gateway API
* APISIX CRD

openapi-to-mcp-ic.yaml (updated PluginConfig)

```
apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: openapi-to-mcp-plugin-config

spec:

  plugins:

    - name: key-auth

      config:

        header: apikey

    - name: openapi-to-mcp

      config:

        transport: streamable_http

        base_url: "http://petstore:8080/api/v3"

        openapi_url: "http://petstore:8080/api/v3/openapi.json"

        flatten_parameters: true
```

openapi-to-mcp-ic.yaml (updated ApisixRoute)

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  ingressClassName: apisix

  http:

    - name: openapi-to-mcp-route

      match:

        paths:

          - /mcp

        methods:

          - POST

      plugins:

        - name: key-auth

          enable: true

          config:

            header: apikey

        - name: openapi-to-mcp

          enable: true

          config:

            transport: streamable_http

            base_url: "http://petstore:8080/api/v3"

            openapi_url: "http://petstore:8080/api/v3/openapi.json"

            flatten_parameters: true
```

Reapply the manifest:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

List the tools again and inspect the `getPetById` input schema. Its `properties` should now contain `petId` directly. Call the tool using the same request as before, with `"arguments": {"petId": 1}`.

### Customize MCP Tool Annotations[​](#customize-mcp-tool-annotations "Direct link to Customize MCP Tool Annotations")

Availability

MCP tool annotations were introduced in API7 Enterprise 3.9.7 and APISIX 3.19.0.

Add MCP annotations to OpenAPI operations so clients can identify read-only, destructive, and idempotent tools. The converter determines annotations in two ways:

1. It infers default tool behavior from the HTTP method.
2. It reads explicit operation-level configuration from the OpenAPI vendor extension `x-mcp-annotations`.

When both are present, explicit `x-mcp-annotations` values override the inferred defaults.

Annotations are stored in the OpenAPI document rather than the gateway configuration. The document changes below work with APISIX and API7 Gateway.

Complete [Expose Petstore as MCP Tools](#expose-petstore-as-mcp-tools), then host a modified copy of the OpenAPI document. Add annotations to the operations in that copy:

openapi.yaml

```
paths:

  /pet/{petId}:

    get:

      operationId: getPetById

      summary: Find pet by ID.

      x-mcp-annotations:

        title: Get Pet by ID

        readOnlyHint: true

        openWorldHint: false

    delete:

      operationId: deletePet

      summary: Deletes a pet.

      x-mcp-annotations:

        title: Delete Pet

        destructiveHint: true
```

Point the Petstore route to the modified document:

* APISIX
* API7 Gateway

Patch the existing route and replace `<ANNOTATED_OPENAPI_URL>` with the URL of the modified document:

```
curl "http://127.0.0.1:9180/apisix/admin/routes/openapi-to-mcp-route" -X PATCH \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "plugins": {

      "openapi-to-mcp": {

        "openapi_url": "<ANNOTATED_OPENAPI_URL>"

      }

    }

  }'
```

1. In the API7 Dashboard, open your gateway group's service list.
2. Open `openapi-to-mcp-service`, select the `openapi-to-mcp-route` route, and open **Plugins**.
3. Click **Edit** for `openapi-to-mcp`, replace `openapi_url` with the URL of the modified document, and click **Save**.

#### Update Annotations with Ingress Controller[​](#update-annotations-with-ingress-controller "Direct link to Update Annotations with Ingress Controller")

Replace `<ANNOTATED_OPENAPI_URL>` in the resource used by your Ingress Controller deployment and preserve the other resources:

* Gateway API
* APISIX CRD

openapi-to-mcp-ic.yaml (updated PluginConfig)

```
apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: openapi-to-mcp-plugin-config

spec:

  plugins:

    - name: key-auth

      config:

        header: apikey

    - name: openapi-to-mcp

      config:

        transport: streamable_http

        base_url: "http://petstore:8080/api/v3"

        openapi_url: "<ANNOTATED_OPENAPI_URL>"

        flatten_parameters: true
```

openapi-to-mcp-ic.yaml (updated ApisixRoute)

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openapi-to-mcp-route

spec:

  ingressClassName: apisix

  http:

    - name: openapi-to-mcp-route

      match:

        paths:

          - /mcp

        methods:

          - POST

      plugins:

        - name: key-auth

          enable: true

          config:

            header: apikey

        - name: openapi-to-mcp

          enable: true

          config:

            transport: streamable_http

            base_url: "http://petstore:8080/api/v3"

            openapi_url: "<ANNOTATED_OPENAPI_URL>"

            flatten_parameters: true
```

Reapply the manifest:

```
kubectl apply -f openapi-to-mcp-ic.yaml
```

The extension accepts the following fields. Configure only the fields that describe the operation:

```
x-mcp-annotations:

  title: Tool title

  readOnlyHint: true

  destructiveHint: false

  idempotentHint: true

  openWorldHint: false
```

If `x-mcp-annotations` is absent, the converter infers these defaults from the HTTP method:

| HTTP method              | Inferred annotations                            |
| ------------------------ | ----------------------------------------------- |
| `GET`, `HEAD`, `OPTIONS` | `readOnlyHint: true`                            |
| `DELETE`                 | `destructiveHint: true`, `idempotentHint: true` |
| `PUT`                    | `idempotentHint: true`                          |

After updating the hosted OpenAPI document, ask your MCP client to list tools. The following snippet shows the `result.tools` portion of the `tools/list` response:

```
{

  "tools": [

    {

      "name": "getPetById",

      "annotations": {

        "title": "Get Pet by ID",

        "readOnlyHint": true,

        "openWorldHint": false

      }

    },

    {

      "name": "deletePet",

      "annotations": {

        "title": "Delete Pet",

        "destructiveHint": true,

        "idempotentHint": true

      }

    }

  ]

}
```

The converter reads `x-mcp-annotations` only at the operation level and ignores invalid values and unsupported fields. The operation's `summary` and `description` control the generated tool description. The tool title comes only from `x-mcp-annotations.title`.

### Forward Client Headers to an Upstream API[​](#forward-client-headers-to-an-upstream-api "Direct link to Forward Client Headers to an Upstream API")

Client-specific headers, such as tenant IDs or user tokens, can be forwarded to the upstream API. APISIX maps selected headers through request variables, while API7 Gateway uses the OpenAPI-to-MCP service's prefix convention.

Complete [Configure Authentication for MCP Routes](#configure-authentication-for-mcp-routes) first. The following examples reuse the `johndoe` consumer and `john-key` credential, expose HTTPBin's header inspection operation, and verify that a tenant header reaches the upstream API.

* APISIX
* API7 Gateway

Configure the route to map the client's `X-Tenant-Id` header to the upstream request:

```
curl "http://127.0.0.1:9180/apisix/admin/routes/openapi-to-mcp-client-headers" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "uri": "/mcp/headers",

    "methods": ["POST"],

    "plugins": {

      "key-auth": {

        "header": "apikey"

      },

      "openapi-to-mcp": {

        "transport": "streamable_http",

        "base_url": "https://httpbin.org",

        "headers": {

          "X-Tenant-Id": "${http_x_tenant_id}"

        },

        "openapi_url": "https://docs.api7.ai/openapi-to-mcp/httpbin-headers.yaml"

      }

    }

  }'
```

Configure the MCP client with the gateway credential and tenant header:

mcp.json

```
{

  "mcpServers": {

    "httpbin-headers": {

      "url": "http://127.0.0.1:9080/mcp/headers",

      "headers": {

        "apikey": "john-key",

        "X-Tenant-Id": "tenant-42"

      }

    }

  }

}
```

APISIX forwards client-provided header values only for headers explicitly mapped in the plugin configuration. The value `${http_x_tenant_id}` resolves from the current MCP request.

[Deploy the OpenAPI-to-MCP service](#deploy-the-openapi-to-mcp-service-for-api7-gateway), then configure the HTTPBin service and route in the API7 Dashboard:

1. Open your gateway group's service list and click **Add Service**.

2. Select **Add Manually** and name the service `openapi-to-mcp-client-headers`.

3. Set the upstream scheme to HTTPS, select **Use Nodes**, and add `httpbin.org` on port `443`.

4. Create the service, open it, and add a route named `openapi-to-mcp-client-headers` with path `/mcp/headers` and method `POST`.

5. Open the route's **Plugins** page, enable `key-auth` with `header` set to `apikey`, and click **Submit**.

6. Enable `openapi-to-mcp` with the following values:

   | Field           | Value                                                      |
   | --------------- | ---------------------------------------------------------- |
   | `transport`     | `Streamable HTTP`                                          |
   | `base_url`      | `https://httpbin.org`                                      |
   | `allowed_hosts` | `httpbin.org`                                              |
   | `openapi_url`   | `https://docs.api7.ai/openapi-to-mcp/httpbin-headers.yaml` |

7. Click **Submit** to save the plugin configuration.

Configure the MCP client with the gateway credential and a tenant header:

mcp.json

```
{

  "mcpServers": {

    "httpbin-headers": {

      "url": "http://127.0.0.1:9080/mcp/headers",

      "headers": {

        "apikey": "john-key",

        "x-openapi2mcp-header-x-tenant-id": "tenant-42"

      }

    }

  }

}
```

The OpenAPI-to-MCP service removes the `x-openapi2mcp-header-` prefix and forwards the remaining header name in lowercase. The prefixed header itself is not sent upstream. Streamable HTTP reads these headers on every MCP request; SSE captures them when the client opens the connection and keeps them for that session.

caution

An authenticated MCP client can use this prefix to send arbitrary upstream headers. Configure sensitive authentication or authorization headers in the plugin's [`headers`](https://docs.api7.ai/hub/openapi-to-mcp/configuration.md) field, which takes precedence over a client value with the same name. Expose only the operations that clients may call with those credentials.

Ask the client to call the `getHeaders` tool. The tool result should include the header received by HTTPBin:

```
{

  "headers": {

    "X-Tenant-Id": "tenant-42"

  }

}
```

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

Start with the component that processes MCP traffic: the gateway for APISIX or the OpenAPI-to-MCP service for API7 Gateway.

APISIX and the API7 OpenAPI-to-MCP service fetch `openapi_url` separately from API operation calls, so the plugin's `headers` field does not authenticate the document request. If the document requires authentication, publish a reviewed copy at a location accessible to the gateway or service within a restricted network. Keep credentials out of the document URL.

### APISIX[​](#apisix "Direct link to APISIX")

Inspect the APISIX error log first. If the client cannot list tools, test `openapi_url` from the gateway's network environment and confirm that it returns HTTP `200` with an OpenAPI document containing API paths. An HTML login page, redirect, authentication error, or document containing only components cannot produce tools.

If the document uses a private CA, add that CA to the gateway runtime trust store.

### API7 Gateway[​](#api7-gateway "Direct link to API7 Gateway")

Conversion failures may not appear in the gateway error log. Inspect the OpenAPI-to-MCP service logs with `docker compose logs openapi-to-mcp` or `kubectl logs <gateway-pod> -c openapi-to-mcp`.

If the client cannot load tools, verify that `openapi_url` returns an OpenAPI document from the service's network environment. The service follows redirects, so check the final response body for an HTML login page or another non-OpenAPI response.

The service's `VERIFY_SSL` setting applies to API calls rather than document fetching. Install a required private CA in the service runtime trust store.

If the MCP route returns `502`, confirm that the service is running and listening on the port configured for the gateway plugin. A timeout before the backend responds returns `status: 0` with `timeout of <TIMEOUT>ms exceeded`; if a response starts and then stalls, the service logs `stream has been aborted`.
