Developer GuideConfiguration

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.

Redacted startup diagnostics with getRedactedEnvSummary()typescript
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.

Example MCP environment block (placeholder values only)bash
# 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>
Generate fresh 256-bit hex secrets locallybash
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 GroupValidation Rule in env.tsFallback / Default
MCP_PORTInteger between 1 and 655354130
MCP_HOSTNon-empty bind host string127.0.0.1
MCP_ISSUER_URLValid http:// or https:// URL (trailing slash stripped)https://mcp.taicket.xyz
MCP_RESOURCE_URLValid http:// or https:// URL (trailing slash stripped)${MCP_ISSUER_URL}/mcp
MCP_DISCORD_REDIRECT_URIValid http:// or https:// URL${MCP_ISSUER_URL}/oauth/discord/callback
MCP_MONGODB_URI / MONGODB_URIMust start with mongodb:// or mongodb+srv://Required (no default)
MCP_TOKEN_ENCRYPTION_KEY / MCP_SESSION_SECRET / MCP_AUDIT_SIGNING_KEYMinimum 32 charactersRequired (no default)
DISCORD_CLIENT_IDMatches /^\d{17,22}$/; falls back to NEXT_PUBLIC_DISCORD_CLIENT_IDRequired
DISCORD_BOT_TOKENNon-empty string; falls back to DISCORD_TOKENRequired
9 Dedicated Module DB URIsEmpty string or valid mongodb:// / mongodb+srv:// URIDB names default to taicket_<module>

Related documentation