# Environments (*environments*) ## 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](https://launchdarkly.com/docs/home/account/environment). ### Available Operations * [listByProject](#listbyproject) - List environments ## 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 ```typescript 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: "", }); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript 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: "", }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("environmentsListByProject failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.GetEnvironmentsByProjectRequest](../../models/operations/getenvironmentsbyprojectrequest.md) | :heavy_check_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :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.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[components.Environments](../../models/components/environments.md)\>** ### Errors | Error Type | Status Code | Content Type | | ------------------------------- | ------------------------------- | ------------------------------- | | errors.InvalidRequestErrorRep | 400 | application/json | | errors.UnauthorizedErrorRep | 401 | application/json | | errors.ForbiddenErrorRep | 403 | application/json | | errors.NotFoundErrorRep | 404 | application/json | | errors.MethodNotAllowedErrorRep | 405 | application/json | | errors.RateLimitedErrorRep | 429 | application/json | | errors.APIError | 4XX, 5XX | \*/\* |