Files
FsMcp/FsMcp/Tools/UserStoresTools.cs

59 lines
2.0 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 UserStoresTools
{
private readonly FoodsharingApiClient _apiClient;
public UserStoresTools(FoodsharingApiClient apiClient)
{
_apiClient = apiClient;
}
[McpServerTool]
[Description("Returns the stores where a user is a member of from GET /api/users/{userId}/stores. Typically used with userId='current' to get the current user's stores.")]
public async Task<IReadOnlyList<StoreTeamMembershipWithPickupStatus>> GetUserStoresAsync(
[Description("User ID as positive integer or 'current'. Defaults to 'current'.")]
string userId = "current",
[Description("Whether to exclude inactive stores.")]
bool? excludeInactive = null)
{
await _apiClient.EnsureLoginAsync();
var stores = await _apiClient.HttpClient.GetFromJsonAsync<IReadOnlyList<StoreTeamMembershipWithPickupStatus>>(Endpoints.UserStores(userId, excludeInactive));
return stores ?? [];
}
}
public sealed record StoreTeamMembershipWithPickupStatus
{
[Description("Unique identifier of the store.")]
[JsonPropertyName("id")]
public int Id { get; init; }
[Description("Name of the store.")]
[JsonPropertyName("name")]
public string Name { get; init; } = string.Empty;
[Description("Whether the user is a manager of this store.")]
[JsonPropertyName("isManaging")]
public bool IsManaging { get; init; }
[Description("Membership status of the user in the store team.")]
[JsonPropertyName("membershipStatus")]
public int MembershipStatus { get; init; }
[Description("Category type of the store.")]
[JsonPropertyName("categoryType")]
public int CategoryType { get; init; }
[Description("Pickup status for the user in this store. Can be null.")]
[JsonPropertyName("pickupStatus")]
public int? PickupStatus { get; init; }
}