get_experiment
Retrieve a specific experiment by its ID from the GrowthBook MCP Server to access detailed information and insights.
Instructions
Gets a single experiment from GrowthBook
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| experimentId | Yes | The ID of the experiment to get |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"experimentId": {
"description": "The ID of the experiment to get",
"type": "string"
}
},
"required": [
"experimentId"
],
"type": "object"
}
Implementation Reference
- src/tools/experiments.ts:216-270 (handler)The handler function fetches the experiment by ID from the GrowthBook API. If mode is 'analyze', it also fetches results. It generates a GrowthBook link and returns the data as formatted text.async ({ experimentId, mode }) => { try { const res = await fetch( `${baseApiUrl}/api/v1/experiments/${experimentId}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, } ); await handleResNotOk(res); const data = await res.json(); // If analyze mode, fetch results if (mode === "analyze") { try { const resultsRes = await fetch( `${baseApiUrl}/api/v1/experiments/${experimentId}/results`, { headers: { Authorization: `Bearer ${apiKey}`, }, } ); await handleResNotOk(resultsRes); const resultsData = await resultsRes.json(); data.result = resultsData.result; } catch (error) { console.error( `Error fetching results for experiment ${experimentId}`, error ); } } const linkToGrowthBook = generateLinkToGrowthBook( appOrigin, "experiment", experimentId ); const text = ` ${JSON.stringify(data, null, 2)} [View the experiment in GrowthBook](${linkToGrowthBook}) `; return { content: [{ type: "text", text }], }; } catch (error) { throw new Error(`Error getting experiment: ${error}`); } }
- src/tools/experiments.ts:204-212 (schema)Zod schema defining the input parameters for the get_experiment tool: experimentId (string) and optional mode ("default" or "analyze").{ experimentId: z.string().describe("The ID of the experiment to get"), mode: z .enum(["default", "analyze"]) .default("default") .describe( "The mode to use to fetch the experiment. Default mode returns summary info about the experiment. Analyze mode will also fetch experiment results, allowing for better analysis, interpretation, and reporting." ), },
- src/tools/experiments.ts:198-271 (registration)The server.tool call that registers the get_experiment tool, including its name, description, input schema, options, and handler function. This is called within registerExperimentTools./** * Tool: get_experiment */ server.tool( "get_experiment", "Gets a single experiment from GrowthBook", { experimentId: z.string().describe("The ID of the experiment to get"), mode: z .enum(["default", "analyze"]) .default("default") .describe( "The mode to use to fetch the experiment. Default mode returns summary info about the experiment. Analyze mode will also fetch experiment results, allowing for better analysis, interpretation, and reporting." ), }, { readOnlyHint: true, }, async ({ experimentId, mode }) => { try { const res = await fetch( `${baseApiUrl}/api/v1/experiments/${experimentId}`, { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, } ); await handleResNotOk(res); const data = await res.json(); // If analyze mode, fetch results if (mode === "analyze") { try { const resultsRes = await fetch( `${baseApiUrl}/api/v1/experiments/${experimentId}/results`, { headers: { Authorization: `Bearer ${apiKey}`, }, } ); await handleResNotOk(resultsRes); const resultsData = await resultsRes.json(); data.result = resultsData.result; } catch (error) { console.error( `Error fetching results for experiment ${experimentId}`, error ); } } const linkToGrowthBook = generateLinkToGrowthBook( appOrigin, "experiment", experimentId ); const text = ` ${JSON.stringify(data, null, 2)} [View the experiment in GrowthBook](${linkToGrowthBook}) `; return { content: [{ type: "text", text }], }; } catch (error) { throw new Error(`Error getting experiment: ${error}`); } } );
- src/index.ts:89-95 (registration)Top-level call to registerExperimentTools in the main MCP server setup, which in turn registers the get_experiment tool.registerExperimentTools({ server, baseApiUrl, apiKey, appOrigin, user, });