get_environments
Retrieve all environments from the GrowthBook API to manage feature flags, set default feature states, and scope environments for specific projects.
Instructions
Fetches all environments from the GrowthBook API. GrowthBook comes with one environment by default (production), but you can add as many as you need. Feature flags can be enabled and disabled on a per-environment basis. You can also set the default feature state for any new environment. Additionally, you can scope environments to only be available in specific projects, allowing for further control and segmentation over feature delivery.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/environments.ts:20-39 (handler)The handler function that performs the actual work of fetching all environments from the GrowthBook API using fetch and returns the JSON response formatted as text.async () => { try { const res = await fetch(`${baseApiUrl}/api/v1/environments`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error fetching environments: ${error}`); } } );
- src/tools/environments.ts:13-39 (registration)Registers the "get_environments" tool on the MCP server, including name, detailed description, empty input schema, read-only hint, and inline handler function.server.tool( "get_environments", "Fetches all environments from the GrowthBook API. GrowthBook comes with one environment by default (production), but you can add as many as you need. Feature flags can be enabled and disabled on a per-environment basis. You can also set the default feature state for any new environment. Additionally, you can scope environments to only be available in specific projects, allowing for further control and segmentation over feature delivery.", {}, { readOnlyHint: true, }, async () => { try { const res = await fetch(`${baseApiUrl}/api/v1/environments`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error fetching environments: ${error}`); } } );
- src/index.ts:63-67 (registration)Invokes registerEnvironmentTools to perform the tool registration for get_environments (and possibly others) in the main application entry point.registerEnvironmentTools({ server, baseApiUrl, apiKey, });
- src/tools/environments.ts:16-16 (schema)Empty input schema (no parameters required) for the get_environments tool.{},