Add support for stdio-based server mode alongside HTTP service integration

This commit is contained in:
Jordan Wages 2026-08-18 22:48:37 -05:00
commit 85eedab29d
2 changed files with 46 additions and 41 deletions

View file

@ -1,5 +1,6 @@
using cs_mic_mcp.Resources;
using cs_mic_mcp.Tools;
using Microsoft.AspNetCore.Localization;
namespace cs_mic_mcp;
@ -7,49 +8,51 @@ public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer()
//.WithStdioServerTransport()
.WithHttpTransport()
.WithTools<MathTools>()
.WithResources<DocumentationResources>();
builder.Services.AddCors(options =>
if (args.Contains("--stdio", StringComparer.InvariantCultureIgnoreCase))
{
options.AddDefaultPolicy(policy =>
// stdio pipeline - local only
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithTools<MathTools>()
.WithResources<DocumentationResources>();
var app = builder.Build();
app.Run();
}
else
{
// web pipeline - http service
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithTools<MathTools>()
.WithResources<DocumentationResources>();
builder.Services.AddCors(options =>
{
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Mcp-Session-Id");
options.AddDefaultPolicy(policy =>
{
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Mcp-Session-Id");
});
});
});
// Add services to the container.
var app = builder.Build();
app.UseCors();
//builder.Services.AddControllers();
app.MapMcp("/mcp");
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
//builder.Services.AddOpenApi();
var app = builder.Build();
app.UseCors();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi();
app.Run();
}
//app.UseAuthorization();
//app.MapControllers();
app.MapMcp("/mcp");
app.Run();
}
}

View file

@ -5,10 +5,12 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5017",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"applicationUrl": "http://localhost:5000"
},
"stdio": {
"commandName": "Project",
"commandLineArgs": "--stdio",
"dotnetRunMessages": false
}
}
}