ASP.NET Core MCP Server - Complete Setup Guide
Configure Swashbuckle, export OpenAPI, and generate MCP servers for Claude Desktop.
Key Takeaways
- Swashbuckle makes OpenAPI export straightforward for ASP.NET Core.
- LegacyAI converts the OpenAPI spec into an MCP server quickly.
- Claude Desktop uses the MCP server to call your API as tools.
- Use scoped auth and read-only defaults for safe production rollouts.
Prerequisites
- An ASP.NET Core API project targeting .NET 6 or later.
- Swashbuckle.AspNetCore installed and configured.
- Access to LegacyAI for MCP generation.
Step 1: Add Swashbuckle
Swashbuckle generates your OpenAPI document at runtime. Install the package and register Swagger services.
dotnet add package Swashbuckle.AspNetCoreStep 2: Configure Swagger in Program.cs
Enable Swagger for your API and set the OpenAPI metadata. This ensures the spec includes the correct title, version, and auth schemes.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new() { Title = "LegacyAI API", Version = "v1" });
});
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.Run();
Step 3: Export the OpenAPI spec
Run the API locally and fetch the JSON from /swagger/v1/swagger.json. Save it as openapi.json for LegacyAI.
curl http://localhost:5000/swagger/v1/swagger.json -o openapi.jsonStep 4: Generate MCP tools with LegacyAI
Upload the OpenAPI file to LegacyAI. The generator will map controllers and routes to MCP tools, apply validation, and detect auth schemes.
Use the dashboard to enable read-only mode and configure tool scopes before publishing.
Step 5: Connect Claude Desktop
Add your MCP server to Claude Desktop using the MCP configuration file. Make sure you store tokens in environment variables and not in plain text.
{
"mcpServers": [
{
"name": "LegacyAI ASP.NET Core",
"command": "node",
"args": ["./legacyai-mcp-server.js"],
"env": {
"API_BASE_URL": "https://api.yourcompany.com",
"API_TOKEN": "${API_TOKEN}"
}
}
]
}Step 6: Verify tool calls
In Claude Desktop, ask the agent to call a read-only endpoint and verify that it returns expected data. Review logs for validation errors or missing headers.
FAQ
Do I need Swashbuckle if I already use NSwag?
No. Any OpenAPI generator works. Swashbuckle is common, but NSwag output is compatible with LegacyAI as long as the spec is valid.
Can I generate the spec during CI?
Yes. Many teams run the API in CI, export the OpenAPI file, and trigger MCP generation automatically.
How do I handle multiple API versions?
Export a spec per version and generate separate MCP servers so each tool catalog maps to the correct version.
Is my API exposed publicly?
No. You can upload the spec file directly without exposing the API. The MCP server runs on your infrastructure and calls the API securely.
How do I keep MCP tools in sync?
Use LegacyAI dynamic sync or a CI trigger so the MCP server refreshes tools when your OpenAPI spec changes.
Related articles
Tutorials
How to Connect FastAPI to Claude Desktop in 5 Minutes
A step-by-step guide to generate MCP tools from FastAPI and register them in Claude Desktop.
Tutorials
How to Generate MCP Server from Swagger JSON
Use Swagger JSON to generate MCP tools, then verify and ship them safely.
Security
Choosing Auth Strategy for MCP - JWT vs API Key vs OAuth
Compare auth strategies, learn when to use each, and see how LegacyAI detects them.