brainax

Context: rules file and MCP

Lesson 20 of 26 in the course “Vibe coding”. Free, with animations and a quiz.

The agent forgets everything

Yesterday you explained to the agent how your workout tracker works. Today it's a new session, and it knows nothing again. Context is everything the agent sees right now: your message, the open files and the instructions. Between sessions it usually remembers nothing. The fix is simple: write the essentials into a file inside the project. The agent reads it by itself when it starts. That file is on the left of the diagram.

AGENTS.md and its relatives

AGENTS.md is an open format: a plain text file in the root of the project, meaning its main folder. Many agents read it. Claude Code reads its own CLAUDE.md, and Cursor has its own rules files. The idea is the same everywhere: a cheat sheet for a new team member. The .md ending means Markdown, plain text with headings and lists. You can keep one main file and simply point to it from the others.

What to put in it

The four lines in the diagram are the basics. Project: one sentence on what it is and who it's for. Run: the command that starts the site on your computer, for example npm run dev. Tests: the command for checks, for example npm test. Never: keys in code, commits straight to main. You can add style rules: “clear names, texts in English”. It's like a note for the next person on your shift: short and to the point.

Short and true

A file ten screens long does harm: it eats up context, and the important stuff gets lost among details. A file that's wrong is even worse. It says npm start, but the project runs with npm run dev? The agent will keep making mistakes. Changed something in the project? Update the file or ask the agent to “update AGENTS.md with what we did”. And no keys in it: the file lives in Git, and Git remembers everything.

MCP: plug sockets for the agent

MCP (Model Context Protocol) is a standard way to plug services and tools into an agent. Think USB: one connector shape, lots of different devices. On the right of the diagram are three plugs. GitHub: the agent reads tasks and PRs. Database: it looks at the data tables. Browser: it opens your site and clicks the buttons itself. Each such connection is called an MCP server.

Plug in wisely

An MCP server gets access to everything you open up to it. Install only trusted ones: from the service itself or from well-known projects. Give the minimum rights: read-only access to the database, ideally to a test copy rather than real user data. The trap: text the agent reads through MCP, like a web page, can hide commands meant for the AI. So you still approve the risky actions yourself.

Check yourself

  1. Why does a project have an AGENTS.md file?
    Correct answer: The agent reads it to learn the project's rules. The agent forgets between sessions, and the rules file gives it the essentials: what the project is, how to run it, what's off limits. Never put keys there: the file is in Git.
  2. What is MCP?
    Correct answer: A standard for plugging services into an agent. MCP is like USB for an agent: GitHub, a database, a browser and other tools all plug in the same way.
  3. You connect a database to the agent via MCP. What's the right way?
    Correct answer: Give minimum rights, for example read-only. The fewer the rights, the less damage from an agent mistake or a hidden command. A test copy beats real user data.

← A map of AI agents Bugs: reading the error →