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,49 +8,51 @@ public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var builder = WebApplication.CreateBuilder(args); if (args.Contains("--stdio", StringComparer.InvariantCultureIgnoreCase))
builder.Services
.AddMcpServer()
//.WithStdioServerTransport()
.WithHttpTransport()
.WithTools<MathTools>()
.WithResources<DocumentationResources>();
builder.Services.AddCors(options =>
{ {
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 options.AddDefaultPolicy(policy =>
.AllowAnyOrigin() {
.AllowAnyHeader() policy
.AllowAnyMethod() .AllowAnyOrigin()
.WithExposedHeaders("Mcp-Session-Id"); .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 app.Run();
//builder.Services.AddOpenApi();
var app = builder.Build();
app.UseCors();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi();
} }
//app.UseAuthorization();
//app.MapControllers();
app.MapMcp("/mcp");
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
} }
} }
} }