Per Session Tools Sample (#724)

This commit is contained in:
Peder Holdgaard Pedersen 2025-09-08 16:34:09 +02:00 • committed by GitHub
commit 0f0aad020b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,23 @@
using ModelContextProtocol.Server;
using System.ComponentModel;
namespace AspNetCoreMcpPerSessionTools.Tools;
/// <summary>
/// User information tools
/// </summary>
[McpServerToolType]
public sealed class UserInfoTool
{
[McpServerTool, Description("Gets information about the current user in the MCP session.")]
public static string GetUserInfo()
{
// Dummy user information for demonstration purposes
return $"User Information:\n" +
$"- User ID: {Guid.NewGuid():N}[..8] (simulated)\n" +
$"- Username: User{new Random().Next(1, 1000)}\n" +
$"- Roles: User, Guest\n" +
$"- Last Login: {DateTime.Now.AddMinutes(-new Random().Next(1, 60)):HH:mm:ss}\n" +
$"- Account Status: Active";
}
}