Skip to content
Languages

Rust AGENTS.md

Rust agents reach for unwrap when a type error gets uncomfortable. This file tells the agent to return Result from library code, to format with rustfmt, and to run cargo test before it finishes.

Paste, then editRust MCP servers

Name the crate if the workspace has more than one, so cargo test does not surprise you with a second package.

In this stack

What to tell the agent

Do

  • Name the workspace crates the agent is allowed to edit.
  • Say whether this repo commits Cargo.lock (applications do, many libraries do not).
  • Ask for a unit test next to the function when the change is pure.
  • Point at the error type the crate already uses.

Leave alone

  • Adding unwrap on a path that handles user or network input.
  • Cloning your way out of a borrow without saying why the clone is the API.
  • Editing Cargo.toml edition or rust-version as part of a small fix.
Starter file

AGENTS.md to copy

Save this as AGENTS.md at the root of the repository, or next to the package it covers. Replace the commands with the ones in this repo. See which agents read the file.

AGENTS.md
# Rust

## Errors
- Library functions return Result. unwrap and expect belong in tests and in the outermost binary, with a message that names the invariant.
- Do not silence a warning with #[allow] unless the task explains why the lint does not apply.

## Style
- Format with cargo fmt. Clippy is the lint. Do not add another.
- Keep unsafe blocks tiny and comment the invariant that makes them sound.

## Checks
- cargo fmt --check
- cargo clippy --all-targets -- -D warnings, when the repo already denies warnings.
- cargo test, or cargo test -p the-crate in a workspace.

## Leave alone
- Do not bump dependency versions across the workspace for an unrelated fix.
- Do not rewrite a public trait to make one call site shorter.
Commands to confirm

Checks named in the file

Confirm each command exists here before you rely on it. Delete the ones this repository does not use.

  • Format check. cargo fmt --check
  • Lint. cargo clippy --all-targets -- -D warnings
  • Tests. cargo test
FAQ

Questions

What is the Rust AGENTS.md for?

It keeps a Rust agent on cargo fmt, clippy, and Result instead of unwrap in library paths.

When is unwrap acceptable in Rust agent instructions?

In tests, and in a binary's main when the failure should stop the program and the message names what was assumed. Library code that parses input returns a Result.

Which Cargo commands should AGENTS.md list?

fmt, the clippy invocation CI uses, and cargo test. In a workspace, name the package with -p so the agent does not treat another crate's failure as its own.

Keep going

Related on MCPpedia