add: gitea tools
This commit is contained in:
36
Program.cs
36
Program.cs
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user