From 71e2c8df92b1f3886ca35e9d99a1a3f84570f6fe Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Wed, 4 Mar 2026 11:43:08 +0100 Subject: [PATCH] Implement dynamic request throttle configuration; update HttpClient initialization --- .vscode/mcp.example.json | 3 ++- FsMcp/FoodsharingApiClient.cs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) 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() {