Cursor Rules .mdc Files

Purchase the course to access all content

Cursor Rules .mdc Files

Hey, welcome back. In the last lesson we did a quick start, migrate from the old cursor rules to the new cursor rules. Now we take a step back and talk about the .mdc file. Basically nothing special. It's a markdown file, so you can also write, for example, UI .mdc or let's say the TypeScript .mdc file. Like MD. And you can write here a header. Header is kind of a yaml front meta. This is usually at the top. And you can give there a short description and specify also the filepad, the globs. Let me do that. Description, this file or you are my TypeScript expert. And then you can write globs. Let's just add here to a bit more complex scenario. Say you have here a lib and then you have here a, let's say a utils TypeScript file, export default, the function before, const, narrate, meal plan, days, map days before, const, and you get the idea. I could enable here the cursor tab to help me, I guess. And then we have here the day, day in the meals, my floor of random export meal plan. Good. So we have here the utils and let's create here a index TS with just a console log, hello world. And let's add two. Let's hit that right here, console warn and console the log. And then let me write maybe just a warn and tier two. Yeah. Thank you. In the index TS, we have three logs, warn, error, and log. And in the utils TS, we have a warn and the log. Error here too. Okay. Yeah. You will see why I've written such a strange console logs here. Now go back to our TypeScript MD file. And let's say we want to start from the lib folder and add all or include all TS files here. Meaning that we exclude explicit this index TS, not explicit, but this will be a, it will be excluded. So we are just looking in the lib folder. Okay. And then we write always transform console warn and console error to console log. So the idea is that we don't use any warn and error logs, just console log log. Okay. So this should be changed here, but not this. And I want to try this now and let's go back to the TypeScript MD. And again, this header tells cursor when to use these rules for files in lib TS. And it gives a human friendly discussion. So the AI uses this to decide which rules, which rule files are relevant at any time. And if you want to apply it globally, you can leave the globs like so sorry, just okay. Let's undo this and let's try it first. But for this, we need to rename it to this .mdc file. So let's rename it .mdc enter. And you can see that this description has been transformed to description globs. So it is now part of the user interface. And that's probably, I guess, the only reason why it's been called .mdc because it could also be MD. It's still markdown, but this is something I want that you understand that we're writing basically markdown here. The interesting part is we could try it with MD too. Let's check it. Let's check it if MD works. So hit up a new composer, go into your utils and hey, do we need to update something regarding console? Yeah, good. Now let's switch back to seek R1 and let's look at the thinking step. Please again, the user wants me. Yeah, let's wait until this is finished. I need to make sure I follow the cursor rules. The general MD rule says to add here, I'm your front and body. Yep, this is the general one. Also if CSS has changed here, let's not apply to it. And cursor is already getting it, but this is type script. So that part doesn't apply here. Mm hmm. Here in the message. Good. Yeah, it doesn't work. So you need to rename it to .mdc. Here, reject this one here and that should, the icon is just wrong, but it should work. Let's try this one again. Let's hit up a new composer, go to utils, change, keep the deep seek R1. Should we do something about console? Yeah. And you can see the cursor rule mentioned the TypeScript .mdc rule that says to always transform console warn and console error to console log. So now it's getting it. And it will probably replace it to log. Okay, reject it and do the same now for this index. Let's try it again. Add a new composer because to have fresh context and write, hey, do we need to change something here in our running console? Yeah. You can see that the cursor rule is not applying now because we have excluded or we have just included here the lib TS. With this globs, you can define folder file extensions. This is pretty nice that we can fine tune our rules now. That's in this specific way. Let's go back to the index. Yeah, it just wants that it's been removed, but we ignore this and perfect. So I think you have seen now a bit behind the scene how it's working. Now let's go back to the TypeScript .mdc. And since we are working with Markdown, we can use Markdown to form our prompts because what happens here? We are manipulating or we are just adding something to the system prompt. Meaning, and you can see it in this thinking step, every time we send some requests with chat composer or the agent mode, add a new composer here, or with the agent mode, all these rules get applied and added and been added to the context. So we are changing this prompt and we can use Markdown. So let's define our rules. For example, we can say we want type safety rules or kind of best practices, enable strict mode, which kind of catches errors early. We don't need to define this. Just enable strict mode and avoid implicit any, which define types to maintain this clarity. Okay, before moving on, let's summarize this session. The benefit of this system is granularity and also organization, especially in logical basis. So each rule file here can focus on one aspect. For example, one for the JavaScript, one for the styles, you can even create one for documentation styles. So let's write here, always use Markdown for documentation, avoid bold asterisks in Markdown and so on. So it's not only tied to any language or programming language. You can add it to kind of every extension you can think of and you want to guide the AI that it makes it better. And this separation keeps your instructions tidy and project specific. And since these files are in your project, you can also add this to your repository. You can version control them and share it with your team. So everyone using cursor on that project will benefit from the same rule set. That's amazing. I mean, that was already possible with the cursor rules before, but now you can really set up some really cool specific rules for each files or folders, whatever. Good, let's recap it. We have multiple context specific rules, then no more one size fits all is being removed. So the cursor rules are getting removed. You can have now different instructions for different languages, frameworks or parts of your project. All right, so in this lesson, we have learned how we define and write our rule files and let's see in the next lesson.

Kevin Kernegger

Full Course - Early Access

Discount for the first 100 students