Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuration Reference

This page is the reference for every gateway setting. The binary parses its configuration with clap, so each option has both a CLI flag and an environment variable, and both feed the same Config struct. When a setting is supplied as a flag and an environment variable at the same time, the command-line flag wins.

For the always-current list, ask the binary directly:

cargo run -p contextforge-gateway-rs --bin contextforge-gateway-rs -- --help

The sections below group the options by concern: listeners, JWT, Redis, upstream transport, runtime, telemetry, and logging.

Minimum Useful Configuration

At startup, the CLI requires Redis location and Redis connection mode:

--redis-address
--redis-port
--redis-mode

To serve useful traffic, the process also needs:

NeedTypical flag
At least one downstream listener--address 127.0.0.1:8001 or --tls-address 0.0.0.0:8443
JWT verification material--token-verification-public-key or --token-verification-secret
A compatible upstream client mode--upstream-connection-mode plain-text-or-tls for local HTTP backends
Runtime user config in RedisWritten by the control plane or by local bootstrap helpers

If no token verification key or secret is configured, authenticated MCP requests cannot pass the claims layer.

Listener Options

FlagEnv varRequiredMeaning
--address <host:port>CONTEXTFORGE_GATEWAY_RS_ADDRESSNoPlain HTTP listener. Omit it when serving only TLS.
--tls-address <host:port>CONTEXTFORGE_GATEWAY_RS_TLS_ADDRESSNoTLS listener address. Requires certificate and private key.
--server-certificate <path>CONTEXTFORGE_GATEWAY_RS_TLS_SERVER_CERTIFICATEWith --tls-addressPEM certificate chain for downstream TLS.
--server-private-key <path>CONTEXTFORGE_GATEWAY_RS_TLS_SERVER_PRIVATE_KEYWith --tls-addressPEM private key for downstream TLS.

--address and --tls-address may both be configured, but they must not use the same socket address.

JWT Options

FlagEnv varRequiredMeaning
--token-verification-public-key <path>CONTEXTFORGE_GATEWAY_RS_TOKEN_VERIFICATION_PUBLIC_KEYFor RSA tokensRSA public key used for RS256, RS384, or RS512 tokens.
--token-verification-secret <secret>CONTEXTFORGE_GATEWAY_RS_TOKEN_SECRETFor HMAC tokensShared secret used for HS256, HS384, or HS512 tokens.
--token-verification-private-key <path>CONTEXTFORGE_GATEWAY_RS_TOKEN_VERIFICATION_PRIVATE_KEYLocal tools onlyRSA private key used by the optional local token helper. Present only when contextforge-gateway-rs-lib/with_tools is enabled.

The claims layer validates issuer, audience, and expiration:

ClaimExpected value
issmcpgateway
audmcpgateway-api
expPresent and not expired

The JWT sub claim selects the Redis user config key. The path virtual host id then selects one virtual host inside that config.

Redis Options

FlagEnv varRequiredMeaning
--redis-address <host>CONTEXTFORGE_GATEWAY_RS_REDIS_HOSTNAMEYesRedis host name or IP.
--redis-port <port>CONTEXTFORGE_GATEWAY_RS_REDIS_PORTYesRedis port.
--redis-mode <mode>CONTEXTFORGE_GATEWAY_RS_REDIS_CONNECTION_MODEYesRedis connection mode: plain-text, tls, or mtls.
--redis-tls-trust-bundle <path>CONTEXTFORGE_GATEWAY_RS_REDIS_TLS_REDIS_TRUST_BUNDLETLS and mTLSPEM trust bundle for Redis TLS.
--redis-tls-client-certificate <path>CONTEXTFORGE_GATEWAY_RS_REDIS_TLS_REDIS_CLIENT_CERTIFICATEmTLSPEM client certificate for Redis mTLS.
--redis-tls-client-private-key <path>CONTEXTFORGE_GATEWAY_RS_REDIS_TLS_REDIS_CLIENT_PRIVATE_KEYmTLSPEM client private key for Redis mTLS.
--user-config-cache-expiry-seconds <n>CONTEXTFORGE_GATEWAY_RS_USER_CONFIG_CACHE_EXPIRY_SECONDSNo, default 60Expiry for the in-process user config cache in front of Redis. 0 disables caching and reads Redis on every request.

Local Compose exposes plain Redis on 127.0.0.1:6379, so local runs normally use:

--redis-address 127.0.0.1 \
--redis-port 6379 \
--redis-mode plain-text

Runtime config values are MessagePack encoded. Redis is the current transport for config, not the routing model itself.

Upstream MCP Transport Options

FlagEnv varRequiredMeaning
--upstream-connection-mode <mode>CONTEXTFORGE_GATEWAY_RS_UPSTREAM_CONNECTION_MODENoControls whether backend MCP URLs may be HTTP, HTTPS, or mTLS.
--upstream-trust-bundle <path>CONTEXTFORGE_GATEWAY_RS_TLS_UPSTREAM_TRUST_BUNDLENoAdditional PEM trust bundle for HTTPS upstreams.
--upstream-certificate <path>CONTEXTFORGE_GATEWAY_RS_TLS_UPSTREAM_CERTIFICATEmTLS modesPEM client certificate for upstream mTLS.
--upstream-private-key <path>CONTEXTFORGE_GATEWAY_RS_TLS_UPSTREAM_PRIVATE_KEYmTLS modesPEM client private key for upstream mTLS.

Connection modes:

