Learn how to set up Cursor MDC files to streamline and standardize project rules effectively. This guide walks you through creating and applying MDC files, highlights best practices, and explains why this modern structure is preferred over the deprecated Cursor rules format.
Prerequisites for Using Cursor MDC Files
Before starting, ensure the following prerequisites are met to successfully use Cursor MDC files:
prerequisites
- Cursor Software: Ensure Cursor is installed and properly configured in your development environment.
- Project Knowledge: Familiarize yourself with your project's structure and naming conventions.
- Programming Patterns: Understand common coding patterns or architectures used in your project.
Steps to Set Up MDC Files
Defining Cursor MDC files enables you to configure project-specific rules in a modular and scalable way. Follow these steps to set up MDC files effectively:
steps
Navigate to Your Project Directory:
- Open a terminal and navigate to the directory of your project where you want to create the .mdc files.
bashcd path/to/your/projectCreate a New MDC File:
- Use a text editor or integrated development environment (IDE) to create a file with the
.mdcextension.
- Use a text editor or integrated development environment (IDE) to create a file with the
Add Metadata to the MDC File:
- Include metadata at the top of the file to describe its purpose.
yaml--- name: Rule Name description: A brief description of this rule. ruleType: autoattach globs: - "**/*.ts" ---Define Patterns and Actions:
- Add detailed instructions or code templates for the AI to follow.
yamlpatterns: - "const fetchData = async () => { ... }" actions: - name: "fetchData" description: "Standard template for asynchronous data fetching" code: | const fetchData = async () => { const response = await apiClient.get('/endpoint'); return response.data; };Document Good Practices and Validations:
- Use the MDC file to describe best practices, actions, or validations specific to your project.
yamlvalidations: - "Use proper TypeScript types for API responses." - "Ensure actions are documented for clarity."Save and Integrate The File:
- Save the .mdc file. If you are using a version control system such as Git, ensure to commit it for team-wide usage.
Test the Rules:
- Use Cursor to verify that the new rules are properly attached (manually or automatically) and guiding AI behavior as intended.
Common Patterns and Practices for MDC Files
When constructing MDC files, consider the following configurations to optimize your rules for AI use:
Metadata: Clearly define key details such as the rule's name, a concise description of its purpose, the rule type (e.g., always-attach, autoattach, agent-requested, manual), and any globs that specify applicable file patterns.
Patterns and Examples: Use straightforward patterns and examples to illustrate best practices for the AI.
Logical Grouping: Group related rules into separate MDC files based on their functional areas or features for clarity and scalability.
Avoid Redundancy: Exclude unnecessary metadata (e.g., redundant globs) to keep MDC files concise and focused.
Advantages of MDC Files Over Deprecated Cursor Rules Format
MDC files offer significant benefits over the old monolithic Cursor rules format:
comparison
Old Format: Cursor Rules
- A single, large file combining all rules.
- Difficult to maintain as project grows.
- High processing cost when passed to the AI.
New Format: MDC Files
- Modular rules improve manageability and organization.
- Easier to update and refine rules specific to a feature or context.
- Optimized for AI efficiency by focusing on relevant rule subsets.
FAQ
What are Cursor MDC files?
Cursor MDC files are modular configurations used to define coding patterns, best practices, actions, and validations within a project. They replace the monolithic Cursor rules files, offering better scalability and manageability.
How do I apply MDC files in a project?
You can apply MDC files in a project by saving them in your project directory and using Cursor's manual or automatic context attachment modes to link the rules with the corresponding files or scenarios.
What are typical use cases for MDC files?
MDC files are commonly used to define project-specific coding patterns, such as API route structures, validations, or common actions like form handling, data fetching, or feature-specific setups.
Official reference: Cursor documentation.