Skip to main content
The ConfigPlugin provides typed environment variable access for your FrontMCP servers. It automatically loads .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 precedence

Schema Validation

Optional Zod schema validation for fail-fast configuration errors

DI Integration

Access via this.config in tools, resources, prompts, and other contexts

Quick 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 via this.config in any execution context:

get(key, defaultValue?)

Get a configuration value with optional default:

getRequired(key)

Get a required configuration value. Throws ConfigMissingError 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:
When schema validation is enabled, missing or invalid values will throw ConfigValidationError during server startup, preventing the server from running with invalid configuration.

File Loading Behavior

Precedence Rules

  1. Base file (.env) is loaded first
  2. Local file (.env.local) overrides base values
  3. Existing process.env values are not overwritten

Supported Syntax

Add .env.local to your .gitignore file to keep local secrets out of version control.

CLI Integration

The frontmcp 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 when getRequired() is called for a missing key:

ConfigValidationError

Thrown when schema validation fails:

Complete Example


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