Skip to main content
Glama
growthbook

GrowthBook MCP Server

Official
by growthbook

get_experiments

Retrieve experiments from the GrowthBook API with customizable parameters like limit, offset, and project for targeted data access.

Instructions

Fetches all experiments from the GrowthBook API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
offsetNo
projectNo

Implementation Reference

  • The handler function fetches experiments from GrowthBook API. Supports pagination (limit/offset), project filter, 'mostRecent' sorting, and 'analyze' mode to include results. Returns JSON stringified response.
    async ({ limit, offset, mostRecent, project, mode }) => {
      try {
        // Default behavior
        if (!mostRecent || offset > 0) {
          const defaultQueryParams = new URLSearchParams({
            limit: limit.toString(),
            offset: offset.toString(),
          });
    
          if (project) {
            defaultQueryParams.append("projectId", project);
          }
    
          const defaultRes = await fetch(
            `${baseApiUrl}/api/v1/experiments?${defaultQueryParams.toString()}`,
            {
              headers: {
                Authorization: `Bearer ${apiKey}`,
                "Content-Type": "application/json",
              },
            }
          );
    
          await handleResNotOk(defaultRes);
          const data = await defaultRes.json();
          const experiments = data.experiments as Experiment[];
    
          if (mode === "analyze") {
            for (const [index, experiment] of experiments.entries()) {
              try {
                const resultsRes = await fetch(
                  `${baseApiUrl}/api/v1/experiments/${experiment.id}/results`,
                  {
                    headers: {
                      Authorization: `Bearer ${apiKey}`,
                    },
                  }
                );
                await handleResNotOk(resultsRes);
                const resultsData = await resultsRes.json();
                experiments[index].result = resultsData.result;
              } catch (error) {
                console.error(
                  `Error fetching results for experiment ${experiment.id} (${experiment.name})`,
                  error
                );
              }
            }
          }
    
          return {
            content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
          };
        }
    
        // Most recent behavior
        const countRes = await fetch(
          `${baseApiUrl}/api/v1/experiments?limit=1`,
          {
            headers: {
              Authorization: `Bearer ${apiKey}`,
            },
          }
        );
    
        await handleResNotOk(countRes);
        const countData = await countRes.json();
        const total = countData.total;
        const calculatedOffset = Math.max(0, total - limit);
    
        const mostRecentQueryParams = new URLSearchParams({
          limit: limit.toString(),
          offset: calculatedOffset.toString(),
        });
    
        if (project) {
          mostRecentQueryParams.append("projectId", project);
        }
    
        const mostRecentRes = await fetch(
          `${baseApiUrl}/api/v1/experiments?${mostRecentQueryParams.toString()}`,
          {
            headers: {
              Authorization: `Bearer ${apiKey}`,
            },
          }
        );
    
        await handleResNotOk(mostRecentRes);
        const mostRecentData = await mostRecentRes.json();
    
        if (
          mostRecentData.experiments &&
          Array.isArray(mostRecentData.experiments)
        ) {
          mostRecentData.experiments = mostRecentData.experiments.reverse();
    
          if (mode === "analyze") {
            for (const [
              index,
              experiment,
            ] of mostRecentData.experiments.entries()) {
              try {
                const resultsRes = await fetch(
                  `${baseApiUrl}/api/v1/experiments/${experiment.id}/results`,
                  {
                    headers: {
                      Authorization: `Bearer ${apiKey}`,
                    },
                  }
                );
                await handleResNotOk(resultsRes);
                const resultsData = await resultsRes.json();
                mostRecentData.experiments[index].result = resultsData.result;
              } catch (error) {
                console.error(
                  `Error fetching results for experiment ${experiment.id} (${experiment.name})`,
                  error
                );
              }
            }
          }
        }
    
        return {
          content: [
            { type: "text", text: JSON.stringify(mostRecentData, null, 2) },
          ],
        };
      } catch (error) {
        throw new Error(`Error fetching experiments: ${error}`);
      }
    }
  • Zod input schema defining parameters: optional project ID, mode (default/analyze), and pagination options from paginationSchema.
    {
      project: z
        .string()
        .describe("The ID of the project to filter experiments by")
        .optional(),
      mode: z
        .enum(["default", "analyze"])
        .default("default")
        .describe(
          "The mode to use to fetch experiments. Default mode returns summary info about experiments. Analyze mode will also fetch experiment results, allowing for better analysis, interpretation, and reporting."
        ),
      ...paginationSchema,
    },
  • Registers the get_experiments tool on the MCP server with name, description, input schema, readOnlyHint, and handler function.
    server.tool(
      "get_experiments",
      "Fetches experiments from the GrowthBook API",
      {
        project: z
          .string()
          .describe("The ID of the project to filter experiments by")
          .optional(),
        mode: z
          .enum(["default", "analyze"])
          .default("default")
          .describe(
            "The mode to use to fetch experiments. Default mode returns summary info about experiments. Analyze mode will also fetch experiment results, allowing for better analysis, interpretation, and reporting."
          ),
        ...paginationSchema,
      },
      {
        readOnlyHint: true,
      },
      async ({ limit, offset, mostRecent, project, mode }) => {
        try {
          // Default behavior
          if (!mostRecent || offset > 0) {
            const defaultQueryParams = new URLSearchParams({
              limit: limit.toString(),
              offset: offset.toString(),
            });
    
            if (project) {
              defaultQueryParams.append("projectId", project);
            }
    
            const defaultRes = await fetch(
              `${baseApiUrl}/api/v1/experiments?${defaultQueryParams.toString()}`,
              {
                headers: {
                  Authorization: `Bearer ${apiKey}`,
                  "Content-Type": "application/json",
                },
              }
            );
    
            await handleResNotOk(defaultRes);
            const data = await defaultRes.json();
            const experiments = data.experiments as Experiment[];
    
            if (mode === "analyze") {
              for (const [index, experiment] of experiments.entries()) {
                try {
                  const resultsRes = await fetch(
                    `${baseApiUrl}/api/v1/experiments/${experiment.id}/results`,
                    {
                      headers: {
                        Authorization: `Bearer ${apiKey}`,
                      },
                    }
                  );
                  await handleResNotOk(resultsRes);
                  const resultsData = await resultsRes.json();
                  experiments[index].result = resultsData.result;
                } catch (error) {
                  console.error(
                    `Error fetching results for experiment ${experiment.id} (${experiment.name})`,
                    error
                  );
                }
              }
            }
    
            return {
              content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
            };
          }
    
          // Most recent behavior
          const countRes = await fetch(
            `${baseApiUrl}/api/v1/experiments?limit=1`,
            {
              headers: {
                Authorization: `Bearer ${apiKey}`,
              },
            }
          );
    
          await handleResNotOk(countRes);
          const countData = await countRes.json();
          const total = countData.total;
          const calculatedOffset = Math.max(0, total - limit);
    
          const mostRecentQueryParams = new URLSearchParams({
            limit: limit.toString(),
            offset: calculatedOffset.toString(),
          });
    
          if (project) {
            mostRecentQueryParams.append("projectId", project);
          }
    
          const mostRecentRes = await fetch(
            `${baseApiUrl}/api/v1/experiments?${mostRecentQueryParams.toString()}`,
            {
              headers: {
                Authorization: `Bearer ${apiKey}`,
              },
            }
          );
    
          await handleResNotOk(mostRecentRes);
          const mostRecentData = await mostRecentRes.json();
    
          if (
            mostRecentData.experiments &&
            Array.isArray(mostRecentData.experiments)
          ) {
            mostRecentData.experiments = mostRecentData.experiments.reverse();
    
            if (mode === "analyze") {
              for (const [
                index,
                experiment,
              ] of mostRecentData.experiments.entries()) {
                try {
                  const resultsRes = await fetch(
                    `${baseApiUrl}/api/v1/experiments/${experiment.id}/results`,
                    {
                      headers: {
                        Authorization: `Bearer ${apiKey}`,
                      },
                    }
                  );
                  await handleResNotOk(resultsRes);
                  const resultsData = await resultsRes.json();
                  mostRecentData.experiments[index].result = resultsData.result;
                } catch (error) {
                  console.error(
                    `Error fetching results for experiment ${experiment.id} (${experiment.name})`,
                    error
                  );
                }
              }
            }
          }
    
          return {
            content: [
              { type: "text", text: JSON.stringify(mostRecentData, null, 2) },
            ],
          };
        } catch (error) {
          throw new Error(`Error fetching experiments: ${error}`);
        }
      }
    );
  • src/index.ts:89-95 (registration)
    Top-level call to registerExperimentTools in the main MCP server setup, which includes registering get_experiments.
    registerExperimentTools({
      server,
      baseApiUrl,
      apiKey,
      appOrigin,
      user,
    });
  • TypeScript type definition for Experiment used in the handler to type API response.
    type Experiment = {
      id: string;
      trackingKey: string;
      dateCreated: string;
      dateUpdated: string;
      name: string;
      type: "standard";
      project: string;
      resultSummary: {
        status: string;
        winner: string;
        conclusions: string;
        releasedVariationId: string;
        excludeFromPayload: true;
      };
      result?: {
        [key: string]: any;
      };
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'fetches' implies a read operation, it doesn't mention pagination behavior (implied by limit/offset parameters), authentication requirements, rate limits, or what format the experiments are returned in. The description is too minimal for a tool with parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized for a simple fetch operation and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, 0% schema description coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain the tool's behavior, parameter meanings, or return format. The description should provide more context about what 'all experiments' means given the pagination parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 3 parameters, the description provides no information about what 'limit', 'offset', or 'project' mean. It doesn't explain that 'limit' controls pagination size, 'offset' controls pagination starting point, or 'project' filters results. The description fails to compensate for the schema's lack of parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('fetches') and resource ('experiments from the GrowthBook API'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'get_experiment' (singular), which appears to fetch a single experiment rather than all experiments.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling 'get_experiment' tool for fetching individual experiments, nor does it explain when filtering by project might be appropriate versus fetching all experiments.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/growthbook/growthbook-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server