Skip to content

Commit a1e6ffb

Browse files
committed
Ensure that PATs work as expected. Make GB_EMAIL validation logic simpler.
1 parent bf59cef commit a1e6ffb

File tree

6 files changed

+13
-64
lines changed

6 files changed

+13
-64
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use the following env variables to configure the MCP server.
1313

1414
| Variable Name | Status | Description |
1515
| ------------- | -------- | ----------------------------------------------------------------- |
16-
| GB_API_KEY | Required | A GrowthBook API key. |
16+
| GB_API_KEY | Required | A GrowthBook API key or PAT. When using a PAT, MCP server capabilities are limited by its permissions. E.g., if the user can't create an experiment in the app, they also won't be able to create one with the MCP server. |
1717
| GB_EMAIL | Required | Your email address used with GrowthBook. Used when creating feature flags and experiments.|
1818
| GB_API_URL | Optional | Your GrowthBook API URL. Defaults to `https://api.growthbook.io`. |
1919
| GB_APP_ORIGIN | Optional | Your GrowthBook app URL Defaults to `https://app.growthbook.io`. |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@growthbook/mcp",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "",
55
"access": "public",
66
"homepage": "https://github.com/growthbook/growthbook-mcp",

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ import { registerExperimentTools } from "./tools/experiments.js";
77
import { registerFeatureTools } from "./tools/features.js";
88
import { registerProjectTools } from "./tools/projects.js";
99
import { registerSdkConnectionTools } from "./tools/sdk-connections.js";
10-
import { getApiKey, getApiUrl, getAppOrigin, getUser } from "./utils.js";
10+
import { getApiKey, getApiUrl, getAppOrigin } from "./utils.js";
1111
import { registerSearchTools } from "./tools/search.js";
1212
import { registerDefaultsTools } from "./tools/defaults.js";
1313

1414
export const baseApiUrl = getApiUrl();
1515
export const apiKey = getApiKey();
1616
export const appOrigin = getAppOrigin();
17-
export const user = await getUser(baseApiUrl, apiKey);
17+
export const user = process.env.GB_EMAIL;
18+
19+
if (!user) {
20+
throw new Error("GB_EMAIL is not set in the environment variables");
21+
}
1822

1923
// Create an MCP server
2024
const server = new McpServer(
2125
{
2226
name: "GrowthBook MCP",
23-
version: "1.0.0",
27+
version: "1.0.2",
2428
},
2529
{
2630
instructions: `You are a helpful assistant that interacts with GrowthBook, an open source feature flagging and experimentation platform. You can create and manage feature flags, experiments (A/B tests), and other resources associated with GrowthBook.

src/tools/experiments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export function registerExperimentTools({
305305
name,
306306
description,
307307
hypothesis,
308-
owner: user.email,
308+
owner: user,
309309
trackingKey: name.toLowerCase().replace(/[^a-z0-9]/g, "-"),
310310
tags: ["mcp"],
311311
assignmentQueryId: experimentDefaults?.assignmentQuery,
@@ -335,7 +335,7 @@ export function registerExperimentTools({
335335

336336
const flagPayload = {
337337
id: flagId,
338-
owner: user.name,
338+
owner: user,
339339
defaultValue: variations[0].value,
340340
valueType:
341341
typeof variations[0].value === "string"

src/tools/features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function registerFeatureTools({
7373
const payload = {
7474
id,
7575
description,
76-
owner: user.name,
76+
owner: user,
7777
valueType,
7878
defaultValue,
7979
tags: ["mcp"],

src/utils.ts

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ export interface BaseToolsInterface {
1111

1212
export interface ExtendedToolsInterface extends BaseToolsInterface {
1313
appOrigin: string;
14-
user: {
15-
email: string;
16-
name: string;
17-
};
14+
user: string;
1815
}
1916

2017
// Shared file extension enum for all MCP tools
@@ -75,58 +72,6 @@ export function getAppOrigin() {
7572
return `${userAppOrigin || defaultAppOrigin}`;
7673
}
7774

78-
export async function getUser(baseApiUrl: string, apiKey: string) {
79-
const user = process.env.GB_EMAIL || process.env.GB_USER;
80-
81-
if (!user) {
82-
throw new Error("GB_EMAIL environment variable is required");
83-
}
84-
85-
// Show deprecation warning if using the old variable
86-
if (process.env.GB_USER && !process.env.GB_EMAIL) {
87-
console.error("⚠️ GB_USER is deprecated. Use GB_EMAIL instead.");
88-
}
89-
90-
const emailSchema = z.string().email();
91-
92-
if (!emailSchema.safeParse(user).success) {
93-
throw new Error("GB_EMAIL is not a valid email");
94-
}
95-
96-
try {
97-
const users = await fetch(
98-
`${baseApiUrl}/api/v1/members?userEmail=${user}`,
99-
{
100-
headers: {
101-
Authorization: `Bearer ${apiKey}`,
102-
},
103-
}
104-
);
105-
await handleResNotOk(users);
106-
107-
const usersData = await users.json();
108-
109-
if (usersData.members.length === 0) {
110-
throw new Error(
111-
`Email not found in GrowthBook. Update GB_EMAIL environment variable to your email address in GrowthBook.`
112-
);
113-
}
114-
115-
const userFromGrowthBook = {
116-
email: usersData.members[0].email,
117-
name: usersData.members[0].name,
118-
};
119-
120-
return userFromGrowthBook;
121-
} catch (error) {
122-
const originalError =
123-
error instanceof Error ? error.message : String(error);
124-
throw new Error(
125-
`Error fetching user from GrowthBook. Please check your GB_EMAIL and GB_API_KEY environment variables. Original error: ${originalError}`
126-
);
127-
}
128-
}
129-
13075
export function getDocsMetadata(extension: string) {
13176
switch (extension) {
13277
case ".tsx":

0 commit comments

Comments
 (0)