Python
Get an OpenAPI spec from Flask
Plain Flask has no spec. flask-smorest adds one, but routes must use its blueprints.
How it works
Flask itself does not describe your API. flask-smorest adds OpenAPI support, but only for routes written with its Blueprint and marshmallow schemas. Routes written with plain @app.route are not included.
If you have many plain Flask routes and do not want to change them, skip this guide: use From code (GitHub) in MCPEasy, which reads your routes directly, or export a Postman collection.
Step by step
Step 1: Install flask-smorest
It brings marshmallow, which describes your inputs.
Terminalpip install flask-smorestStep 2: Set up the Api object
Where you create your Flask app:
app.pyfrom flask import Flask from flask_smorest import Api app = Flask(__name__) app.config["API_TITLE"] = "My API" app.config["API_VERSION"] = "v1" app.config["OPENAPI_VERSION"] = "3.0.3" app.config["OPENAPI_URL_PREFIX"] = "/" api = Api(app)Step 3: Write routes as blueprints with schemas
Each route says what it accepts (@blp.arguments) and returns (@blp.response). Register the blueprint with api.register_blueprint, not app.register_blueprint, or it will not be in the spec.
bookings.pyimport marshmallow as ma from flask_smorest import Blueprint class BookingSchema(ma.Schema): service_id = ma.fields.String(required=True) start_time = ma.fields.DateTime(required=True) blp = Blueprint("bookings", __name__, url_prefix="/bookings", description="Bookings") @blp.route("/", methods=["POST"]) @blp.arguments(BookingSchema) @blp.response(201, BookingSchema) def create_booking(data): """Create a booking Books an appointment in a free slot. """ # data is the validated request body return dataapp.pyfrom bookings import blp as bookings_blp api.register_blueprint(bookings_blp)Step 4: Get the spec
While the app runs, the spec is at /openapi.json (because OPENAPI_URL_PREFIX is "/"). To write a file, use the flask command that flask-smorest adds:
Terminalflask --app app openapi write openapi.jsonTerminal (YAML)flask --app app openapi write --format=yaml openapi.yamlChange --app app to your module name if your app is not in app.py.
Check that it worked
- http://localhost:5000/openapi.json shows your blueprint routes under "paths".
Give it to MCPEasy
Have a link? Paste it (best)
In MCPEasy, create a server, choose OpenAPI URL and paste the link, for example https://api.example.com/openapi.json. Later changes to your API can be picked up with a sync.
Have a file? Upload it
Choose Upload file and drop in the .json or .yaml file (up to 5 MB). MCPEasy turns each endpoint into a tool, and you review them all before anything goes live.
If something goes wrong
- /openapi.json returns 404.
- Set app.config["OPENAPI_URL_PREFIX"] = "/". Without it, flask-smorest does not serve the spec.
- Some routes are missing.
- They use @app.route or were registered with app.register_blueprint. Move them to a flask-smorest Blueprint registered with api.register_blueprint, or use From code (GitHub) in MCPEasy.
Still stuck, or no time to set this up? In MCPEasy choose From code (GitHub): it reads your routes straight from the repository, read-only, and tests every tool against your live API before it goes live.
Official documentation
Other frameworks
More guides for MCP and OpenAPI
- OpenAPI to MCP serverHow a spec maps to MCP tools, which endpoints to keep, and how auth works.
- REST API to MCP serverConvert any API, with or without a spec: Postman, cURL, code, plus a worked example.
- Get an OpenAPI spec from your frameworkExport an OpenAPI (Swagger) file from 11 frameworks, step by step.
- OpenAPI spec from FastAPINothing to install: FastAPI already serves your spec at /openapi.json.
- OpenAPI spec from ExpressThe packages, code and commands to produce a spec from an Express app.