diff --git a/.vscode/mcp.example.json b/.vscode/mcp.example.json index 1150b83..3017317 100644 --- a/.vscode/mcp.example.json +++ b/.vscode/mcp.example.json @@ -10,7 +10,8 @@ ], "env": { "USERNAME": "mail@address.com", - "PASSWORD": "sup3rsecur3" + "PASSWORD": "sup3rsecur3", + "REQUEST_THROTTLE_MS": "500" } } } diff --git a/FsMcp/FoodsharingApiClient.cs b/FsMcp/FoodsharingApiClient.cs index 046296a..f7ab059 100644 --- a/FsMcp/FoodsharingApiClient.cs +++ b/FsMcp/FoodsharingApiClient.cs @@ -4,9 +4,23 @@ namespace FsMcp; internal sealed class FoodsharingApiClient { + private const string RequestThrottleMsEnvVar = "REQUEST_THROTTLE_MS"; + private readonly SemaphoreSlim _loginLock = new(1, 1); - public HttpClient HttpClient { get; } = new(new RequestThrottleHandler(TimeSpan.FromMilliseconds(200))); + public HttpClient HttpClient { get; } = new(new RequestThrottleHandler(TimeSpan.FromMilliseconds(GetRequestThrottleMs()))); + + private static int GetRequestThrottleMs() + { + string? configuredValue = Environment.GetEnvironmentVariable(RequestThrottleMsEnvVar); + + if (int.TryParse(configuredValue, out int throttleMs) && throttleMs >= 0) + { + return throttleMs; + } + + return 500; + } public async Task EnsureLoginAsync() {