Код: Выделить всё
ModelContextProtocol --prerelease
Microsoft.Extensions.Hosting
< /code>
Tool.csКод: Выделить всё
using Microsoft.Extensions.AI;
using ModelContextProtocol;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Text.Json;
namespace Tools;
[McpServerToolType]
public sealed class GreetingTools
{
public GreetingTools()
{
}
[McpServerTool, Description("Says Hello to a user")]
public static string Echo(string username)
{
return "Hello " + username;
}
}
< /code>
Program.csКод: Выделить всё
using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
// Register MCP server and discover tools from the current assembly
builder.Services.AddMcpServer().WithHttpTransport().WithToolsFromAssembly();
var app = builder.Build();
// Add MCP middleware
app.MapMcp();
app.Run();
< /code>
I can successfully run this MCP server code and when client call url with GETПодробнее здесь: https://stackoverflow.com/questions/797 ... e-sessions
Мобильная версия