Skip to main content
Glama

generate_llm_context

Create comprehensive LLM context documentation for tools, memory systems, and workflows to enable easy reference within projects.

Instructions

Generate a comprehensive LLM context reference file documenting all tools, memory system, and workflows for easy @ reference

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesPath to the project root directory where LLM_CONTEXT.md will be generated
includeExamplesNoInclude usage examples for tools
formatNoLevel of detail in the generated contextdetailed

Implementation Reference

  • The primary handler function for the 'generate_llm_context' tool. It validates the input parameters, dynamically loads tool definitions from src/index.js, generates comprehensive Markdown content summarizing all tools and system capabilities, writes it to LLM_CONTEXT.md in the project root, and returns a structured MCP response with stats and next steps.
    export async function generateLLMContext(
      params: Partial<GenerateLLMContextInput>,
    ): Promise<any> {
      try {
        // Parse with defaults
        const validated = GenerateLLMContextInputSchema.parse(params);
        const { projectPath, includeExamples, format } = validated;
    
        // Always generate LLM_CONTEXT.md in the project root
        const outputPath = path.join(projectPath, "LLM_CONTEXT.md");
    
        // Get tool definitions dynamically
        const toolDefinitions = await getToolDefinitions();
    
        // Generate the context content
        const content = generateContextContent(
          includeExamples,
          format,
          toolDefinitions,
        );
    
        // Write the file
        await fs.writeFile(outputPath, content, "utf-8");
    
        const metadata = {
          toolVersion: "0.4.1",
          executionTime: 0,
          timestamp: new Date().toISOString(),
        };
    
        return formatMCPResponse({
          success: true,
          data: {
            message: `LLM context file generated successfully at ${outputPath}`,
            path: path.resolve(outputPath),
            stats: {
              totalTools: toolDefinitions.length,
              fileSize: Buffer.byteLength(content, "utf-8"),
              sections: [
                "Overview",
                "Core Tools",
                "README Tools",
                "Memory System",
                "Phase 3 Features",
                "Workflows",
                "Quick Reference",
              ],
            },
          },
          metadata,
          nextSteps: [
            {
              action:
                "Reference this file with @LLM_CONTEXT.md in your LLM conversations",
              priority: "high" as const,
            },
            {
              action: "Regenerate periodically when new tools are added",
              toolRequired: "generate_llm_context",
              priority: "low" as const,
            },
            {
              action: "Use this as a quick reference for DocuMCP capabilities",
              priority: "medium" as const,
            },
          ],
        });
      } catch (error: any) {
        return formatMCPResponse({
          success: false,
          error: {
            code: "GENERATION_ERROR",
            message: `Failed to generate LLM context: ${error.message}`,
          },
          metadata: {
            toolVersion: "0.4.1",
            executionTime: 0,
            timestamp: new Date().toISOString(),
          },
        });
      }
    }
  • Zod schema for input validation of the generate_llm_context tool. Defines required projectPath and optional includeExamples and format parameters.
    export const GenerateLLMContextInputSchema = z.object({
      projectPath: z
        .string()
        .describe(
          "Path to the project root directory where LLM_CONTEXT.md will be generated",
        ),
      includeExamples: z
        .boolean()
        .optional()
        .default(true)
        .describe("Include usage examples for tools"),
      format: z
        .enum(["detailed", "concise"])
        .optional()
        .default("detailed")
        .describe("Level of detail in the generated context"),
    });
  • Helper function to dynamically import and cache the TOOLS array from src/index.js, used by the handler to get all available tool definitions for generating the context file.
    async function getToolDefinitions(): Promise<any[]> {
      if (cachedTools) return cachedTools;
    
      try {
        const indexModule = await import("../index.js");
        cachedTools = indexModule.TOOLS || [];
        return cachedTools;
      } catch (error) {
        console.warn("Could not load TOOLS from index.js:", error);
        return [];
      }
    }
  • Helper function called from src/index.ts to set the cached tool definitions directly, avoiding circular dependency issues.
    /**
     * Set tool definitions for the context generator
     * This is called from src/index.ts when TOOLS array is initialized
     */
    export function setToolDefinitions(tools: any[]) {
      cachedTools = 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/tosin2013/documcp'

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