48 lines
1.2 KiB
C#
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 = "when user asks anything about itself, use this to retrieve user information.")]
|
|
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;
|
|
}
|
|
}
|
|
} |