001_rust

Rust coding and architecture rules for tfmcp, a command-line tool that connects AI assistants with Terraform infrastructure management.

In plain words
What is it for?
Use them when writing or reviewing Rust code in tfmcp, including formatting, public documentation, error types, module organization, and safe use of Rust features.
Why use it?
They reduce inconsistent code and make error handling, documentation, formatting, testing, and project structure more predictable.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nwiizo/tfmcp/001_rust
Clone the repo
git clone --depth 1 https://github.com/nwiizo/tfmcp

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 477 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00477
Opus 5 $0.00000 $0.00238
Sonnet 5 $0.00000 $0.00095
Haiku 4.5 $0.00000 $0.00048

Measured 2d ago against content hash a3d9c2240c73, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

001_rust scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/001_rust.mdc · 64 lines

How it starts

The opening of the file, as written. The whole thing — 64 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rust Coding Style Guide

Code Style

  • Follow the Rust style guide as enforced by rustfmt and cargo fmt.
  • Use 4 spaces for indentation, not tabs.
  • Maximum line length is 100 characters.
  • Always run cargo fmt before committing code.

Error Handling

  • Use Result and Option types appropriately.
  • Propagate errors with the ? operator where appropriate.
  • Create custom error types in modules with complex error handling.
  • Use thiserror for defining error types.
  • Use anyhow for error propagation in application code.

Documentation

  • Document all public functions, methods, and types with rustdoc comments.
  • Include examples in documentation when useful.
  • Document complex or non-obvious code sections.

Best Practices

  • Prefer immutable variables (let instead of let mut) when possible.
  • Use strong typing rather than type aliases for clarity.
  • Leverage Rust's ownership system properly.
  • Avoid unsafe code unless absolutely necessary.
  • Use clippy to catch common mistakes.

Rust Architecture Guidelines

Project Structure

  • Follow the modular structure in src/:
    • core/: Core tfmcp functionality and abstractions
    • mcp/: Model Context Protocol implementation
    • terraform/: Terraform integration services
    • config/: Configuration handling
    • shared/: Shared utilities

Module Organization

  • Each module should have a clear, single responsibility.
  • Public APIs should be exposed through the module's mod.rs or lib.rs.
  • Keep implementation details private whenever possible.
  • Use feature flags for optional functionality.

Dependencies

  • Be conservative with external dependencies.
  • Evaluate new dependencies carefully:
    • Is it actively maintained?
    • Is it widely used/trusted?
    • Would it be better to implement the functionality ourselves?
  • Pin dependency versions in Cargo.toml for reproducible builds.

Asynchronous Programming

  • Use async/await for asynchronous code.
  • Use tokio for async runtime.
  • Be careful with blocking operations in async contexts.
  • Consider using channels for communication between components.

Read the full file on GitHub · 64 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 64 lines · 477 tokens per session scan A a3d9c2240c73

Subscribe to this mod's changes

001_rust is a cursor rule published in the GitHub repository nwiizo/tfmcp (371 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 477 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.