add: gitea tools

This commit is contained in:
h z
2025-05-08 01:14:41 +01:00
parent 58d9c333e0
commit c21d047826
9 changed files with 731 additions and 219 deletions

View File

@@ -1,3 +1,5 @@
using Alchegos.MCP.Middleware;
var builder = WebApplication.CreateBuilder(args);
const int BIND_PORT = 5050;
@@ -6,13 +8,41 @@ builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithToolsFromAssembly();
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(BIND_PORT));
//builder.Services.AddHttpLogging(o => { });
var app = builder.Build();
// var logger = app.Logger;
//app.UseHttpLogging();
app.UseRequestBodyLogging();
app.Use(async (context, next) =>
{
var expectedToken = Environment.GetEnvironmentVariable("MCP_API_KEY");
if (string.IsNullOrEmpty(expectedToken))
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync("API Key not configured");
return;
}
if (!context.Request.Headers.TryGetValue("X-Api-Key", out var apiKey) ||
string.IsNullOrEmpty(apiKey))
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Missing API Key");
return;
}
if (apiKey != expectedToken)
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Invalid API Key");
return;
}
await next();
});
app.MapMcp();
app.Run();