Skip to main content
Glama
growthbook

GrowthBook MCP Server

Official
by growthbook

search_growthbook_docs

Search the GrowthBook documentation to find detailed instructions and guidance on using specific features effectively.

Instructions

Search the GrowthBook docs on how to use a feature

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query to look up in the GrowthBook docs.

Implementation Reference

  • Handler function that executes the search_growthbook_docs tool logic: fetches search results from GrowthBook docs via the helper function and formats them into structured text responses.
    async ({ query }) => {
      const hits = await searchGrowthBookDocs(query);
      return {
        content: hits.slice(0, 5).map((hit: any) => {
          // Algolia typically returns content in various fields
          const content =
            hit.content ||
            hit.text ||
            hit._snippetResult?.content?.value ||
            hit._highlightResult?.content?.value;
          const snippet =
            hit._snippetResult?.content?.value ||
            hit._highlightResult?.content?.value;
          const title = hit.title || hit.hierarchy?.lvl0 || hit.hierarchy?.lvl1;
          const url = hit.url || hit.anchor;
    
          let text = "";
          if (title) {
            text += `**${title}**\n`;
          }
          if (url) {
            text += `URL: ${url}\n`;
          }
          if (snippet || content) {
            text += `\n${snippet || content}`;
          }
    
          return {
            type: "text",
            text: text || JSON.stringify(hit),
          };
        }),
      };
    }
  • Input schema definition using Zod for the tool's 'query' parameter.
    {
      query: z
        .string()
        .describe("The search query to look up in the GrowthBook docs."),
    },
  • Tool registration via server.tool() in the registerSearchTools export function, including name, description, schema, and handler.
    export function registerSearchTools({ server }: { server: McpServer }) {
      server.tool(
        "search_growthbook_docs",
        "Search the GrowthBook docs on how to use a feature",
        {
          query: z
            .string()
            .describe("The search query to look up in the GrowthBook docs."),
        },
        {
          readOnlyHint: true,
        },
        async ({ query }) => {
          const hits = await searchGrowthBookDocs(query);
          return {
            content: hits.slice(0, 5).map((hit: any) => {
              // Algolia typically returns content in various fields
              const content =
                hit.content ||
                hit.text ||
                hit._snippetResult?.content?.value ||
                hit._highlightResult?.content?.value;
              const snippet =
                hit._snippetResult?.content?.value ||
                hit._highlightResult?.content?.value;
              const title = hit.title || hit.hierarchy?.lvl0 || hit.hierarchy?.lvl1;
              const url = hit.url || hit.anchor;
    
              let text = "";
              if (title) {
                text += `**${title}**\n`;
              }
              if (url) {
                text += `URL: ${url}\n`;
              }
              if (snippet || content) {
                text += `\n${snippet || content}`;
              }
    
              return {
                type: "text",
                text: text || JSON.stringify(hit),
              };
            }),
          };
        }
      );
    }
  • Supporting helper function that performs the actual Algolia search query against the GrowthBook documentation index and returns raw hits.
    export async function searchGrowthBookDocs(query: string) {
      const APPLICATION_ID = "MN7ZMY63CG";
      const API_KEY = "e17ebcbd97bce29ad0bdec269770e9df";
      const INDEX_NAME = "growthbook";
      const url = `https://${APPLICATION_ID}-dsn.algolia.net/1/indexes/${INDEX_NAME}/query`;
      try {
        const response = await fetch(url, {
          method: "POST",
          headers: {
            "X-Algolia-API-Key": API_KEY,
            "X-Algolia-Application-Id": APPLICATION_ID,
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            query,
            attributesToSnippet: ["content:20", "text:20"],
            snippetEllipsisText: "...",
            hitsPerPage: 5,
          }),
        });
    
        await handleResNotOk(response);
    
        const data = await response.json();
        const hits = data.hits || [];
    
        return hits;
      } catch (error) {
        return [];
      }
    }

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