create_sdk_connection
Generate an SDK connection for GrowthBook to fetch features and experiments. Specify the SDK language, environment, and name to create a client key.
Instructions
Create an SDK connection for a user. Returns an SDK clientKey that can be used to fetch features and experiments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environment | No | The environment associated with the SDK connection. | |
| language | Yes | The language of the SDK. Either 'javascript' or 'typescript'. | |
| name | Yes | Name of the SDK connection in GrowthBook. Should reflect the current project. |
Implementation Reference
- src/tools/sdk-connections.ts:115-169 (handler)Handler function for the create_sdk_connection tool. If no environment is provided, it lists available environments. Otherwise, it creates a new SDK connection by POSTing to the GrowthBook API.async ({ name, language, environment, projects }) => { if (!environment) { 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(); const text = `${JSON.stringify(data, null, 2)} Here is the list of environments. Ask the user to select one and use the key in the create_sdk_connection tool. `; return { content: [{ type: "text", text }], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], }; } } const payload = { name, language, environment, ...(projects && { projects }), }; try { const res = await fetch(`${baseApiUrl}/api/v1/sdk-connections`, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error creating sdk connection: ${error}`); } }
- src/tools/sdk-connections.ts:70-110 (schema)Zod input schema for create_sdk_connection tool defining parameters: name (string), language (enum of platforms), environment (optional string), projects (optional array of strings).{ name: z .string() .describe( "Name of the SDK connection in GrowthBook. Should reflect the current project." ), language: z .enum([ "nocode-webflow", "nocode-wordpress", "nocode-shopify", "nocode-other", "javascript", "nodejs", "react", "php", "ruby", "python", "go", "java", "csharp", "android", "ios", "flutter", "elixir", "edge-cloudflare", "edge-fastly", "edge-lambda", "edge-other", "other", ]) .describe("The language or platform for the SDK connection."), environment: z .string() .optional() .describe("The environment associated with the SDK connection."), projects: z .array(z.string()) .describe("The projects to create the SDK connection in") .optional(), },
- src/tools/sdk-connections.ts:67-170 (registration)Direct registration of the create_sdk_connection tool using server.tool, including name, description, schema, options, and handler.server.tool( "create_sdk_connection", `Create an SDK connection for a user. Returns an SDK clientKey that can be used to fetch features and experiments.`, { name: z .string() .describe( "Name of the SDK connection in GrowthBook. Should reflect the current project." ), language: z .enum([ "nocode-webflow", "nocode-wordpress", "nocode-shopify", "nocode-other", "javascript", "nodejs", "react", "php", "ruby", "python", "go", "java", "csharp", "android", "ios", "flutter", "elixir", "edge-cloudflare", "edge-fastly", "edge-lambda", "edge-other", "other", ]) .describe("The language or platform for the SDK connection."), environment: z .string() .optional() .describe("The environment associated with the SDK connection."), projects: z .array(z.string()) .describe("The projects to create the SDK connection in") .optional(), }, { readOnlyHint: false, destructiveHint: false, }, async ({ name, language, environment, projects }) => { if (!environment) { 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(); const text = `${JSON.stringify(data, null, 2)} Here is the list of environments. Ask the user to select one and use the key in the create_sdk_connection tool. `; return { content: [{ type: "text", text }], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], }; } } const payload = { name, language, environment, ...(projects && { projects }), }; try { const res = await fetch(`${baseApiUrl}/api/v1/sdk-connections`, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); await handleResNotOk(res); const data = await res.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { throw new Error(`Error creating sdk connection: ${error}`); } } );
- src/index.ts:75-79 (registration)Top-level registration call in main index file that invokes registerSdkConnectionTools to add the create_sdk_connection tool to the MCP server.registerSdkConnectionTools({ server, baseApiUrl, apiKey, });