Cursor Agent Rules for Code Modification
March 12, 2025 ยท View on GitHub
1. Pre-Edit Analysis Requirements
BEFORE making any code changes, MUST:
- Use
mcp__get_document_symbolson the target file to understand its structure - Use
mcp__find_usageson any symbol being modified to identify all affected locations - Use
mcp__get_type_definitionand/ormcp__go_to_definitionfor any types or symbols being modified - Use
mcp__get_hover_infoto verify function signatures and type information
2. Impact Analysis Rules
BEFORE proceeding with changes:
-
If
mcp__find_usagesreveals usage in multiple files:- Must analyze each usage context
- Must verify type compatibility across all uses
- Must plan changes for all affected locations
-
If modifying interfaces or types:
- Must use
mcp__find_implementationsto locate all implementations - Must ensure changes won't break implementing classes
- Must verify backward compatibility or plan updates for all implementations
- Must use
3. Type Safety Rules
MUST maintain type safety by:
-
Using
mcp__get_type_definitionfor:- All modified parameters
- Return types
- Interface members
- Generic constraints
-
Using
mcp__get_hover_infoto verify:- Function signatures
- Type constraints
- Optional vs required properties
4. Code Modification Sequence
When making changes:
- First gather context:
// Example sequence
await mcp__get_document_symbols(file)
await mcp__find_usages(symbol)
await mcp__get_type_definition(symbol)
await mcp__get_hover_info(symbol)
- Then analyze impact:
// For each usage found
await mcp__get_hover_info(usage)
await mcp__get_type_definition(relatedTypes)
- Only then use
edit_file
5. Post-Edit Verification
After making changes:
- Use
mcp__get_document_symbolsto verify file structure remains valid - Use
mcp__find_usagesto verify all usages are still compatible - Use
mcp__get_hover_infoto verify new type signatures
6. Special Cases
When Modifying React Components:
-
Must use
mcp__find_usagesto:- Find all component instances
- Verify prop usage
- Check for defaultProps and propTypes
-
Must use
mcp__get_type_definitionfor:- Prop interfaces
- State types
- Context types
When Modifying APIs/Functions:
- Must use
mcp__get_call_hierarchyto:- Understand the call chain
- Identify dependent functions
- Verify changes won't break callers
When Modifying Types/Interfaces:
- Must use
mcp__find_implementationsto:- Locate all implementing classes
- Verify compatibility
- Plan updates if needed
7. Error Prevention Rules
- NEVER modify a symbol without first:
await mcp__find_usages(symbol)
await mcp__get_type_definition(symbol)
- NEVER modify a type without:
await mcp__find_implementations(type)
await mcp__get_hover_info(type)
- NEVER modify a function signature without:
await mcp__get_call_hierarchy(function)
await mcp__find_usages(function)
8. Documentation Requirements
When explaining changes, must reference:
- What tools were used to analyze the code
- What usages were found
- What type information was verified
- What impact analysis was performed
Example:
I analyzed the code using:
1. mcp__find_usages to locate all 5 usages of handleSubmit
2. mcp__get_type_definition to verify the function signature
3. mcp__get_hover_info to check parameter types
4. mcp__get_document_symbols to understand the component structure
9. Change Abort Conditions
Must ABORT changes if:
mcp__find_usagesreveals unexpected usagesmcp__get_type_definitionshows incompatible typesmcp__find_implementationsshows breaking changes- Unable to verify full impact using available tools
10. Tool Priority Order
When analyzing code, use tools in this order:
mcp__get_document_symbols(understand structure)mcp__find_usages(understand impact)mcp__get_type_definition(verify types)mcp__get_hover_info(verify signatures)- Additional tools as needed