ModeBehavior
omitted or tls-onlyHTTPS upstreams only. This is the safe default.
plain-text-or-tlsAllows HTTP and HTTPS upstream URLs. Use this for the local Compose backends.
plain-text-or-m-tlsAllows HTTP and HTTPS with client identity configured.
mtls-onlyRequires HTTPS and uses the configured client certificate and key.

If an upstream backend URL is http://... and the mode is omitted, calls fail before reaching that backend because the reqwest client is HTTPS-only.

Runtime Options

FlagEnv varDefaultMeaning
--number-of-cpus <n>CONTEXTFORGE_GATEWAY_RS_GATEWAY_CPUSHost CPU countWorker thread count for the Tokio runtime shape.
--single-runtime <bool>CONTEXTFORGE_GATEWAY_RS_SINGLE_RUNTIMEtruetrue uses one multi-thread runtime. false starts multiple current-thread runtimes.
--runtime-plugins-enabled <bool>CONTEXTFORGE_GATEWAY_RS_RUNTIME_PLUGINS_ENABLEDfalseEnables CPEX runtime plugin execution and Redis plugin config loading.

When runtime plugins are enabled, plugin config is read from Redis key ContextForgeGatewayRuntimePluginConfig. That key is a control-plane trust boundary because it decides which registered hooks run.

Telemetry Options

FlagEnv varDefaultMeaning
--enable-open-telemetry <bool>CONTEXTFORGE_GATEWAY_RS_ENABLE_OPEN_TELEMETRYfalseEnables trace export.
--enable-otel-metrics <bool>CONTEXTFORGE_GATEWAY_RS_ENABLE_OTEL_METRICSfalseEnables HTTP server metric export.
--otlp-protocol <protocol>CONTEXTFORGE_GATEWAY_RS_OTEL_EXPORTER_OTLP_PROTOCOLgrpcgrpc or http-protobuf.
--otlp-endpoint <uri>CONTEXTFORGE_GATEWAY_RS_OTEL_EXPORTER_OTLP_ENDPOINTProtocol-specificTrace export endpoint.
--otlp-metrics-endpoint <uri>CONTEXTFORGE_GATEWAY_RS_OTEL_EXPORTER_OTLP_METRICS_ENDPOINTProtocol-specificMetrics export endpoint.
--otlp-headers <headers>CONTEXTFORGE_GATEWAY_RS_OTEL_EXPORTER_OTLP_HEADERSnoneComma-separated key=value headers for OTLP export.
--otlp-service-name <name>CONTEXTFORGE_GATEWAY_RS_OTEL_SERVICE_NAMECONTEXTFORGE-GATEWAY-RSOpenTelemetry service.name.

Default endpoints:

ProtocolTracesMetrics
grpchttp://127.0.0.1:4317http://127.0.0.1:4317
http-protobufhttp://127.0.0.1:4318/v1/traceshttp://127.0.0.1:4318/v1/metrics

RUST_TRACE_LOG controls which spans reach the OTLP trace layer. The HTTP trace layer emits debug-level spans, so local trace verification usually needs:

RUST_TRACE_LOG=debug

Logging Options

Flag or env varDefaultMeaning
--log-name / CONTEXTFORGE_GATEWAY_LOG_NAMEcontextforge-gateway-rs.logFile log name in the current working directory.
--log-rotation / CONTEXTFORGE_GATEWAY_LOG_ROTATIONhourlyRotation mode: minutely, hourly, daily, or never.
RUST_LOGdebugConsole event filter.
RUST_FILE_LOGdebugFile event filter.
RUST_TRACE_LOGinfoOpenTelemetry span filter.

Common Flag Sets

Local HTTP Gateway And Plain Redis

--address 127.0.0.1:8001 \
--redis-address 127.0.0.1 \
--redis-port 6379 \
--redis-mode plain-text \
--token-verification-public-key assets/jwt.key.pub \
--upstream-connection-mode plain-text-or-tls

Downstream TLS Listener

--tls-address 0.0.0.0:8443 \
--server-certificate assets/contextforgeCA/contextforge-server.cert.pem \
--server-private-key assets/contextforgeCA/contextforge-server.key.pem

You may combine this with --address to expose both HTTP and HTTPS listeners.

HMAC Token Verification

--token-verification-secret "${CONTEXTFORGE_GATEWAY_RS_TOKEN_SECRET}"

Use this only when downstream JWTs are signed with an HS* algorithm. RSA tokens need --token-verification-public-key.

Redis TLS

--redis-address 127.0.0.1 \
--redis-port 16379 \
--redis-mode tls \
--redis-tls-trust-bundle assets/contextforgeCA/contextforge.intermediate.ca-chain.cert.pem

Upstream mTLS

--upstream-connection-mode mtls-only \
--upstream-trust-bundle assets/contextforgeCA/contextforge.intermediate.ca-chain.cert.pem \
--upstream-certificate assets/contextforgeCA/contextforge-client.cert.pem \
--upstream-private-key assets/contextforgeCA/contextforge-client.key.pem

The certificate and key paths must point to PEM files accepted by reqwest.

Startup Validation

The gateway fails fast for these invalid combinations:

Invalid combinationReason
--tls-address without server cert or keyDownstream TLS cannot be configured partially.
Same socket for --address and --tls-addressThe process cannot bind both listeners to the same address.
--redis-mode tls without trust bundleRedis TLS needs a root certificate bundle.
--redis-mode mtls without trust bundle, client cert, or client keyRedis mTLS needs all three pieces.
mTLS upstream mode without upstream cert and keyThe reqwest identity cannot be built.
Plain HTTP backend with default upstream modeDefault upstream mode is HTTPS-only.