All framework guides

Java or Kotlin

Get an OpenAPI spec from Spring Boot

Add the springdoc dependency. The spec is served at /v3/api-docs.

Tool
springdoc-openapi
Time
About 3 minutes
You get
Live at /v3/api-docs (OpenAPI 3)

How it works

springdoc reads your @RestController classes, their mappings (@GetMapping, @PostMapping...), @RequestBody classes and validation annotations while the app starts, and serves the spec.

Step by step

  1. Step 1: Add the dependency

    Pick the version line that matches your Spring Boot version: 2.x for Spring Boot 3, 3.x for Spring Boot 4. Check Maven Central for the newest release in that line.

    pom.xml (Maven, Spring Boot 3)
    <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.8.6</version>
    </dependency>
    build.gradle (Gradle, Spring Boot 3)
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6'

    Using WebFlux? Use springdoc-openapi-starter-webflux-ui instead. Still on Spring Boot 2? Use org.springdoc:springdoc-openapi-ui:1.8.0.

  2. Step 2: Run the app and open the spec

    The spec is at /v3/api-docs (JSON) and /v3/api-docs.yaml. A browsable page is at /swagger-ui.html.

    Terminal (Maven)
    ./mvnw spring-boot:run
    Terminal (Gradle)
    ./gradlew bootRun
    Terminal (save a file)
    curl http://localhost:8080/v3/api-docs -o openapi.json

    On your live server the link is https://api.example.com/v3/api-docs. Paste it into MCPEasy under OpenAPI URL.

  3. Step 3: If you use Spring Security

    The spec links need to be reachable without signing in. Add this matcher to your existing security rules:

    SecurityConfig.java
    http.authorizeHttpRequests(auth -> auth
        .requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
        .anyRequest().authenticated());
  4. Step 4: Optional: better descriptions

    @Operation gives each tool a clear description.

    BookingController.java
    import io.swagger.v3.oas.annotations.Operation;
    
    @PostMapping("/bookings")
    @Operation(summary = "Create a booking", description = "Books an appointment in a free slot.")
    public Booking create(@Valid @RequestBody CreateBookingRequest request) {
        // ...
    }

Check that it worked

  • http://localhost:8080/v3/api-docs returns JSON with every controller route 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

/v3/api-docs returns 401 or 403.
Spring Security blocks it. Add the permitAll matcher from step 3.
/v3/api-docs returns 404 in production only.
Your production profile may set springdoc.api-docs.enabled=false. Turn it on, or download the file locally and upload it.
The app fails to start after adding the dependency.
The springdoc version line does not match your Spring Boot version. See step 1.

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