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);
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Mcp-Session-Id");
});
});
// Add services to the container. builder.Services
.AddMcpServer()
//builder.Services.AddControllers(); .WithStdioServerTransport()
.WithTools<MathTools>()
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi .WithResources<DocumentationResources>();
//builder.Services.AddOpenApi();
var app = builder.Build();
var app = builder.Build();
app.UseCors(); app.Run();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi();
} }
else
{
// web pipeline - http service
var builder = WebApplication.CreateBuilder(args);
//app.UseAuthorization(); builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithTools<MathTools>()
.WithResources<DocumentationResources>();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Mcp-Session-Id");
});
});
var app = builder.Build();
app.UseCors();
//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
} }
} }
} }