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
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes | Absolute path where cursor-rules will be created | |
| projectPurpose | Yes | Proje amacını detaylı bir şekilde açıklayan bir metin giriniz. Bu metin projenin temel hedeflerini ve kapsamını belirleyecektir. |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"location": {
"description": "Absolute path where cursor-rules will be created",
"type": "string"
},
"projectPurpose": {
"description": "Proje amacını detaylı bir şekilde açıklayan bir metin giriniz. Bu metin projenin temel hedeflerini ve kapsamını belirleyecektir.",
"minLength": 10,
"type": "string"
}
},
"required": [
"projectPurpose",
"location"
],
"type": "object"
}
Implementation Reference
- src/mcp/memoryBankMcp.ts:622-720 (handler)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 }; } }
- src/mcp/memoryBankMcp.ts:615-621 (schema)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') },
- src/mcp/memoryBankMcp.ts:614-721 (registration)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."); } }