python

A set of writing and programming rules for Python and FastMCP, a Python toolkit for building MCP servers.

In plain words
What is it for?
Creating or editing Python MCP servers with modular files, asynchronous external calls, and object-based inputs and results.
Why use it?
It gives an agent consistent guidance for code structure, naming, type hints, and handling input and output.

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/quincymillerdev/ilograph-mcp-server/python
Clone the repo
git clone --depth 1 https://github.com/QuincyMillerDev/ilograph-mcp-server

Made for: Cursor.

Per session 1,189 This file is loaded in full into every session.
When invoked 1,189 The same file — it is already loaded in full.
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.01189 $0.01189
Opus 5 $0.00594 $0.00594
Sonnet 5 $0.00238 $0.00238
Haiku 4.5 $0.00119 $0.00119

Measured yesterday against content hash 4702c121ffa5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python 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 yesterday.

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/python.mdc · 125 lines

How it starts

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

You are an expert in Python, FastMCP, and scalable MCP server development.

Key Principles

  • Write concise, technical responses with accurate Python examples.
  • Use functional, declarative programming; avoid classes where possible except for custom error types.
  • Prefer iteration and modularization over code duplication.
  • Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).
  • Use lowercase with underscores for directories and files (e.g., tools/data_tools.py).
  • Favor named exports for tools, resources, and utility functions.
  • Use the Receive an Object, Return an Object (RORO) pattern where applicable.
  • DO NOT MAKE ASSUMPTIONS

Python/FastMCP

  • Use def for function definitions with proper type hints.
  • Use type hints for all function signatures where possible.
  • File structure: MCP server initialization, tools, resources, prompts, utilities, config.
  • Avoid unnecessary curly braces in conditional statements.
  • For single-line statements in conditionals, omit curly braces.
  • Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).
  • Prefer async/await for I/O operations and external API calls.

Error Handling and Validation

  • Prioritize error handling and edge cases:
    • Handle errors and edge cases at the beginning of functions.
    • Use early returns for error conditions to avoid deeply nested if statements.
    • Place the happy path last in the function for improved readability.
    • Avoid unnecessary else statements; use the if-return pattern instead.
    • Use guard clauses to handle preconditions and invalid states early.
    • Implement proper error logging and user-friendly error messages.
    • Use custom error types or error factories for consistent error handling.
    • Handle MCP protocol errors gracefully and return meaningful responses.

Dependencies

  • FastMCP (core MCP server framework)
  • Pydantic (for data validation and serialization)
  • httpx or aiohttp (for async HTTP requests)
  • pathlib (for file system operations)
  • typing (for advanced type hints)

FastMCP-Specific Guidelines

  • Use FastMCP decorators for exposing functionality:
    • @mcp.tool() for executable functions (like POST endpoints)
    • @mcp.resource() for data exposure (like GET endpoints)
    • @mcp.prompt() for reusable interaction templates
  • Organize MCP capabilities using clear separation of concerns.
  • Use descriptive names for tools, resources, and prompts that clearly indicate their purpose.
  • Implement proper docstrings for all MCP-exposed functions as they serve as descriptions.
  • Use FastMCP's built-in validation and error handling capabilities.
  • Leverage FastMCP's automatic protocol handling rather than implementing low-level MCP details.
  • Use FastMCP's client capabilities for server-to-server communication when needed.
  • Implement proper logging using Python's logging module.

Performance Optimization

  • Use async/await for I/O-bound operations to avoid blocking.
  • Implement caching for frequently accessed resources.
  • Use connection pooling for external API calls.
  • Implement proper session management for stateful operations.
  • Use background tasks for time-consuming operations when appropriate.
  • Consider resource lifecycle management (setup/teardown) for expensive resources.

Key Conventions

  1. Use clear, descriptive function names that indicate the tool/resource purpose.
  2. Prioritize MCP server performance metrics (response time, resource availability).
  3. Structure the application:
    • Use modular organization for different capability areas.
    • Implement clear separation between tools, resources, and business logic.
    • Use environment variables for configuration management.
    • Group related functionality into logical modules.

Data Handling and Validation

  • Use Pydantic models for complex data structures and validation.
  • Implement proper input validation for all tool parameters.
  • Use type hints extensively for better IDE support and runtime validation.
  • Handle different data formats (JSON, text, binary) appropriately.

Read the full file on GitHub · 125 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. yesterday First seen · 125 lines · 1,189 tokens per session scan A 4702c121ffa5

Subscribe to this mod's changes

python is a cursor rule published in the GitHub repository QuincyMillerDev/ilograph-mcp-server (3 stars, last pushed 10mo ago), licensed MIT. It adds 1,189 tokens to every session, about $0.0059 per session on Opus 5. 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-31.