Files
xAiMcpServer/Tools/XUserTools.cs
T

48 lines
1.2 KiB
C#

using xIdentityHelper;
using xModels.Extensions;
using xCommons.Extensions;
using xAiModels.Attributes;
using xAiService.Interfaces;
using System.Threading.Tasks;
using xIdentityService.Interfaces;
namespace xAiMcpServer.Tools
{
[XAiMcpToolType]
public class XUserTools
{
//
private readonly IXPersonService personService;
private readonly IXAiMcpUserContext userContext;
public XUserTools(
IXAiMcpUserContext userContext,
IXPersonService personService
)
{
//
this.userContext = userContext;
this.personService = personService;
}
[XAiMcpTool(
RequiresAuthentication = true,
RequiredPolicy = XPolicies.EnabledUser,
Description = "Get information about the currently logged-in user.")]
public async Task<string> WhoAmI()
{
//
var user = userContext.UserInfo;
if (user.IsNullOrDefault())
{
return "Anonymous";
}
//
var person = await personService.GetPerson(user.UserId);
//
return person?.GetFullname() ?? user.UserId;
}
}
}