C# (.NET)
Get an OpenAPI spec from ASP.NET Core
.NET 9+: AddOpenApi() and MapOpenApi() serve /openapi/v1.json. .NET 8: Swashbuckle.
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
Step 1: Add the package (.NET 9 or newer)
New web API projects already include it. If yours does not:
Terminaldotnet add package Microsoft.AspNetCore.OpenApiStep 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.csvar 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();Step 3: Run it and get the spec
dotnet run prints the local address. Open it with /openapi/v1.json on the end.
Terminaldotnet runTerminal (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.
Step 1: Install and register
Terminaldotnet add package Swashbuckle.AspNetCoreProgram.csbuilder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseSwagger(); // serves /swagger/v1/swagger.json app.UseSwaggerUI(); // browsable page at /swaggerStep 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
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.