MultiConnectMultiConnectDocs Website home
MultiConnectCloud › Server Deployments

10. Environment variables the platform sets

The platform starts every container with these variables. MultiConnectSDK reads them for you. Without the SDK, read them yourself. Your own variables cannot start with MC_.

The same table is on the form under Environment reference.

Every container

Name Value
PORT The port your process must listen on inside the container. Bind anything else and the container fails its health check and is replaced
MC_DEPLOYMENT_ID Your deployment's id, as used by the API and webhooks
MC_DEPLOYMENT_NAME The deployment's name. For logs only; it can be renamed
MC_CONTAINER_ID This container's id, stable for its whole life. Webhooks and the lookup call it containerId, and the instance API calls it instanceId
MC_REGION The region this container runs in
MC_ROLE CombinedServer, MasterServer or WorkerServer. One build can serve both roles by checking this
MC_BUILD_VERSION The build version this container runs. Log it: during a redeploy two versions run at once
MC_MODE CombinedServer or MasterWorker
MC_TRANSPORT Tcp, Udp, or both. Bind only what is published: a UDP-only deployment has no TCP port
MC_ENABLE_WEBSOCKET true when each container has a wss:// address
MC_GRACE_PERIOD_MINUTES The grace period: roughly how long you have to move players off after generation.retiring
MC_PUBLIC_HOST The public address clients use to reach this container
MC_PUBLIC_PORT The public port clients connect to. Read this one when telling anyone where you are
MC_PUBLIC_WSS_URL This container's wss:// address. Only when WebSocket is on

Workers only

Name Value
MC_MASTER_HOST The public address of the master this worker reports to, set by the worker region's Reports to. It is reached over the internet
MC_MASTER_PORT The master's public port
MC_MASTER_REGION The master's region. Every worker in a region reports to the same master
MC_MASTER_WSS_URL The master's wss:// address. Only when WebSocket is on

Masters only

Name Value
MC_TOPOLOGY_URL The lookup that lists this deployment's workers, for catching up after a restart. It needs one of your access keys, which you supply as your own environment variable
MC_MASTER_TOKEN Lets this master list its workers and manage its on-demand game servers with no access key. Send it as the X-MC-Master-Token header with MC_CONTAINER_ID as X-MC-Container. It works only for this deployment and ends with this container. It is a secret: never log it or send it to a client
MC_WORKER_SCALING Managed (Always ready) or OnDemand
MC_MAX_INSTANCES On-demand deployments: the most game servers that may run at once

On-demand game servers only

Name Value
MC_ON_DEMAND Always 1. This server should exit when its match ends
MC_INSTANCE_TAG The tag your master gave when it started this server, such as its match id
MC_INSTANCE_EXPIRES_AT When the platform removes this server if it is still running (ISO 8601 UTC). A match that would run past it should not start

Variables your master passed when it started the server arrive too, under the names it chose.

When an SDK App is linked

Name Value
MC_SDK_KEY The linked app's SDK key. Written when a container starts, so redeploy after linking or regenerating the key
MC_SDK_REPORT_TOKEN Marks this server's analytics as coming from MultiConnectCloud. MultiConnectSDK sends it by itself

Script 10.1: Read your own address and role in C#

var port       = int.Parse(Environment.GetEnvironmentVariable("PORT") ?? "7777");
var publicHost = Environment.GetEnvironmentVariable("MC_PUBLIC_HOST");
var publicPort = Environment.GetEnvironmentVariable("MC_PUBLIC_PORT");
var role       = Environment.GetEnvironmentVariable("MC_ROLE");        // MasterServer, WorkerServer or CombinedServer
var master     = Environment.GetEnvironmentVariable("MC_MASTER_HOST"); // workers only

var listener = new TcpListener(IPAddress.Any, port);
listener.Start();
Console.WriteLine($"listening on 0.0.0.0:{port}, reachable at {publicHost}:{publicPort}");

Script 10.2: Read your own address and role in Node.js

const port = Number(process.env.PORT ?? 7777);
const publicAddress = `${process.env.MC_PUBLIC_HOST}:${process.env.MC_PUBLIC_PORT}`;
const role = process.env.MC_ROLE;            // MasterServer, WorkerServer or CombinedServer
const master = process.env.MC_MASTER_HOST;   // workers only
console.log(`listening on 0.0.0.0:${port}, reachable at ${publicAddress}`);