Skip to main content
Glama

create_cursor_rules

Define cursor rules to organize and manage project documentation by specifying project purpose and storage location within the Memory Bank MCP server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesAbsolute path where cursor-rules will be created
projectPurposeYesProje amacını detaylı bir şekilde açıklayan bir metin giriniz. Bu metin projenin temel hedeflerini ve kapsamını belirleyecektir.

Implementation Reference

  • Main handler for create_cursor_rules tool: handles directory creation, file writing, error handling, and delegates content generation to helper.
    async ({ projectPurpose, location }) => {
      try {
        // Diagnostics: Log environment info
        console.log(`Current working directory: ${process.cwd()}`);
        console.log(`Node version: ${process.version}`);
        console.log(`Platform: ${process.platform}`);
        
        // Determine where to create the .cursor directory
        let baseDir;
        
        if (location) {
          // Use user-specified location as the base directory
          if (path.isAbsolute(location)) {
            // If absolute path is provided, use it directly as base directory
            baseDir = location;
          } else {
            // If relative path is provided, resolve against current working directory
            baseDir = path.resolve(process.cwd(), location);
          }
          console.log(`Using user specified base location: ${baseDir}`);
        } else {
          // If no location provided, use current working directory as base
          baseDir = process.cwd();
          console.log(`No location specified, using current directory as base: ${baseDir}`);
        }
        
        // Create .cursor directory in the base directory
        const cursorDir = path.join(baseDir, '.cursor');
        console.log(`Will create Cursor Rules at: ${cursorDir}`);
        
        // Ensure parent directory exists if needed
        const parentDir = path.dirname(cursorDir);
        try {
          await fs.ensureDir(parentDir);
          console.log(`Ensured parent directory exists: ${parentDir}`);
        } catch (error) {
          console.error(`Error ensuring parent directory: ${error}`);
          throw new Error(`Cannot create or access parent directory: ${error}`);
        }
        
        // Ensure .cursor directory exists
        try {
          await fs.ensureDir(cursorDir);
          console.log(`Created .cursor directory: ${cursorDir}`);
        } catch (error) {
          console.error(`Error creating .cursor directory: ${error}`);
          throw new Error(`Cannot create .cursor directory: ${error}`);
        }
        
        // Create the cursor-rules.mdc file
        const cursorRulesPath = path.join(cursorDir, 'cursor-rules.mdc');
        console.log(`Will create cursor-rules.mdc at: ${cursorRulesPath}`);
        
        // Generate content for the rules file based on project purpose
        console.log(`Generating cursor rules content for purpose: ${projectPurpose}`);
        try {
          const cursorRulesContent = await generateCursorRules(projectPurpose);
          
          // Save the file
          try {
            await fs.writeFile(cursorRulesPath, cursorRulesContent, 'utf-8');
            console.log(`Created cursor-rules.mdc at: ${cursorRulesPath}`);
          } catch (error) {
            console.error(`Error creating cursor-rules.mdc file: ${error}`);
            throw new Error(`Cannot create cursor-rules.mdc file: ${error}`);
          }
          
          return {
            content: [{ 
              type: 'text', 
              text: `✅ Cursor Rules successfully created!\n\nLocation: ${cursorRulesPath}` 
            }]
          };
        } catch (ruleGenError) {
          console.error(`Error generating cursor rules content: ${ruleGenError}`);
          
          // Detaylı hata mesajı oluştur
          let errorMessage = 'Error generating Cursor Rules content: ';
          if (ruleGenError instanceof Error) {
            errorMessage += ruleGenError.message;
            
            // API key ile ilgili hata mesajlarını daha açıklayıcı hale getir
            if (ruleGenError.message.includes('GEMINI_API_KEY') || ruleGenError.message.includes('API key')) {
              errorMessage += '\n\nÖnemli: Bu özellik Gemini API kullanıyor. Lütfen .env dosyasında geçerli bir GEMINI_API_KEY tanımladığınızdan emin olun.';
            }
          } else {
            errorMessage += String(ruleGenError);
          }
          
          throw new Error(errorMessage);
        }
      } catch (error) {
        console.error('Error creating Cursor Rules:', error);
        return {
          content: [{ type: 'text', text: `❌ Error: ${error instanceof Error ? error.message : String(error)}` }],
          isError: true
        };
      }
    }
  • Zod schema defining input parameters: projectPurpose (string, min 10 chars) and location (string).
    {
      projectPurpose: z.string()
        .min(10, 'Proje amacı en az 10 karakter olmalıdır')
        .describe('Proje amacını detaylı bir şekilde açıklayan bir metin giriniz. Bu metin projenin temel hedeflerini ve kapsamını belirleyecektir.'),
      location: z.string()
        .describe('Absolute path where cursor-rules will be created')
    },
  • MCP server.tool registration for 'create_cursor_rules' with schema and handler.
      'create_cursor_rules',
      {
        projectPurpose: z.string()
          .min(10, 'Proje amacı en az 10 karakter olmalıdır')
          .describe('Proje amacını detaylı bir şekilde açıklayan bir metin giriniz. Bu metin projenin temel hedeflerini ve kapsamını belirleyecektir.'),
        location: z.string()
          .describe('Absolute path where cursor-rules will be created')
      },
      async ({ projectPurpose, location }) => {
        try {
          // Diagnostics: Log environment info
          console.log(`Current working directory: ${process.cwd()}`);
          console.log(`Node version: ${process.version}`);
          console.log(`Platform: ${process.platform}`);
          
          // Determine where to create the .cursor directory
          let baseDir;
          
          if (location) {
            // Use user-specified location as the base directory
            if (path.isAbsolute(location)) {
              // If absolute path is provided, use it directly as base directory
              baseDir = location;
            } else {
              // If relative path is provided, resolve against current working directory
              baseDir = path.resolve(process.cwd(), location);
            }
            console.log(`Using user specified base location: ${baseDir}`);
          } else {
            // If no location provided, use current working directory as base
            baseDir = process.cwd();
            console.log(`No location specified, using current directory as base: ${baseDir}`);
          }
          
          // Create .cursor directory in the base directory
          const cursorDir = path.join(baseDir, '.cursor');
          console.log(`Will create Cursor Rules at: ${cursorDir}`);
          
          // Ensure parent directory exists if needed
          const parentDir = path.dirname(cursorDir);
          try {
            await fs.ensureDir(parentDir);
            console.log(`Ensured parent directory exists: ${parentDir}`);
          } catch (error) {
            console.error(`Error ensuring parent directory: ${error}`);
            throw new Error(`Cannot create or access parent directory: ${error}`);
          }
          
          // Ensure .cursor directory exists
          try {
            await fs.ensureDir(cursorDir);
            console.log(`Created .cursor directory: ${cursorDir}`);
          } catch (error) {
            console.error(`Error creating .cursor directory: ${error}`);
            throw new Error(`Cannot create .cursor directory: ${error}`);
          }
          
          // Create the cursor-rules.mdc file
          const cursorRulesPath = path.join(cursorDir, 'cursor-rules.mdc');
          console.log(`Will create cursor-rules.mdc at: ${cursorRulesPath}`);
          
          // Generate content for the rules file based on project purpose
          console.log(`Generating cursor rules content for purpose: ${projectPurpose}`);
          try {
            const cursorRulesContent = await generateCursorRules(projectPurpose);
            
            // Save the file
            try {
              await fs.writeFile(cursorRulesPath, cursorRulesContent, 'utf-8');
              console.log(`Created cursor-rules.mdc at: ${cursorRulesPath}`);
            } catch (error) {
              console.error(`Error creating cursor-rules.mdc file: ${error}`);
              throw new Error(`Cannot create cursor-rules.mdc file: ${error}`);
            }
            
            return {
              content: [{ 
                type: 'text', 
                text: `✅ Cursor Rules successfully created!\n\nLocation: ${cursorRulesPath}` 
              }]
            };
          } catch (ruleGenError) {
            console.error(`Error generating cursor rules content: ${ruleGenError}`);
            
            // Detaylı hata mesajı oluştur
            let errorMessage = 'Error generating Cursor Rules content: ';
            if (ruleGenError instanceof Error) {
              errorMessage += ruleGenError.message;
              
              // API key ile ilgili hata mesajlarını daha açıklayıcı hale getir
              if (ruleGenError.message.includes('GEMINI_API_KEY') || ruleGenError.message.includes('API key')) {
                errorMessage += '\n\nÖnemli: Bu özellik Gemini API kullanıyor. Lütfen .env dosyasında geçerli bir GEMINI_API_KEY tanımladığınızdan emin olun.';
              }
            } else {
              errorMessage += String(ruleGenError);
            }
            
            throw new Error(errorMessage);
          }
        } catch (error) {
          console.error('Error creating Cursor Rules:', error);
          return {
            content: [{ type: 'text', text: `❌ Error: ${error instanceof Error ? error.message : String(error)}` }],
            isError: true
          };
        }
      }
    );
  • Core helper that generates Cursor rules content using AI (Gemini), detects project type, handles errors.
    export async function generateCursorRules(purpose: string): Promise<string> {
      // Format current date in English locale
      const currentDate = new Date().toLocaleDateString("en-US");
    
      // Project type detection based on user's purpose
      const projectType = detectProjectType(purpose);
    
      // AI ile içerik oluştur
      try {
        console.log("Attempting to generate cursor rules with AI...");
        const mainRulesContent = await generateMainCursorRulesWithAI(
          purpose,
          currentDate,
          projectType
        );
        console.log("Successfully generated cursor rules with AI");
        return mainRulesContent;
      } catch (error) {
        console.error("Error generating cursor rules with AI:", error);
        
        // Hata detayı için log ekleyelim
        if (error instanceof Error) {
          console.error("Error details:", error.message);
          if (error.stack) {
            console.error("Error stack:", error.stack);
          }
          
          // Kullanıcıya daha açıklayıcı hata mesajı göster
          throw new Error(`AI ile içerik oluşturulamadı: ${error.message}`);
        }
        
        // Genel hata durumunda
        throw new Error("AI ile içerik oluşturulamadı. Lütfen daha sonra tekrar deneyin.");
      }
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related 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/tuncer-byte/memory-bank-MCP'

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