Environment Configuration
Centralized root .env configuration, strict Zod startup validation in mcp/src/config/env.ts, secret redaction, and safe key generation.
How mcp/src/config/env.ts loads and validates .env
Taicket stores shared service environment variables in the repository root .env file. When mcp/src/config/env.ts initializes, ensureDotenvLoaded() resolves candidate paths in deterministic order (../../../.env relative to the compiled module, ../.env relative to cwd, and .env in cwd) with override: false so explicit process environment variables always take precedence.
Every variable is normalized (whitespace stripped from MongoDB URIs, trailing slashes removed from issuer and resource URLs) and validated against rawEnvSchema using Zod. If any required key is missing or invalid, loadEnv() throws an error listing only key names and validation messages without ever printing secret values.
import { getEnv, getRedactedEnvSummary } from './config/env.js';
const config = getEnv();
const summary = getRedactedEnvSummary(config);
// Safe to log: contains booleans for secret presence, never raw secrets or URIs.
logger.info({ env: summary }, 'MCP environment validated');Core MCP and cryptographic keys
Never put real secrets in documentation or source code
All examples below use placeholder values. Production keys belong strictly in the server .env file and must never be copied into documentation, unit test fixtures, or client configs.
# Service binding & canonical OAuth 2.1 URLs
MCP_PORT=4130
MCP_HOST=127.0.0.1
MCP_ISSUER_URL=https://mcp.taicket.xyz
MCP_RESOURCE_URL=https://mcp.taicket.xyz/mcp
MCP_DISCORD_REDIRECT_URI=https://mcp.taicket.xyz/oauth/discord/callback
DASHBOARD_URL=https://taicket.xyz
# Dedicated physically isolated MCP database
MCP_MONGODB_URI=mongodb+srv://<user>:<password>@<cluster-host>/taicket_mcp?retryWrites=true&w=majority
MCP_DB_NAME=taicket_mcp
# Cryptographic keys (minimum 32 characters; use 64 hex chars / 256 bits in production)
MCP_TOKEN_ENCRYPTION_KEY=<generate-64-hex-chars>
MCP_SESSION_SECRET=<generate-64-hex-chars>
MCP_AUDIT_SIGNING_KEY=<generate-64-hex-chars>
# Discord OAuth2 & Bot credentials (shared with Taicket)
DISCORD_CLIENT_ID=<17-to-22-digit-snowflake>
DISCORD_CLIENT_SECRET=<discord-oauth-client-secret>
DISCORD_BOT_TOKEN=<discord-bot-token>node -e "console.log('MCP_TOKEN_ENCRYPTION_KEY=' + require('crypto').randomBytes(32).toString('hex'))"
node -e "console.log('MCP_SESSION_SECRET=' + require('crypto').randomBytes(32).toString('hex'))"
node -e "console.log('MCP_AUDIT_SIGNING_KEY=' + require('crypto').randomBytes(32).toString('hex'))"Key validation constraints enforced at boot
| Variable Group | Validation Rule in env.ts | Fallback / Default |
|---|---|---|
| MCP_PORT | Integer between 1 and 65535 | 4130 |
| MCP_HOST | Non-empty bind host string | 127.0.0.1 |
| MCP_ISSUER_URL | Valid http:// or https:// URL (trailing slash stripped) | https://mcp.taicket.xyz |
| MCP_RESOURCE_URL | Valid http:// or https:// URL (trailing slash stripped) | ${MCP_ISSUER_URL}/mcp |
| MCP_DISCORD_REDIRECT_URI | Valid http:// or https:// URL | ${MCP_ISSUER_URL}/oauth/discord/callback |
| MCP_MONGODB_URI / MONGODB_URI | Must start with mongodb:// or mongodb+srv:// | Required (no default) |
| MCP_TOKEN_ENCRYPTION_KEY / MCP_SESSION_SECRET / MCP_AUDIT_SIGNING_KEY | Minimum 32 characters | Required (no default) |
| DISCORD_CLIENT_ID | Matches /^\d{17,22}$/; falls back to NEXT_PUBLIC_DISCORD_CLIENT_ID | Required |
| DISCORD_BOT_TOKEN | Non-empty string; falls back to DISCORD_TOKEN | Required |
| 9 Dedicated Module DB URIs | Empty string or valid mongodb:// / mongodb+srv:// URI | DB names default to taicket_<module> |