Skip to main content
Glama

start_context_engine

Initialize the context engine to access current library documentation and code examples for AI coding assistance.

Instructions

Starts the context engine and returns a confirmation message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectRootYesThe project root directory

Implementation Reference

  • Core implementation of the startContextEngine function, which handles local documentation setup and remote API call to start the context engine.
    export async function startContextEngine(
      projectRoot: string,
      clientIp?: string,
      apiKey?: string,
      serverUrl?: string
    ): Promise<string> {
      if (!projectRoot) {
        throw new Error("Project root directory is required for context engine initialization");
      }
    
      let apiResponse = "";
      let documentationStatus = "";
    
      try {
        // Step 1: Setup local documentation structure first
        logger.info("Setting up local documentation structure");
        const setupResult = await setupDocumentationStructure(projectRoot);
    
        if (setupResult.success) {
          documentationStatus = `\n\n📁 Local Documentation Structure: ${setupResult.message}`;
          logger.info("Local documentation structure setup completed", {
            status: setupResult.status as unknown as Record<string, unknown>,
          });
        } else {
          logger.warn("Local documentation structure setup failed", {
            status: setupResult.status as unknown as Record<string, unknown>,
          });
          // Don't proceed with API call if local setup fails
          return `❌ Failed to setup local documentation structure: ${setupResult.message}`;
        }
      } catch (error) {
        logger.error("Local documentation structure setup failed", {
          error: error instanceof Error ? error.message : String(error),
        });
        // Don't proceed with API call if local setup fails
        return `❌ Failed to setup local documentation structure: ${error instanceof Error ? error.message : String(error)}`;
      }
    
      try {
        // Step 2: Start the context engine via API (only if local setup succeeded)
        logger.info("Starting ContextEngine via API");
        const url = buildApiUrl("start-context-engine", {}, serverUrl);
        const headers = generateHeaders(clientIp, apiKey, { "X-ContextEngine-Source": "mcp-server" });
    
        const response = await makeApiRequest(url, headers, "start context engine");
        const text = await response.text();
    
        if (!text || text === "No content available") {
          apiResponse = "Context engine start request sent but no confirmation available.";
        } else {
          apiResponse = text;
        }
    
        logger.info("ContextEngine API call successful");
      } catch (error) {
        logger.error("ContextEngine API call failed", {
          error: error instanceof Error ? error.message : String(error),
        });
    
        apiResponse = `⚠️  ContextEngine API call failed: ${error instanceof Error ? error.message : String(error)}`;
      }
      
      // Return combined response
      return `${apiResponse}${documentationStatus}`;
    }
  • src/index.ts:77-107 (registration)
    MCP tool registration for 'start_context_engine', including input schema, description, and handler that delegates to the core startContextEngine function.
    server.registerTool(
      "start_context_engine",
      {
        title: "Start Context Engine",
        description: "Starts the context engine and returns a confirmation message.",
        inputSchema: {
          projectRoot: z.string().describe("The project root directory"),
        },
      },
      async (args) => {
        // Validate API key based on environment
        validateApiKey(apiKey, finalServerUrl);
    
        const startContextEngineResponse = await startContextEngine(
          args.projectRoot,
          clientIp,
          apiKey,
          finalServerUrl
        );
    
        return {
          content: [
            {
              type: "text",
              text: startContextEngineResponse,
            },
          ],
        };
      }
    );
  • Input schema definition for the tool using Zod, requiring projectRoot string.
    {
      title: "Start Context Engine",
      description: "Starts the context engine and returns a confirmation message.",
      inputSchema: {
        projectRoot: z.string().describe("The project root directory"),
      },
    },
Install Server

Other 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/livelifelively/context-engine-mcp'

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