Back to Resources

When to Use MDC Files

Learn when and how to effectively use MDC files in your AI development workflow.

Enforcing Coding Standards

  • When to Use: Your project has specific coding conventions, such as preferring const for immutable variables in TypeScript or enforcing a particular function syntax.
  • Why: MDC files guide the AI to suggest code that follows these standards, ensuring consistency across your codebase.
  • Example: An MDC file for TypeScript files (**/*.ts) can enforce using const and requiring explicit return types.

Framework-Specific Guidelines

  • When to Use: You're working with a framework like React, Vue, or Django, and want the AI to follow best practices or team preferences specific to that framework.
  • Why: MDC files can specify framework-related rules, such as preferring functional components in React or using hooks for state management.
  • Example: An MDC file for React components (src/components/*.jsx) can ensure suggestions use functional components and proper prop typing.

Testing Conventions

  • When to Use: Your project follows specific testing practices, like using Jest for unit tests or targeting a minimum code coverage percentage.
  • Why: MDC files help the AI suggest test structures that match your established testing standards.
  • Example: An MDC file for test files (**/*.test.ts) can enforce Jest usage and a consistent test organization.

Project-Wide Conventions

  • When to Use: You have general practices that apply across the entire project, such as naming conventions, indentation rules, or documentation requirements.
  • Why: MDC files with broad glob patterns (e.g., **/*) ensure the AI applies these rules universally.
  • Example: A project-wide MDC file can mandate 4-space indentation and JSDoc comments for public APIs.

Directory-Specific Rules

  • When to Use: Certain directories or file types in your project have unique requirements, like components in a specific folder following distinct patterns.
  • Why: MDC files let you target specific parts of your codebase with precise glob patterns for tailored guidance.
  • Example: An MDC file for src/components/ can enforce component-specific rules, while one for src/utils/ focuses on utility functions.

Migrating from Older Rule Systems

  • When to Use: Your project is moving from an older rule system, like .cursorrules, to the more flexible MDC format.
  • Why: MDC files provide granular control with multiple files and glob patterns, making them ideal for complex projects.
  • Example: Replace a single .cursorrules file with multiple MDC files targeting specific file types or directories.

When Not to Use MDC Files

  • No Clear Standards: If your project lacks defined coding standards, MDC files may not add much value.
  • Overcomplication: Too many MDC files with overlapping or conflicting rules can confuse the AI and produce inconsistent suggestions.
  • Simple Projects: For small projects with minimal customization needs, the AI's default behavior might be sufficient.

Summary

Use MDC files when you need to:

  • Customize the AI's suggestions to match specific coding standards, framework guidelines, or testing practices.
  • Provide context about your project's structure, such as directory-specific rules.
  • Maintain consistency across your codebase with project-wide conventions.
  • Transition from older rule systems like .cursorrules to a more precise and flexible setup.

By applying MDC files in these situations, you can make Cursor's AI assistance more accurate, relevant, and aligned with your team's development practices.