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.Resources;
using cs_mic_mcp.Tools; using cs_mic_mcp.Tools;
using Microsoft.AspNetCore.Localization;
namespace cs_mic_mcp; namespace cs_mic_mcp;
@ -7,11 +8,28 @@ public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
if (args.Contains("--stdio", StringComparer.InvariantCultureIgnoreCase))
{
// 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); var builder = WebApplication.CreateBuilder(args);
builder.Services builder.Services
.AddMcpServer() .AddMcpServer()
//.WithStdioServerTransport()
.WithHttpTransport() .WithHttpTransport()
.WithTools<MathTools>() .WithTools<MathTools>()
.WithResources<DocumentationResources>(); .WithResources<DocumentationResources>();
@ -28,28 +46,13 @@ public class Program
}); });
}); });
// Add services to the container.
//builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
//builder.Services.AddOpenApi();
var app = builder.Build(); var app = builder.Build();
app.UseCors(); app.UseCors();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi();
}
//app.UseAuthorization();
//app.MapControllers();
app.MapMcp("/mcp"); app.MapMcp("/mcp");
app.Run(); app.Run();
} }
}
} }

View file

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