Skip to content

Auto-Generate an AirStack Edge MCP Server

This tutorial shows how to generate a basic Model Context Protocol (MCP) server from the AirStack Edge OpenAPI documentation. Instead of writing one MCP tool per API endpoint, FastMCP reads the OpenAPI schema and automatically exposes the documented AirStack Edge operations as MCP tools.

The example uses FastMCP.from_openapi() from FastMCP. This is a fast way to prototype an MCP interface over AirStack Edge while still using the API documentation as the source of truth.

AirStack Edge and OpenAPI

AirStack Edge exposes its REST API using the OpenAPI Specification. OpenAPI is a standard, machine-readable description format for REST-style APIs. It defines what paths are available, which HTTP methods they support, what authentication is required, what request bodies and parameters are valid, and what response formats clients should expect.

For MCP, this is useful because the OpenAPI document already contains the information a tool server needs: endpoint names, summaries, schemas, and request/response structure. FastMCP can read the Edge OpenAPI document and automatically turn those documented operations into MCP tools.

Prerequisites

You will need:

  • An AirStack Edge instance reachable from the machine running the MCP server
  • A bearer token for the Edge API
  • The CA certificate used by your Edge instance, or a development environment where certificate verification can be disabled
  • A local copy of the AirStack Edge OpenAPI JSON schema
  • Python 3.10 or newer
  • uv for Python project and dependency management
  • Node.js and npx for the MCP Inspector

Create a uv project and install the Python dependencies:

uv init airstack-edge-mcp
cd airstack-edge-mcp
uv add fastmcp httpx

Download the OpenAPI Documentation

When AirStack Edge is running, the API reference is published by the Edge service using Scalar:

https://<hostname:port>/docs/

Scalar renders an OpenAPI JSON schema. That schema contains the endpoint paths, HTTP methods, request body schemas, response types, authentication requirements, tags, summaries, and operationId values. FastMCP uses that metadata to generate MCP tools.

Download the OpenAPI JSON before starting the MCP server. The server in this tutorial reads the schema from disk and does not automatically fetch API documentation at startup.

Open https://<hostname:port>/docs/ in a browser, click Scalar's download button, and save the file as:

openapi/airstack-edge_openapi.json

The bundled documentation in this repository is also available at ../api_documentation/openapi.json. You can use that file for local prototyping, but the schema downloaded from your Edge device is the best match for that device's installed software version.

Generate the MCP Server From OpenAPI

Create a file named airstack_openapi_mcp.py:

import json
import os
from pathlib import Path
from typing import Any

import httpx
from fastmcp import FastMCP


def parse_verify(value: str) -> bool | str:
    if value.lower() in {"false", "0", "no"}:
        return False
    if value.lower() in {"true", "1", "yes"}:
        return True
    return value


def load_openapi_spec(openapi_path: str) -> dict[str, Any]:
    return json.loads(Path(openapi_path).read_text())


EDGE_BASE_URL = os.environ["EDGE_BASE_URL"].rstrip("/")
EDGE_BEARER_TOKEN = os.environ["EDGE_BEARER_TOKEN"]
EDGE_VERIFY = parse_verify(os.getenv("EDGE_CA_CERT", "true"))
EDGE_OPENAPI_PATH = os.environ["EDGE_OPENAPI_PATH"]

openapi_spec = load_openapi_spec(EDGE_OPENAPI_PATH)

edge_client = httpx.AsyncClient(
    base_url=EDGE_BASE_URL,
    headers={"Authorization": f"Bearer {EDGE_BEARER_TOKEN}"},
    verify=EDGE_VERIFY,
    timeout=30.0,
)

mcp = FastMCP.from_openapi(
    openapi_spec=openapi_spec,
    client=edge_client,
    name="AirStack Edge OpenAPI",
)

if __name__ == "__main__":
    mcp.run(transport="http", host="127.0.0.1", port=8000)

There are no @mcp.tool() definitions in this file. The tools are generated from the OpenAPI schema. FastMCP uses the documented routes and operationId values to create MCP components, then uses the authenticated httpx.AsyncClient to call the real AirStack Edge API.

Configure and Run

Run the generated MCP server with the required environment variables.

On Linux, macOS, WSL, or Git Bash:

EDGE_BASE_URL="https://<hostname:port>/" \
EDGE_BEARER_TOKEN="<your-edge-bearer-token>" \
EDGE_OPENAPI_PATH="$PWD/openapi/airstack-edge_openapi.json" \
EDGE_CA_CERT="false" \
uv run python airstack_openapi_mcp.py

On Windows PowerShell:

$env:EDGE_BASE_URL = "https://<hostname:port>/"; $env:EDGE_BEARER_TOKEN = "<your-edge-bearer-token>"; $env:EDGE_OPENAPI_PATH = "$PWD\openapi\airstack-edge_openapi.json"; $env:EDGE_CA_CERT = "false"; uv run python airstack_openapi_mcp.py

The examples above set EDGE_CA_CERT to false, which disables certificate verification for local development. For a trusted certificate chain, set EDGE_CA_CERT to true instead. For a private CA or self-signed deployment, set EDGE_CA_CERT to the CA certificate path, such as /path/to/edge-ca.pem on Linux or macOS, or C:\path\to\edge-ca.pem on Windows.

The MCP endpoint will be available at:

http://127.0.0.1:8000/mcp

View the Generated Server With the MCP Inspector

Use the MCP Inspector to verify that the generated tools are visible. The command is npx, not ngx:

npx -y @modelcontextprotocol/inspector

In the Inspector:

  1. Set the transport to Streamable HTTP.
  2. Set the URL to http://127.0.0.1:8000/mcp.
  3. Click Connect.
  4. Open the Tools tab.
  5. Click List Tools.

You should see tools corresponding to the AirStack Edge OpenAPI operations. Tool names are derived from the OpenAPI operationId values, so names may look like take, release, info, open, open_tx, list_triton, run_predict, or register.