81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using System.ComponentModel;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json.Serialization;
|
|
using FsMcp;
|
|
using ModelContextProtocol.Server;
|
|
|
|
namespace FsMcp.Tools;
|
|
|
|
internal sealed class RegionUsersTools
|
|
{
|
|
private readonly FoodsharingApiClient _apiClient;
|
|
|
|
public RegionUsersTools(FoodsharingApiClient apiClient)
|
|
{
|
|
_apiClient = apiClient;
|
|
}
|
|
|
|
[McpServerTool]
|
|
[Description("Returns a list of all members for a region. Useful for discovering users within a specific foodsharing region.")]
|
|
public async Task<IReadOnlyList<UnitMemberListItem>> GetRegionUsersAsync(
|
|
[Description("Region ID as positive integer (OpenAPI path pattern: [1-9][0-9]*).")]
|
|
int regionId)
|
|
{
|
|
if (regionId <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(regionId), "regionId must be a positive integer.");
|
|
}
|
|
|
|
await _apiClient.EnsureLoginAsync();
|
|
|
|
var users = await _apiClient.HttpClient.GetFromJsonAsync<IReadOnlyList<UnitMemberListItem>>(Endpoints.RegionUsers(regionId));
|
|
return users ?? [];
|
|
}
|
|
}
|
|
|
|
public sealed record UnitMemberListItem
|
|
{
|
|
[Description("Unique user ID of the member.")]
|
|
[JsonPropertyName("id")]
|
|
public int Id { get; init; }
|
|
|
|
[Description("Display name of the member.")]
|
|
[JsonPropertyName("name")]
|
|
public string Name { get; init; } = string.Empty;
|
|
|
|
[Description("Relative API path of the member avatar image.")]
|
|
[JsonPropertyName("avatar")]
|
|
public string? Avatar { get; init; }
|
|
|
|
[Description("Whether the user is currently using the sleeping hat function.")]
|
|
[JsonPropertyName("isSleeping")]
|
|
public bool? IsSleeping { get; init; }
|
|
|
|
[Description("Whether the user is an admin or ambassador of the region.")]
|
|
[JsonPropertyName("isAdminOrAmbassadorOfRegion")]
|
|
public bool IsAdminOrAmbassadorOfRegion { get; init; }
|
|
|
|
[Description("Last name of the member (if available or returned by the API).")]
|
|
[JsonPropertyName("lastName")]
|
|
public string? LastName { get; init; }
|
|
|
|
[Description("Whether the region is the user's home region (if available).")]
|
|
[JsonPropertyName("isHomeRegion")]
|
|
public bool? IsHomeRegion { get; init; }
|
|
|
|
[Description("Last activity timestamp of the user (if available).")]
|
|
[JsonPropertyName("lastActivity")]
|
|
public DateTimeOffset? LastActivity { get; init; }
|
|
|
|
[Description("Numeric role enum from OpenAPI Role: 0, 1, 2, 3, 4, 5.")]
|
|
[JsonPropertyName("role")]
|
|
public int? Role { get; init; }
|
|
|
|
[Description("Date and time of the last generated pass, format: YYYY-MM-DD HH:mm:ss.")]
|
|
[JsonPropertyName("lastPassDate")]
|
|
public string? LastPassDate { get; init; }
|
|
|
|
[Description("Whether the member account is verified.")]
|
|
[JsonPropertyName("isVerified")]
|
|
public bool? IsVerified { get; init; }
|
|
} |