.env and .env.local files, and exposes configuration via this.config in all execution contexts.
Built-in Feature
ConfigPlugin is built into the SDK - no separate installation required. Just import and use:Why Use ConfigPlugin?
Typed Access
Type-safe environment variable access with
getRequired(), getNumber(), getBoolean()Auto-Loading
Automatically loads
.env and .env.local files with proper precedenceSchema Validation
Optional Zod schema validation for fail-fast configuration errors
DI Integration
Access via
this.config in tools, resources, prompts, and other contextsQuick Start
1. Create your .env files
2. Add ConfigPlugin to your server
3. Use this.config in your tools
Configuration Options
Configure the plugin when initializing:string
Base directory for resolving relative
.env paths. Required for file loading.string
default:"'.env'"
Path to the base environment file, relative to
basePath.string
default:"'.env.local'"
Path to the local override file, relative to
basePath. Values in this file override the base file.boolean
default:"true"
Whether to load
.env files. Set to false if you only want to read from process.env.boolean
default:"true"
Whether to set loaded values into
process.env. Does not override existing values.z.ZodType
Optional Zod schema to validate the configuration. Throws
ConfigValidationError if validation fails.ConfigService API
Access configuration values viathis.config in any execution context:
get(key, defaultValue?)
Get a configuration value with optional default:getRequired(key)
Get a required configuration value. ThrowsConfigMissingError if not found:
has(key)
Check if a configuration key exists:getAll()
Get all configuration values as a record:getNumber(key, defaultValue?)
Parse a configuration value as a number:getBoolean(key, defaultValue?)
Parse a configuration value as a boolean:Schema Validation
Define a Zod schema to validate your configuration at startup:File Loading Behavior
Precedence Rules
- Base file (
.env) is loaded first - Local file (
.env.local) overrides base values - Existing
process.envvalues are not overwritten
Supported Syntax
CLI Integration
Thefrontmcp dev command automatically loads .env files before starting your server:
The CLI loads environment files before spawning your server process, so
process.env values are available immediately.Error Handling
ConfigMissingError
Thrown whengetRequired() is called for a missing key:
ConfigValidationError
Thrown when schema validation fails:Complete Example
Links & Resources
Source Code
View the ConfigPlugin source code
Providers Guide
Learn about dependency injection and providers
Plugins Overview
Learn about the FrontMCP plugin system
Demo Application
See ConfigPlugin in action with real examples