Environments

March 2, 2026 ยท View on GitHub

Overview

Environments allow you to maintain separate rollout rules in different contexts, from local development to QA, staging, and production. With the LaunchDarkly Environments API, you can programmatically list, create, and manage environments. To learn more, read Environments.

Available Operations

listByProject

Return a list of environments for the specified project.

By default, this returns the first 20 environments. Page through this list with the limit parameter and by following the first, prev, next, and last links in the _links field that returns. If those links do not appear, the pages they refer to don't exist. For example, the first and prev links will be missing from the response on the first page, because there is no previous page and you cannot return to the first page when you are already on the first page.

Filtering environments

LaunchDarkly supports two fields for filters:

  • query is a string that matches against the environments' names and keys. It is not case sensitive.
  • tags is a +-separated list of environment tags. It filters the list of environments that have all of the tags in the list.

For example, the filter filter=query:abc,tags:tag-1+tag-2 matches environments with the string abc in their name or key and also are tagged with tag-1 and tag-2. The filter is not case-sensitive.

The documented values for filter query parameters are prior to URL encoding. For example, the + in filter=tags:tag-1+tag-2 must be encoded to %2B.

Sorting environments

LaunchDarkly supports the following fields for sorting:

  • createdOn sorts by the creation date of the environment.
  • critical sorts by whether the environments are marked as critical.
  • name sorts by environment name.

For example, sort=name sorts the response by environment name in ascending order.

Example Usage

import { LaunchDarkly } from "@launchdarkly/mcp-server";

const launchDarkly = new LaunchDarkly({
  apiKey: process.env["LAUNCHDARKLY_API_KEY"] ?? "",
});

async function run() {
  const result = await launchDarkly.environments.listByProject({
    projectKey: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { LaunchDarklyCore } from "@launchdarkly/mcp-server/core.js";
import { environmentsListByProject } from "@launchdarkly/mcp-server/funcs/environmentsListByProject.js";

// Use `LaunchDarklyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const launchDarkly = new LaunchDarklyCore({
  apiKey: process.env["LAUNCHDARKLY_API_KEY"] ?? "",
});

async function run() {
  const res = await environmentsListByProject(launchDarkly, {
    projectKey: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("environmentsListByProject failed:", res.error);
  }
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.GetEnvironmentsByProjectRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Environments>

Errors

Error TypeStatus CodeContent Type
errors.InvalidRequestErrorRep400application/json
errors.UnauthorizedErrorRep401application/json
errors.ForbiddenErrorRep403application/json
errors.NotFoundErrorRep404application/json
errors.MethodNotAllowedErrorRep405application/json
errors.RateLimitedErrorRep429application/json
errors.APIError4XX, 5XX*/*