Node.js (JavaScript or TypeScript)
Get an OpenAPI spec from Fastify
Register @fastify/swagger before your routes. The spec is served at /documentation/json.
How it works
@fastify/swagger collects every route you register after it, and uses each route's schema (body, querystring, params, response) for the inputs.
Routes without a schema still appear with their path and method, but without fields.
Step by step
Step 1: Install the plugins
@fastify/swagger builds the spec. @fastify/swagger-ui serves it and a browsable page.
Terminalnpm install @fastify/swagger @fastify/swagger-uiStep 2: Register them before your routes
Order matters: routes registered before @fastify/swagger are not included.
server.jsconst fastify = require('fastify')({ logger: true }); async function start() { await fastify.register(require('@fastify/swagger'), { openapi: { info: { title: 'My API', description: 'What this API does.', version: '1.0.0' }, servers: [{ url: 'https://api.example.com' }], }, }); await fastify.register(require('@fastify/swagger-ui'), { routePrefix: '/documentation' }); // your routes go here, after the two plugins fastify.register(require('./routes/bookings')); await fastify.listen({ port: 3000 }); } start();Using ES modules? Write import swagger from '@fastify/swagger' and import swaggerUi from '@fastify/swagger-ui', then register(swagger, {...}) and register(swaggerUi, {...}).
Step 3: Give routes a schema (recommended)
This is how fields, types and required inputs get into the spec.
routes/bookings.jsmodule.exports = async function (fastify) { fastify.post('/bookings', { schema: { summary: 'Create a booking', description: 'Books an appointment in a free slot.', body: { type: 'object', required: ['service_id', 'start_time'], properties: { service_id: { type: 'string' }, start_time: { type: 'string', format: 'date-time' }, }, }, }, }, async (request, reply) => { // ... }); };Step 4: Get the spec
Start the app and open /documentation/json. On your live server: https://api.example.com/documentation/json.
To save a file instead, add these lines after all routes are registered (for example right before fastify.listen):
server.jsawait fastify.ready(); require('fs').writeFileSync('openapi.json', JSON.stringify(fastify.swagger(), null, 2));Terminalcurl http://localhost:3000/documentation/json -o openapi.json
Check that it worked
- Open http://localhost:3000/documentation/json. Every route should be under "paths".
- Routes with a schema should show their fields.
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
- Some routes are missing.
- They were registered before @fastify/swagger. Move the two register calls above your routes, and await them.
- Routes have no fields.
- Add a schema to those routes (step 3). Fastify cannot see fields you read in the handler without one.
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.