Skip to main content
Glama

initialize_ide_rules

Set up IDE-specific rules for your project by creating necessary files and directories. This tool ensures AI assistants understand project conventions. Uses current working directory if no path is specified.

Instructions

Initialize IDE rules for a project. This tool sets up IDE-specific rules for a project, creating the necessary files and directories for AI assistants to understand project conventions. Note: If project_path is omitted, not a string, or invalid, the current working directory will be used automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ideNoThe IDE to initialize rules for (cursor, windsurf-next, windsurf, cline, roo, copilot)cursor
project_pathNoPath to the project. If not provided or invalid, the current working directory will be used automatically

Implementation Reference

  • Core handler function that implements the logic for initializing IDE-specific rules by creating appropriate directories and files for Cursor, Windsurf, Cline, or Copilot.
    def initialize_ide_rules(ide: str = "cursor", project_path: Optional[str] = None) -> Dict[str, Any]: """ Initialize IDE rules for a project. Args: ide: IDE to initialize rules for ("cursor", "windsurf", "cline", "copilot") project_path: Optional path to project directory Returns: Dictionary containing initialization results """ if project_path is None: project_path = os.getcwd() project_path = Path(project_path) # Create rules directory for Cursor if ide == "cursor": rules_dir = project_path / ".cursor" / "rules" rules_dir.mkdir(parents=True, exist_ok=True) # Copy default rules from installed package src_rules_dir = Path(__file__).parent / "cursor_rules" if src_rules_dir.exists(): for rule_file in src_rules_dir.glob("*.md"): shutil.copy2(rule_file, rules_dir) # Always create default rules to ensure there are files rules = [ ( "001-project-basics.md", """# Project Basics - Follow standard project structure - Use consistent coding style - Document key decisions""", ), ( "002-code-guidelines.md", """# Code Guidelines - Write clear and maintainable code - Add comprehensive tests - Keep documentation up to date""", ), ( "003-best-practices.md", """# Best Practices - Review code before committing - Handle errors appropriately - Optimize performance when needed""", ), ] for filename, content in rules: rule_file = rules_dir / filename if not rule_file.exists(): rule_file.write_text(content) return { "success": True, "initialized_rules": True, "project_path": str(project_path), "rules_directory": str(rules_dir), "templates_directory": str(project_path / ".ai-templates"), "rules_file": None, "message": f"Initialized cursor project in {project_path}", } # Create rules file for other IDEs rules_file = project_path / ( ".windsurfrules" if ide == "windsurf" else ( ".clinerules" if ide == "cline" else ".github/copilot-instructions.md" if ide == "copilot" else None ) ) if rules_file is None: return { "success": False, "error": f"Unknown IDE: {ide}", "message": "Supported IDEs are: cursor, windsurf, cline, copilot", } # Create parent directory for GitHub Copilot if ide == "copilot": rules_file.parent.mkdir(parents=True, exist_ok=True) # Write initial content rules_file.write_text( f"""# {ide.title()} Rules This file contains default rules for the {ide.title()} IDE. ## Project Organization - Place source code in src/ directory - Place tests in tests/ directory - Document APIs in docs/ directory ## Code Style - Follow PEP 8 guidelines for Python code - Use type hints for function parameters and return values - Write docstrings for all public functions and classes ## Testing - Write unit tests for new functionality - Ensure tests pass before committing changes - Maintain test coverage above 80% ## Documentation - Keep documentation up to date with code changes - Document significant design decisions - Include examples in documentation """ ) return { "success": True, "initialized_rules": True, "project_path": str(project_path), "rules_directory": None, "templates_directory": str(project_path / ".ai-templates"), "rules_file": str(rules_file), "message": f"Initialized {ide} project in {project_path}", }
  • MCP FastMCP-registered tool handler for 'initialize_ide_rules'. Performs input validation, resolves project path via get_project_settings, and delegates to the core implementation.
    @mcp.tool() def initialize_ide_rules( ide: str = Field( description=f"The IDE to initialize rules for ({', '.join(VALID_IDE_RULES.keys())})", default="cursor", ), project_path: Optional[str] = Field( description="Path to the project. If not provided or invalid, the current working directory will be used automatically", default=None, ), ) -> str: """ Initialize IDE rules for a project. This tool sets up IDE-specific rules for a project, creating the necessary files and directories for AI assistants to understand project conventions. Note: If project_path is omitted, not a string, or invalid, the current working directory will be used automatically. """ # Extract the actual value from the project_path if it's a Field if hasattr(project_path, "default"): project_path = project_path.default # Handle potentially invalid paths (empty strings, incorrect types, etc.) if project_path is not None and not isinstance(project_path, str): project_path = None # This will trigger using the current directory # Extract the actual value from ide if it's a Field if hasattr(ide, "default"): ide = ide.default # Validate IDE type if ide not in VALID_IDE_RULES: return json.dumps( { "success": False, "error": f"Unknown IDE type: {ide}", "message": f"Supported IDE types for rules are: {', '.join(VALID_IDE_RULES.keys())}", "project_path": None, }, indent=2, ) # Get project settings and parse the JSON response settings_json = get_project_settings(proposed_path=project_path) settings = json.loads(settings_json) if not settings["success"]: return json.dumps( { "success": False, "error": settings.get("error", "Failed to get project settings"), "message": "Please provide a valid project path. You can look up project path and try again.", "project_path": None, }, indent=2, ) actual_project_path = settings["project_path"] try: # Call the specialized implementation and format the result result = initialize_ide_rules_impl(ide=ide, project_path=actual_project_path) return json.dumps(result, indent=2) except Exception as e: return json.dumps( { "success": False, "error": str(e), "message": "Please provide a valid project path. You can look up project path and try again.", "project_path": None, }, indent=2, )
  • Schema definition for valid IDE types used in input validation and Field descriptions for the initialize_ide_rules tool.
    VALID_IDE_RULES = { "cursor": ".cursor/rules", "windsurf-next": ".windsurfrules", "windsurf": ".windsurfrules", "cline": ".clinerules", "roo": ".clinerules", "copilot": ".github/copilot-instructions.md", }
  • Registration of supported tools list in package __init__, including 'initialize_ide_rules'.
    SUPPORTED_TOOLS = [ "initialize_ide", "initialize_ide_rules", "get_project_settings", "prime_context", "migrate_mcp_config", "think", "get_thoughts", "clear_thoughts", "get_thought_stats", "process_natural_language", ]
  • FastMCP decorator registration of the initialize_ide_rules tool.
    @mcp.tool() def initialize_ide_rules( ide: str = Field( description=f"The IDE to initialize rules for ({', '.join(VALID_IDE_RULES.keys())})", default="cursor", ), project_path: Optional[str] = Field( description="Path to the project. If not provided or invalid, the current working directory will be used automatically", default=None, ), ) -> str: """ Initialize IDE rules for a project. This tool sets up IDE-specific rules for a project, creating the necessary files and directories for AI assistants to understand project conventions. Note: If project_path is omitted, not a string, or invalid, the current working directory will be used automatically. """ # Extract the actual value from the project_path if it's a Field if hasattr(project_path, "default"): project_path = project_path.default # Handle potentially invalid paths (empty strings, incorrect types, etc.) if project_path is not None and not isinstance(project_path, str): project_path = None # This will trigger using the current directory # Extract the actual value from ide if it's a Field if hasattr(ide, "default"): ide = ide.default # Validate IDE type if ide not in VALID_IDE_RULES: return json.dumps( { "success": False, "error": f"Unknown IDE type: {ide}", "message": f"Supported IDE types for rules are: {', '.join(VALID_IDE_RULES.keys())}", "project_path": None, }, indent=2, ) # Get project settings and parse the JSON response settings_json = get_project_settings(proposed_path=project_path) settings = json.loads(settings_json) if not settings["success"]: return json.dumps( { "success": False, "error": settings.get("error", "Failed to get project settings"), "message": "Please provide a valid project path. You can look up project path and try again.", "project_path": None, }, indent=2, ) actual_project_path = settings["project_path"] try: # Call the specialized implementation and format the result result = initialize_ide_rules_impl(ide=ide, project_path=actual_project_path) return json.dumps(result, indent=2) except Exception as e: return json.dumps( { "success": False, "error": str(e), "message": "Please provide a valid project path. You can look up project path and try again.", "project_path": None, }, indent=2, )

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/smian0/mcp-agile-flow'

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