All framework guides

C# (.NET)

Get an OpenAPI spec from ASP.NET Core

.NET 9+: AddOpenApi() and MapOpenApi() serve /openapi/v1.json. .NET 8: Swashbuckle.

Tool
Microsoft.AspNetCore.OpenApi or Swashbuckle
Time
About 3 minutes
You get
Live at /openapi/v1.json (.NET 9+) or /swagger/v1/swagger.json (.NET 8)

How it works

ASP.NET Core reads your controllers or minimal API endpoints, their parameters and request classes, and serves the spec while the app runs.

Since .NET 9, this is built in (Microsoft.AspNetCore.OpenApi). Older projects usually use Swashbuckle. Check which one your Program.cs already has: many projects are already set up.

Step by step

  1. Step 1: Add the package (.NET 9 or newer)

    New web API projects already include it. If yours does not:

    Terminal
    dotnet add package Microsoft.AspNetCore.OpenApi
  2. Step 2: Register and map it in Program.cs

    Add the two OpenApi lines. Project templates put MapOpenApi() inside if (app.Environment.IsDevelopment()), which means it is off on your live server. Move it outside that block if you want a live link.

    Program.cs
    var builder = WebApplication.CreateBuilder(args);
    
    builder.Services.AddControllers(); // if you use controllers
    builder.Services.AddOpenApi();     // NEW
    
    var app = builder.Build();
    
    app.MapOpenApi();                  // NEW: serves /openapi/v1.json
    app.MapControllers();
    
    app.Run();
  3. Step 3: Run it and get the spec

    dotnet run prints the local address. Open it with /openapi/v1.json on the end.

    Terminal
    dotnet run
    Terminal (save a file; use your port)
    curl http://localhost:5000/openapi/v1.json -o openapi.json

Check that it worked

  • The JSON lists every controller action or minimal API endpoint 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.

.NET 8 or older: Swashbuckle

If your Program.cs already has AddSwaggerGen(), it is set up: open /swagger/v1/swagger.json.

  1. Step 1: Install and register

    Terminal
    dotnet add package Swashbuckle.AspNetCore
    Program.cs
    builder.Services.AddEndpointsApiExplorer();
    builder.Services.AddSwaggerGen();
    
    var app = builder.Build();
    
    app.UseSwagger();    // serves /swagger/v1/swagger.json
    app.UseSwaggerUI();  // browsable page at /swagger
  2. Step 2: Get the spec

    Run the app and open /swagger/v1/swagger.json, or save it:

    Terminal (use your port)
    curl http://localhost:5000/swagger/v1/swagger.json -o openapi.json

If something goes wrong

The link works locally but returns 404 on the live server.
MapOpenApi() or UseSwagger() is inside if (app.Environment.IsDevelopment()). Move it out, or download the file locally and upload it.
Minimal API endpoints have no descriptions.
Add .WithSummary("Create a booking") and .WithDescription("...") to each MapGet / MapPost.

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