ASP.NET CORE Web MCP Server -Handelssitzungen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: ASP.NET CORE Web MCP Server -Handelssitzungen

by Anonymous » 18 Aug 2025, 22:04

Ich versuche, einen MCP -Server mit SSE -Kommunikation zu erstellen, es ist erfolgreich und ich kann eine Verbindung zum Server herstellen.

Code: Select all

ModelContextProtocol --prerelease
Microsoft.Extensions.Hosting
< /code>
Tool.cs
:

Code: Select all

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
:

Code: Select all

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
Methode von Postman (URL: http: // localhost: 5000/sse ) generiert eine Sitzungs -ID wie/message? SessionID = B7ty0L9X9QAXIS96S7NOPKQ (für die nächsten nachfolgenden Anfragen). B7ty0L9X9QAXIS96S7NOPKQ In meiner Datenbank, wenn der Client zum ersten Mal erfolgreich eine Verbindung zum Server herstellt?

Top