Go
Get an OpenAPI spec from Go (gin, echo, chi, net/http)
swag builds the spec from comments above your handlers. swag init writes docs/swagger.json.
How it works
Go has no standard way to describe an API. swag reads special comments above main() and above each handler, and writes the spec. Only handlers with comments appear.
The output is Swagger 2.0, which MCPEasy reads fine. If you have many handlers without comments, From code (GitHub) in MCPEasy is faster.
Step by step
Step 1: Install the swag command
Make sure your Go bin folder (go env GOPATH, then /bin) is on your PATH so the swag command is found.
Terminalgo install github.com/swaggo/swag/cmd/swag@latestStep 2: Describe the API above main()
These comments go directly above func main().
main.go// @title My API // @version 1.0 // @description What this API does, in one sentence. // @host api.example.com // @BasePath /api/v1 // @securityDefinitions.apikey BearerAuth // @in header // @name Authorization func main() { // ... }Step 3: Describe each handler
One block per handler. @Router is the path and method; @Param body points at the request struct, so its fields appear.
bookings.gotype CreateBookingRequest struct { ServiceID string `json:"service_id" binding:"required"` StartTime string `json:"start_time" binding:"required"` } // CreateBooking godoc // @Summary Create a booking // @Description Books an appointment in a free slot. // @Tags bookings // @Accept json // @Produce json // @Param booking body CreateBookingRequest true "Booking details" // @Success 201 {object} Booking // @Security BearerAuth // @Router /bookings [post] func CreateBooking(c *gin.Context) { // ... }Step 4: Generate the files
Run in the folder with main.go. If main.go is elsewhere, point at it with -g.
Terminalswag initTerminal (main.go in another folder)swag init -g cmd/api/main.goThis writes docs/swagger.json, docs/swagger.yaml and docs/docs.go. Upload docs/swagger.json to MCPEasy.
Step 5: Optional: serve it (gin)
With gin-swagger, the spec is served at /swagger/doc.json. Replace yourmodule with your module name from go.mod.
Terminalgo get github.com/swaggo/gin-swagger github.com/swaggo/filesmain.goimport ( swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" _ "yourmodule/docs" ) r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))For echo use github.com/swaggo/echo-swagger; for chi and net/http use github.com/swaggo/http-swagger.
Check that it worked
- docs/swagger.json lists each handler you commented 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
- swag: command not found.
- Your Go bin folder is not on PATH. Add $(go env GOPATH)/bin to PATH and open a new terminal.
- A handler is missing.
- It has no @Router comment, or the comment block is not directly above the function.
- cannot find type definition.
- swag could not find the struct named in @Param or @Success. Use the package name, for example models.Booking, or run swag init --parseDependency.
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.