From c3e2d76286ef24d6fdac73ba520f533b2969c684 Mon Sep 17 00:00:00 2001 From: Gurram Srujan Date: Thu, 11 Dec 2025 15:12:49 +0530 Subject: [PATCH] Add coercion for converting string to number in config --- .changeset/huge-ducks-draw.md | 5 +++++ README.md | 6 +++++- src/config.ts | 10 +++++----- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 .changeset/huge-ducks-draw.md diff --git a/.changeset/huge-ducks-draw.md b/.changeset/huge-ducks-draw.md new file mode 100644 index 0000000..9f3c0f1 --- /dev/null +++ b/.changeset/huge-ducks-draw.md @@ -0,0 +1,5 @@ +--- +"@iqai/mcp-discord": patch +--- + +Adds coerce to convert string to number for env vars diff --git a/README.md b/README.md index 3643c43..a12f4fa 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ All configuration is now handled via the `src/config.ts` file, which supports bo | `DEFAULT_RATE_LIMIT_SECONDS` | number | `2` | Rate limit (seconds) for sampling requests per user. | | `DEFAULT_MESSAGE_CHUNK_SIZE` | number | `2000` | Max message chunk size for sampling responses. | | `RESPOND_TO_MENTIONS_ONLY` | boolean | `true` | Only respond to messages that mention the bot. | +| `SAMPLING_DEFAULT_TIMEOUT` | number | — | Timeout (milliseconds) for sampling requests. | +| `SAMPLING_REACTION_TIMEOUT` | number | — | Timeout (milliseconds) for sending reactions to Discord. | | `BLOCK_DMS` | boolean | `true` | Block direct messages to the bot. | | `BLOCKED_GUILDS` | string | `""` | Comma-separated list of guild IDs to block. | | `BANNED_USERS` | string | `""` | Comma-separated list of user IDs to ban. | @@ -126,6 +128,8 @@ HTTP_PORT=3000 DEFAULT_RATE_LIMIT_SECONDS=5 DEFAULT_MESSAGE_CHUNK_SIZE=1500 RESPOND_TO_MENTIONS_ONLY=true +SAMPLING_DEFAULT_TIMEOUT=5000 +SAMPLING_REACTION_TIMEOUT=3000 BLOCK_DMS=true BLOCKED_GUILDS="123456789,987654321" BANNED_USERS="111111111,222222222" @@ -137,7 +141,7 @@ REACTION_FALLBACK_EMOJI="👍" **Command-line arguments:** ```bash -node build/index.js --config "your_discord_bot_token" --sampling --transport http --port 3000 --rate-limit 5 --message-chunk-size 1500 --mentions-only --block-dms --blocked-guilds "123,456" --banned-users "111,222" --reaction-timeout 3000 --enable-reaction-sampling --reaction-fallback-emoji "👍" +node build/index.js --config "your_discord_bot_token" --sampling --transport http --port 3000 --rate-limit 5 --message-chunk-size 1500 --mentions-only --sampling-default-timeout 5000 --sampling-reaction-timeout 3000 --block-dms --blocked-guilds "123,456" --banned-users "111,222" --reaction-timeout 3000 --enable-reaction-sampling --reaction-fallback-emoji "👍" ``` If both are provided, command-line arguments take precedence. diff --git a/src/config.ts b/src/config.ts index 1e763d1..e5d4e96 100644 --- a/src/config.ts +++ b/src/config.ts @@ -17,12 +17,12 @@ const envSchema = z.object({ .string() .optional() .transform((val) => (val ? Number.parseInt(val, 10) : 8080)), - DEFAULT_RATE_LIMIT_SECONDS: z + DEFAULT_RATE_LIMIT_SECONDS: z.coerce .number() .optional() .default(2) .describe('used in sampling, when sampling is enabled'), - DEFAULT_MESSAGE_CHUNK_SIZE: z + DEFAULT_MESSAGE_CHUNK_SIZE: z.coerce .number() .optional() .default(2000) @@ -32,11 +32,11 @@ const envSchema = z.object({ .optional() .default(true) .describe('Only respond to messages that mention the bot'), - SAMPLING_DEFAULT_TIMEOUT: z + SAMPLING_DEFAULT_TIMEOUT: z.coerce .number() .optional() .describe('A timeout (in milliseconds) for this request'), - SAMPLING_REACTION_TIMEOUT: z + SAMPLING_REACTION_TIMEOUT: z.coerce .number() .optional() .describe('A timeout for sending reactions to discord'), @@ -55,7 +55,7 @@ const envSchema = z.object({ .optional() .default('') .describe('Comma-separated list of user IDs to ban'), - REACTION_TIMEOUT_MS: z + REACTION_TIMEOUT_MS: z.coerce .number() .optional() .default(3000)