init: 初始化.NET 9 项目!

main
bicijinlian 3 weeks ago
parent 1864a9acaa
commit a6f6728ac8

@ -0,0 +1,21 @@
using System;
using System.ComponentModel;
using ModelContextProtocol.Server;
namespace McpStudy.Core
{
[McpServerToolType]
public static class EchoTool
{
[McpServerTool, DisplayName("EchoServer"), Description("回传原消息给客户端!")]
public static string Echo(string message)
{
Console.WriteLine($"Echo: {message}");
System.IO.File.AppendAllText("Mcplog.txt", $"Echo: {message}\n");
return $"hello {message}";
}
}
}

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.6" />
<PackageReference Include="ModelContextProtocol" Version="0.3.0-preview.1" />
<PackageReference Include="ModelContextProtocol-SemanticKernel" Version="0.3.0-preview-01" />
<PackageReference Include="ModelContextProtocolServer.Sse" Version="0.3.0-preview-01" />
<PackageReference Include="ModelContextProtocolServer.Stdio" Version="0.3.0-preview-01" />
</ItemGroup>
</Project>

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\McpStudy.Core\McpStudy.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,10 @@
namespace McpStudy.McpClient
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("调用MCP服务器示例");
}
}
}

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace McpStudy.McpServerSSE.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\McpStudy.Core\McpStudy.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,6 @@
@McpStudy.McpServerSSE_HostAddress = http://localhost:5027
GET {{McpStudy.McpServerSSE_HostAddress}}/weatherforecast/
Accept: application/json
###

@ -0,0 +1,32 @@
namespace McpStudy.McpServerSSE
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}

@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5027",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,13 @@
namespace McpStudy.McpServerSSE
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\McpStudy.Core\McpStudy.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,55 @@
using System;
using System.ComponentModel;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol.Server;
namespace McpStudy.McpServerStdIO
{
internal class Program
{
static async Task Main(string[] args)
{
try
{
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(options =>
{
options.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
await builder.Build().RunAsync();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
}
}
}
}
[McpServerToolType]
public static class TimeTool
{
[McpServerTool, Description("Get the current time for a city")]
public static string GetCurrentTime(string city)
{
var message = $"It is {DateTime.Now.Hour}:{DateTime.Now.Minute} in {city}.";
File.AppendAllText("Mcplog.txt", $"{message}{System.Environment.NewLine}");
return message;
}
}

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\McpStudy.Core\McpStudy.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>

@ -0,0 +1,11 @@
namespace McpStudy.UnitTest
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36221.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "McpStudy.Core", "McpStudy.Core\McpStudy.Core.csproj", "{431D5D01-A1CE-46AD-862C-E03508B1EFA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "McpStudy.McpClient", "McpStudy.McpClient\McpStudy.McpClient.csproj", "{6A7B2283-2503-4024-A966-2DF0851F364B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "McpStudy.UnitTest", "McpStudy.UnitTest\McpStudy.UnitTest.csproj", "{09C2F3F1-B770-4DAC-81A1-0217AD09874F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "McpStudy.McpServerStdio", "McpStudy.McpServerStdio\McpStudy.McpServerStdio.csproj", "{7EDCB267-57AB-E836-D3EE-AA9ABAC8E373}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "McpStudy.McpServerSSE", "McpStudy.McpServerSSE\McpStudy.McpServerSSE.csproj", "{34A4291B-BA36-491B-914D-674CF3806314}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{431D5D01-A1CE-46AD-862C-E03508B1EFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{431D5D01-A1CE-46AD-862C-E03508B1EFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{431D5D01-A1CE-46AD-862C-E03508B1EFA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{431D5D01-A1CE-46AD-862C-E03508B1EFA5}.Release|Any CPU.Build.0 = Release|Any CPU
{6A7B2283-2503-4024-A966-2DF0851F364B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A7B2283-2503-4024-A966-2DF0851F364B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A7B2283-2503-4024-A966-2DF0851F364B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A7B2283-2503-4024-A966-2DF0851F364B}.Release|Any CPU.Build.0 = Release|Any CPU
{09C2F3F1-B770-4DAC-81A1-0217AD09874F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09C2F3F1-B770-4DAC-81A1-0217AD09874F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09C2F3F1-B770-4DAC-81A1-0217AD09874F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09C2F3F1-B770-4DAC-81A1-0217AD09874F}.Release|Any CPU.Build.0 = Release|Any CPU
{7EDCB267-57AB-E836-D3EE-AA9ABAC8E373}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EDCB267-57AB-E836-D3EE-AA9ABAC8E373}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EDCB267-57AB-E836-D3EE-AA9ABAC8E373}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EDCB267-57AB-E836-D3EE-AA9ABAC8E373}.Release|Any CPU.Build.0 = Release|Any CPU
{34A4291B-BA36-491B-914D-674CF3806314}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34A4291B-BA36-491B-914D-674CF3806314}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34A4291B-BA36-491B-914D-674CF3806314}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34A4291B-BA36-491B-914D-674CF3806314}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F66B4535-D87E-43A7-A8C9-91FFD8992330}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save