mcp-best-practices

mcp-best-practices is a cursor rule for coding agents from steipete/agent-rules. It costs 0 tokens per session (2,231 once invoked), scanned A, original, MIT.

A set of guidelines for building Model Context Protocol (MCP) tools, which let AI applications call functions provided by another program.

In plain words
What is it for?
Use it when defining tool names, parameter descriptions, defaults, input handling, error messages, and dynamic version information.
Why use it?
It helps make tools easier for agents and developers to understand, configure, and recover from errors when inputs or runtime conditions vary.

Cursor rule

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/steipete/agent-rules/mcp-best-practices
Clone the repo
git clone --depth 1 https://github.com/steipete/agent-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,231 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.02231
Opus 5 $0.00000 $0.01115
Sonnet 5 $0.00000 $0.00446
Haiku 4.5 $0.00000 $0.00223

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

Security

Grade A, and why

mcp-best-practices 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 3d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

docs/mcp-best-practices.mdc · 123 lines

How it starts

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

MCP Best Practices - May 26, 2025

I. General Tool Configuration & Behavior

  1. Sensible Defaults: All environment variables must have sensible defaults for easy out-of-the-box usage.
  2. Dynamic Versioning: The tool's version is emitted in its description. This version must be read dynamically (e.g., from package.json) and not hardcoded.
  3. Tool & Parameter Descriptions:
    • Tool Titles: Use descriptive, human-friendly titles for tools.
    • Parameter Descriptions: All parameters must offer a clear description.
    • Optional/Required Parameters: Parameters must be explicitly noted as "optional" or "required."
    • Default Values: If a parameter is optional, its default value must be explained.
    • (These details should be verifiable by hovering over the tool in clients like Cursor or using the MCP inspector.)
  4. Parameter Parsing: Parameter parsing should be lenient (e.g., accept path if project_path is formally defined). Generally, advertise stricter schemas but be more lenient in execution to accommodate variations from agents.
  5. Runtime Error Handling: In case of an error, emit a helpful message to the caller with information to potentially recover.
  6. Configuration Error Handling: Misconfigurations (e.g., wrongly set environment variables) must not crash the tool. Instead, provide a useful explanation when the tool is run, enabling the user to self-correct their setup.
  7. No stdio Output: CRITICAL: There must be absolutely NO output to stdout or stderr during any tool operation. This includes:
    • No console.log(), console.error(), console.warn(), etc.
    • No process.stdout.write() or process.stderr.write()
    • No print statements or debug output to stdio
    • Even during errors or initialization, all output must go through the file logger
    • Any stdio output will disrupt MCP clients (like Claude) and cause loading errors
    • File-based logging (e.g., Pino to log files) is the only acceptable method for operational output
  8. info Command:
    • At least one tool must offer an info sub command (find the most appropriate tool and add there)
    • This command shall list:
      • The version of the MCP tool.
      • The status of any required native dependencies (if applicable), including tests for their presence and functionality.
      • Any detected configuration issues or missing environment variables (e.g., problems with the logger path).

II. Logging (Pino)

  1. Default File Logger: Pino is used for logging with a default file logger in the system's log directory (e.g., ~/Library/Logs/). The log file path is configurable via the [ProjectName]_LOG_FILE environment variable.
  2. Log Path Resilience:
    • Pino logic must automatically create missing parent directories for the specified log file path.
    • If pino cannot write to the [ProjectName]_LOG_FILE path, it must fall back to logging to the default temporary directory path.
  3. Configurable Log Level: The log level is set using the [ProjectName]_LOG_LEVEL environment variable (accepts upper, lower, or mixed case values).
  4. Optional Console Logging: An environment variable, [ProjectName]_CONSOLE_LOGGING=true, enables logging to the console in addition to the pino file logger.
  5. Logger Flush: The logger must be flushed before the process exits to ensure all log messages are written.

III. Code, Dependencies & Build

  1. Dependency Management: All dependencies should be kept at their latest stable versions. (The release script will warn for outdated dependencies).
  2. Static Analysis: There must be no linter (e.g., ESLint) or TypeScript errors.
  3. File Size: No single file should exceed 500 lines of code (LOC); aim for below 300 LOC.
  4. Execution with Compiled Code: The startup logic and all tool operations must always use the compiled JavaScript output (e.g., from the dist folder).
  5. Shebangs: Compiled JavaScript files intended for direct execution must have the correct shebang (e.g., #!/usr/bin/env node).
  6. NPM Package Contents: The published npm package must contain only the absolute minimum files: the dist/ folder, any potential native components, the README.md, and a LICENSE file.

Read the full file on GitHub · 123 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. 3d ago First seen · 123 lines · 0 tokens per session scan A 2e20f0cee257

Subscribe to this mod's changes

mcp-best-practices is a cursor rule published in the GitHub repository steipete/agent-rules (5,695 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,231 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.