From b73d00a5c546471715c2dced67ceced2ad72672b Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Tue, 1 Jul 2025 11:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8=E9=A1=B5(?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=9C=89=E6=95=88=E3=80=81=E5=AD=90=E7=AB=99?= =?UTF-8?q?=E7=82=B9=E6=9C=89=E6=95=88=E6=9E=9C)=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E7=A1=AE=E8=AE=A4=E9=83=A8=E7=BD=B2=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=8F=8A=E5=8A=9F=E8=83=BD=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- McpStudy.McpServerSSE/Index.html | 33 +++++++++++++++++++ .../McpStudy.McpServerSSE.csproj | 6 ++++ McpStudy.McpServerSSE/Program.cs | 28 +++++++++++----- 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 McpStudy.McpServerSSE/Index.html diff --git a/McpStudy.McpServerSSE/Index.html b/McpStudy.McpServerSSE/Index.html new file mode 100644 index 0000000..d85c0e9 --- /dev/null +++ b/McpStudy.McpServerSSE/Index.html @@ -0,0 +1,33 @@ + + + + + + McpStudy.McpServerSSE + + +
+

McpStudy.McpServerSSE 启动成功!

+

WebAPI参阅:Swagger 文档

+

MCP服务测试:MCP服务页

+
+ + + \ No newline at end of file diff --git a/McpStudy.McpServerSSE/McpStudy.McpServerSSE.csproj b/McpStudy.McpServerSSE/McpStudy.McpServerSSE.csproj index 3efdcb9..933f213 100644 --- a/McpStudy.McpServerSSE/McpStudy.McpServerSSE.csproj +++ b/McpStudy.McpServerSSE/McpStudy.McpServerSSE.csproj @@ -16,4 +16,10 @@ + + + PreserveNewest + + + diff --git a/McpStudy.McpServerSSE/Program.cs b/McpStudy.McpServerSSE/Program.cs index 26828ff..ebef631 100644 --- a/McpStudy.McpServerSSE/Program.cs +++ b/McpStudy.McpServerSSE/Program.cs @@ -23,21 +23,33 @@ public class Program var app = builder.Build(); // Configure the HTTP request pipeline. - if (app.Environment.IsDevelopment()) - { - app.MapOpenApi(); + app.MapOpenApi(); - app.UseSwaggerUI(options => - { - options.SwaggerEndpoint("/openapi/v1.json", "v1"); - }); - } + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/openapi/v1.json", "v1"); + }); app.UseAuthorization(); app.MapControllers(); + //ַ(֧վ):Զм+ض + //ֻм·(app.Map): / "" ȱapp.MapMcp + app.Use(async (context, next) => + { + if (context.Request.Path == "/" || context.Request.Path == "") + { + context.Response.ContentType = "text/html"; + await context.Response.SendFileAsync(Path.Combine(app.Environment.ContentRootPath, "index.html")); + } + else + { + await next(); + } + }); + app.MapMcp(); app.Run();