python

A set of coding rules for Python projects built around the Cycloid MCP Server architecture. MCP is a standard way for an AI agent to call external tools.

In plain words
What is it for?
Use it when writing or reviewing Python code for the Cycloid MCP Server, especially handlers and MCP server components.
Why use it?
It gives the agent consistent patterns for handlers, imports, types, error handling and naming. This reduces disagreements between new code and the server's existing structure.

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

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 667 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.00667
Opus 5 $0.00000 $0.00333
Sonnet 5 $0.00000 $0.00133
Haiku 4.5 $0.00000 $0.00067

Measured yesterday against content hash 29aab784f8dc, 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 · 67 lines

What it actually says

You are an expert in Python and MCP server development, specifically for the Cycloid MCP Server with its optimized architecture.

Key Principles

  • Write concise, technical responses with accurate Python examples using our optimized patterns
  • Use BaseHandler inheritance for all handlers (from src.base_handler)
  • Import types from src.types instead of typing directly (JSONDict, JSONList, etc.)
  • Use @handle_errors decorator for consistent error handling
  • Apply proper import organization: stdlib → third-party → local → relative
  • Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission)
  • Use lowercase with underscores for directories and files (e.g., components/stacks/stacks_handler.py)
  • Favor composition with BaseHandler over deep inheritance hierarchies
  • Use the Receive an Object, Return an Object (RORO) pattern with proper typing

Architecture Patterns (CYCLOID MCP SERVER SPECIFIC)

  • Handler Pattern: All handlers inherit from BaseHandler and get self.cli, self.logger automatically

  • Type Safety: Use centralized types from src.types (JSONDict, JSONList, CliFlags, etc.)

  • Error Handling: Use @handle_errors decorator with descriptive actions and suggestions

  • CLI Integration: Use execute_cli_command with auto_parse parameter

  • Memory Optimization: Use conditional debug logging and proper resource management

Error Handling and Validation

  • Use @handle_errors decorator from src.error_handling for consistent error handling:
    • Provide descriptive action names: @handle_errors(action="validate configuration")
    • Include helpful suggestions: suggestions=["Check syntax", "Verify fields"]
    • Let decorator handle CycloidCLIError vs Exception automatically
  • 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
  • Use self.logger (provided by BaseHandler) for consistent logging

Type Safety (CENTRALIZED TYPES)

  • Import common types from src.types instead of typing directly:
    • Use JSONDict instead of Dict[str, Any]
    • Use JSONList instead of List[Dict[str, Any]]
    • Use CliFlags instead of Dict[str, Union[str, bool]]
    • Use OptionalString instead of Optional[str]
  • Avoid Any usage - prefer specific type aliases from src.types
  • Use ElicitationResult, StackCreationParams for complex operations

Dependencies

  • fastmcp (FastMCP 2.0)
  • pydantic (for configuration and validation)
  • Python 3.12+

Performance Optimization

  • Use conditional debug logging to prevent unnecessary string creation: if logger.isEnabledFor(logger.DEBUG): logger.debug(...)
  • Apply @lru_cache only for static data (configuration discovery)
  • NEVER cache CLI API responses (dynamic data that changes)
  • Use tempfile.NamedTemporaryFile(delete=True) for automatic resource cleanup
  • Use execute_cli_command with auto_parse parameter to avoid duplication
  • Minimize blocking I/O operations; use asynchronous operations for all CLI calls
  • Use proper resource management with context managers
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 · 67 lines · 667 tokens per session scan A 29aab784f8dc

Subscribe to this mod's changes

python is a cursor rule published in the GitHub repository cycloidio/cycloid-mcp-server (0 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 667 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-31.