Skip to main content
Version: Dev

Expose a REST API as MCP Tools

An MCP server registry entry can be backed by a plain REST API instead of an upstream MCP server. Register the API's OpenAPI 3.x document with type set to openapi, and AISIX generates one MCP tool per operation. A tools/call executes as an HTTP request against the API's base URL, with the gateway-held credential attached when configured. The MCP caller never receives the credential, and the API needs no MCP server of its own.

This turns existing internal services, such as an ERP, inventory system, or payroll API, into agent-callable tools. Tool access control, traffic controls, guardrails, and observability apply through both the control-plane and resources-file paths. AISIX Enterprise and AISIX Cloud also provide server review and shared access policies.

Prerequisites​

Before starting, prepare the following:

  • For AISIX Enterprise, complete the AISIX Enterprise getting-started guide, then keep its shell and attached gateway running. For AISIX Cloud, obtain an environment, attached gateway, caller API key, and gateway URL from your organization. Dashboard users need permission to manage MCP servers and caller API keys. Admin API users need a write-scoped token from an identity with those resource permissions. To request AISIX Cloud access, contact API7.
  • For an open-source AISIX gateway, complete Set Up MCP Gateway, then remain in its shell and working directory without cleaning up its temporary Docker network.
  • cURL and jq for the control-plane example.

How Tools Are Generated​

AISIX walks the document's paths and generates one tool per operation for the get, post, put, delete, and patch methods:

  • Tool name: the operation's operationId, lowercased, with any character outside a-z, 0-9, _, and - replaced by _, capped at 128 characters. An operation without an operationId is named <method>_<path> under the same rules. Tools are exposed to callers as <server-name>__<tool-name>, like every MCP tool.
  • Input schema: each path and query parameter becomes a property with its type, description, enum values, and required flag. A JSON request body becomes a single body object property, marked required when the spec says so. Local $refs, including referenced component schemas inside the body, are resolved so the agent sees the real shape. Header and cookie parameters are not exposed because upstream headers belong to the gateway, not the caller.
  • Skipped operations: an operation whose request body has no application/json variant, such as a multipart/form-data file upload, is skipped rather than generating a tool that cannot succeed.

Validation timing differs by management path. The AISIX Cloud Admin API validates the document during registration. It rejects a document that cannot be parsed, a Swagger 2.0 document, a document with no tool-generatable operations, or operationIds that collide after normalization. The create response returns the generated names in tool_names.

With resources.yaml, aisix validate checks that spec is a mapping and is not a Swagger document. The gateway generates tools when it loads the server from resources.yaml or etcd, using the same logic that serves them at runtime. It refuses a document with no usable paths or only unsupported operations, such as multipart/form-data uploads. In resources.yaml, aisix validate reports this as a load error. A server rejected from etcd appears in the rejected list of /status/config and in aisix_config_rejected_resources.

Normalized name collisions still load. They receive _2, _3, and subsequent suffixes so every operation remains reachable, and aisix validate prints a warning naming the colliding tool names while still exiting with status 0. List tools after loading the file to verify the generated surface.

Register a REST API​

The registration shape differs between the control-plane and AISIX OSS management paths. In both cases, url is the REST API base URL, and generated calls are issued against <url><path>.

Register and Review the Server​

  1. Open MCP servers and select New MCP server.
  2. Under Server type, select REST API (OpenAPI).
  3. Enter httpbin in Name and https://httpbin.org in API base URL.
  4. Under OpenAPI document, choose Paste document. You can instead choose Fetch from URL, or select Choose file… to load a local .json, .yaml, or .yml file into the editor.

Paste this document into the editor:

{
"openapi": "3.0.0",
"info": {
"title": "HTTPBin",
"version": "1.0.0"
},
"paths": {
"/anything": {
"get": {
"operationId": "inspectRequest",
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
  1. Choose the upstream Authentication and select the target under Available in environments.
  2. Select Register MCP server.
New REST API MCP server form with the API base URL and OpenAPI document URL configured

The server row shows an OpenAPI badge and a preview of generated tool names. Select View tools or View all N to open the tools page, where Search tools filters the Tool, Operation, and Description columns.

Grant the Tool to a Caller Key​

  1. Open the environment and select API keys.
  2. If you have the plaintext of an existing caller key, select Edit. Otherwise, select New API key and enter a display name.
  3. Grant httpbin__inspectrequest under MCP tool access.
  4. Select Save changes for an existing key, or Create API key for a new key.
  5. For a new key, copy the plaintext from the one-time view before dismissing it.

Export the plaintext key you copied:

export AISIX_MCP_KEY="YOUR_CALLER_API_KEY"

Review the Generated Tools in AISIX Enterprise or AISIX Cloud​

Each registered server's card lists the first few generated tool names and links to a tools page for that server, which lists every tool with:

  • its <server>__<tool> name, which is the form to copy into an API key's mcp_access block or an access policy pattern;
  • the HTTP operation it calls, such as GET /items/{id};
  • its description.

Use Search tools to filter the Tool, Operation, and Description columns.

Authenticate to the REST API​

The upstream authentication modes apply as-is; the credential is attached to every generated tool call:

  • bearer: Authorization: Bearer <secret>.
  • api_key: the key from secret, sent as the x-api-key header by default. REST APIs often expect a custom header: set api_key_header (for example X-ERP-Key) to override the header name. This field exists only on openapi servers with auth_type: api_key.
  • oauth2: AISIX mints an access token from the configured client credentials and sends it as a bearer, with the same token caching as MCP upstreams.
  • oauth_delegate: AISIX relays the caller's own Authorization header when the caller sent its gateway key in x-aisix-api-key. See Delegate the Caller's Token.
  • oauth2_token_exchange: AISIX exchanges the caller's verified Entra ID token for a token to the REST API and sends it as a bearer. See Entra On-Behalf-Of Token Exchange.

Redirects are never followed on generated tool calls, so the credential cannot be re-sent to a host you did not configure.

Call Results and Errors​

A successful response's body is returned as the tool result text. A non-2xx response returns a tool-level error result (isError: true) carrying HTTP <status> and the response body, so the agent can see and react to the failure. A missing required path parameter is reported the same readable way. AISIX also rejects a path value that contains / or \, or that equals . or .., to keep the request on the configured path.

Update the Document​

Replacing the document regenerates the tool list.

An approved replacement updates the review timestamp and starts projecting the new tool surface when the update returns. A role holding only mcp_server_submissions permissions stages the replacement instead, so the current tools remain live until approval.

  1. Select Edit on the OpenAPI-backed server.
  2. Paste the new document into Replace OpenAPI document, or select Choose file….
  3. Select Save. Leaving the replacement empty keeps the current document.
  4. Open the tools page and confirm that the regenerated list matches the replacement.

To remove the registry entry from every environment, select Delete and confirm.

In AISIX Enterprise and AISIX Cloud, the server's type is fixed at creation. To switch between an MCP upstream and an OpenAPI backing, delete the entry and register a new one. In resources.yaml, change the entry and reload the file; the validated configuration replaces the previous runtime entry.

Next Steps​

You can now expose a REST API as MCP tools through either management path. Use these guides to secure and govern the generated tools: