AspNetCoreMcpServer 能加到 dify 中
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
|
||||
<PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.ComponentModel;
|
||||
using ConsoleEchoMcpServer.Tools;
|
||||
|
||||
var builder = Host.CreateEmptyApplicationBuilder(settings: null);
|
||||
builder.Services
|
||||
.AddMcpServer()
|
||||
.WithStdioServerTransport()
|
||||
.WithTools<EchoTool>();
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
14
ConsoleEchoMcpServer/Tools/EchoTool.cs
Normal file
14
ConsoleEchoMcpServer/Tools/EchoTool.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace ConsoleEchoMcpServer.Tools;
|
||||
|
||||
[McpServerToolType]
|
||||
public sealed class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"Hello from C#: {message}";
|
||||
|
||||
[McpServerTool, Description("Echoes in reverse the message sent.")]
|
||||
public static string ReverseEcho(string message) => string.Concat(message.Reverse());
|
||||
}
|
||||
Reference in New Issue
Block a user