Fundamentals 10 min read

Mastering Cursor AI: Advanced Rules, MCP, Commands, and Modes Explained

This guide walks you through Cursor AI’s advanced configuration—covering core features, custom Rules, the Model Context Protocol (MCP), user‑defined Commands, and switchable Modes—while showing practical Spring Boot and refactoring cases and quantifying efficiency gains.

Xike
Xike
Xike
Mastering Cursor AI: Advanced Rules, MCP, Commands, and Modes Explained

Cursor AI is an AI‑enhanced development platform that can be deeply customized to fit personal workflows. This guide explains how to configure its core advanced features, including Rules, MCP, Commands, and Modes.

Core Features Overview

AI Chat – sidebar conversation that understands project context (shortcut: Cmd+L)

Inline Edit – generate or modify code directly (shortcut: Cmd+K)

Composer – multi‑file collaborative editing (shortcut: Cmd+I)

Tab Completion – intelligent code completion (shortcut: Tab)

@ Reference – precise file or code reference (shortcut: @)

1. Rules: Custom AI Behavior

Rules define the AI’s behavior and coding style. The rule files live under .cursor/rules/ in the project root:

project-root/
├── .cursor/
│   └── rules/
│       ├── default.md      # default rules
│       ├── java.md         # language‑specific rules
│       └── project-specific.md # project‑specific rules

Example .cursor/rules/java.md for a Spring Boot project:

# Java Project Development Guidelines

## Project Info
- Framework: Spring Boot 3.2
- Java version: 17
- Build tool: Maven

## Code Conventions
### Naming
- Class: PascalCase (UserService)
- Method: camelCase (getUserById)
- Constant: UPPER_SNAKE_CASE

### Required Practices
1. Use Lombok for all entity classes
2. Controllers only handle validation and response wrapping
3. Services contain business logic and transaction management
4. Use Optional for potentially null returns

### API Design
GET    /api/v1/users   # list users
POST   /api/v1/users   # create user
PUT    /api/v1/users/{id} # update user
DELETE /api/v1/users/{id} # delete user

### Response Format
```json
{
  "code": 200,
  "message": "success",
  "data": { ... }
}
```

### Rules Best Practices
✅ Recommended:
- Make rules specific and clear
- Include positive and negative examples
- Update regularly

❌ Avoid:
- Overly generic rules
- Conflicting rules

2. MCP: Model Context Protocol

MCP lets Cursor interact safely with external tools and services. Create ~/.cursor/mcp.json to declare servers:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/projects"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost:5432/mydb"]
    }
  }
}

Common servers and their purposes:

filesystem – file operations

github – GitHub API access

postgres – PostgreSQL database interaction

git – Git commands

fetch – web page scraping

Example usage in a Cursor prompt:

使用 @filesystem 读取当前目录的 package.json
使用 @github 创建一个新的 issue

3. Commands: Custom Commands

Built‑in commands: /help – show help /clear – clear chat history /search – search code /problems – view problems

To add custom commands, create ~/.cursor/commands.json:

{
  "commands": {
    "review": {
      "description": "代码审查",
      "prompt": "请审查当前文件,检查:1. 代码规范 2. 潜在 bug 3. 性能问题",
      "context": ["currentFile"]
    },
    "test": {
      "description": "生成测试",
      "prompt": "为当前选中的函数生成完整的单元测试",
      "context": ["selection"]
    },
    "doc": {
      "description": "生成文档",
      "prompt": "为当前文件生成完整的 API 文档",
      "context": ["currentFile"]
    }
  }
}

Invoke them with:

/review
/test

4. Modes: Working Mode Switching

Built‑in modes:

Ask – quick Q&A, no code changes

Edit – direct code editing

Agent – autonomous multi‑step tasks

Custom modes are defined in ~/.cursor/modes.json:

{
  "modes": {
    "review": {
      "name": "Review",
      "description": "代码审查",
      "model": "claude-3.5-sonnet",
      "systemPrompt": "你是一个严格的代码审查员。检查代码规范、潜在 bug、性能问题。",
      "tools": ["search", "readFile"]
    },
    "learn": {
      "name": "Learn",
      "description": "学习模式",
      "systemPrompt": "你是一个耐心的编程教师。解释概念时要详细,提供多个示例。",
      "tools": ["search", "readFile"]
    }
  }
}

Switch modes with commands such as:

/mode ask
/mode edit
/mode agent
/mode review

5. Practical Cases

Case 1: Build a Spring Boot Project from Scratch

Use /mode agent to initialize a Spring Boot 3.2 project with layered architecture and Swagger.

Create a Rules file .cursor/rules/spring-boot.md to enforce coding standards.

Enter /mode edit and use Composer to generate the user module (entity, repository, service, controller, DTO).

Run /test to generate a full unit‑test suite for UserService.

Case 2: Refactor Legacy Code

Enter /mode review to analyze a 500‑line method, identifying extractable sub‑functions and potential bugs.

Switch to /mode agent to perform the refactor: extract methods, add parameter validation, and insert logging.

Efficiency Comparison

Project initialization : traditional 60 min → Cursor 5 min (12× faster)

CRUD development : traditional 120 min → Cursor 20 min (6× faster)

Unit testing : traditional 90 min → Cursor 15 min (6× faster)

Code review : traditional 60 min → Cursor 10 min (6× faster)

Average efficiency gain: 5–10×.

Avoiding Pitfalls

Do not blindly trust AI‑generated code—especially security‑critical logic.

Understand AI explanations; avoid copying them verbatim.

Manually verify critical business logic.

Cursor’s context window is limited to ~100 K tokens; split large projects into modules.

Use @ references for precise file or code location.

Conclusion

Cursor is more than an editor; it is an AI‑augmented development platform. By thoughtfully configuring Rules, MCP, Commands, and Modes, you can craft a personalized super‑charged development environment.

Start by defining your Rules, try Composer for multi‑file edits, configure MCP to connect external tools, and build a workflow that fits your team.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MCPConfigurationDevelopment ToolsAI-assisted CodingCursor AICustom CommandsModes
Xike
Written by

Xike

Stupid is as stupid does.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.