Cursor & Model Context Protocol

AI-Powered Coding for Enhanced Productivity


Team: 😈πŸ”₯

Today:

Session:

https://phasheen.github.io/revealjs-cursor

Presentation Outline

  1. Introduction to Cursor - AI-powered code editor
  2. Cursor Key Features - Agent, Codebase Indexing, Rule, and more
  3. Cursor System Prompt - Understanding Cursor's Prompt Engineering Foundation
  4. Model Context Protocol in Cursor - Building with MCP
  5. Discussion - Q&A

Introduction to Cursor

  • AI-powered code editor built on VSCode
  • Using Claude 3.7 Sonnet as base LLM
  • Advanced Tool calling capabilities that enable agents to execute tasks in one go
  • Native support of Model Context Protocol for extended functionality
Cursor editor interface

Cursor editor interface

Comparison of AI Coding Assistants

Feature Cursor GitHub Copilot Windsurf
Base Technology VS Code with custom UI Extension for popular IDEs VS Code with custom UI
Base AI Models Claude 3.7 Sonnet GPT-4o Mixed
Code Completion Multi-line intelligent suggestions Line-by-line suggestions Context-aware suggestions
Agent Capabilities Advanced with MCP support Basic with chat-based workflows Cascade system for automations
Codebase Understanding Advanced semantic indexing Basic repository awareness Context-aware file search
Community Growing rapidly Largest user base Emerging
Pro Plan $20/month $10/month $15/month

Cursor Key Features

  • Agent Mode - Completes coding tasks end-to-end
  • Chat - AI-powered chat that understands your codebase
  • Tab - Smart code autocomplete with multi-line predictions
  • Ctrl+K - Edit and generate code with AI assistance
Cursor features overview

Cursor features overview

Agent Mode

  • Autonomous AI coding agent that independently explores, plans, and executes complex codebase changes
  • Follows a systematic workflow:
    • 🧠 Understand your request and codebase context
    • πŸ” Explore relevant files and documentation
    • πŸ“ Plan changes with a step-by-step approach
    • πŸ”§ Execute necessary modifications across files
    • βœ… Verify results and fix any issues
  • Creates checkpoints before making changes, allowing you to revert if needed

Codebase Indexing

  • Local-first scan – builds a Merkle-tree of your files (respects .gitignore/.cursorignore)
  • Incremental updates – every 10 minutes it diff-checks and only uploads changed chunks
  • Vector embeddings – files split into overlapping snippets and embedded server-side (with obfuscated paths)
  • On-demand retrieval – queries return only chunk IDs; Cursor reads the matching lines locally before prompting the LLM

Cursor Rules

What Are Cursor Rules?

  • Custom instructions for the AI within Cursor
  • Override default behavior for specific use cases
  • Can be global or project-specific
  • Stored in .cursor/rules.json files

Implementing Cursor Rules

Best Practices

  • Keep rules clear and specific
  • Target only necessary modes
  • Use project-specific rules for unique requirements
  • Global rules for personal preferences
Cursor interface with rules

Cursor System Prompt

Understanding Cursor's AI Foundation

  • Core Identity: "You are a powerful agentic AI coding assistant, powered by Claude 3.7 Sonnet"
  • Primary Goal: Follow user instructions at each message
  • Tool Integration: Access to file system, search and code manipulation tools
  • Context Awareness: Automatically attaches information about current state
  • Proactiveness: Balances task completion with user control
Cursor operates with a sophisticated system prompt

Cursor operates with a sophisticated system prompt

Key Elements of Cursor's System Prompt

Tool Integration Guidelines

  • Never refer to tool names when speaking to users
  • Follow schema exactly and provide all parameters
  • Explain intentions before calling tools

Code Change Rules

  • Never output code directly to users
  • Always read file contents before editing
  • Group edits to the same file together
  • Limit to 3 attempts for fixing linter errors

Code Format Standards

  • Create dependency files when building from scratch
  • Never generate long hashes or binary code
  • Fix reasonable linter errors

Search Optimization

  • Prefer semantic search over grep/file search
  • Read larger sections at once
  • Stop searching once sufficient information found
Cursor's prompt encourages quality code generation while maintaining a user-friendly interface

Model Context Protocol

Understanding MCP Architecture

  • Open protocol that standardizes how applications provide context to LLMs
  • Acts like a USB-C port for AI applications
  • Connects AI models to data sources and tools
  • Enables switching between LLM providers
  • Ensures data security within your infrastructure
flowchart LR
  %% Define a reusable class for consistent styling
  classDef common fill:#e0e0ff,stroke:#4b0082,stroke-width:1px,color:#000080;

  subgraph "Your Computer"
    direction TB
    client["Host with MCP Client
(Claude, IDEs, Tools)"]:::common subgraph "MCP Servers" direction LR A["MCP Server A"]:::common --> DataA[(Local Data Source A)]:::common B["MCP Server B"]:::common --> DataB[(Local Data Source B)]:::common C["MCP Server C"]:::common --> Web[(Web APIs)]:::common end end subgraph Internet Remote[(Remote Service C)]:::common end client -->|MCP Protocol| A client -->|MCP Protocol| B client -->|MCP Protocol| C DataA --> A DataB --> B Web --> Remote

MCP architecture overview

MCP Architecture

  • MCP Hosts: Programs like Cursor, Claude Desktop, or AI tools
  • MCP Clients: Protocol clients with 1:1 server connections
  • MCP Servers: Lightweight programs exposing capabilities
  • Data Sources: Local files, databases, services
  • Remote Services: External APIs and web services
flowchart TD
  classDef hosts fill:#f9f9ff,stroke:#333,stroke-width:1px
  classDef clients fill:#e6f3ff,stroke:#333,stroke-width:1px
  classDef servers fill:#f0fff0,stroke:#333,stroke-width:1px
  classDef data fill:#fff0f0,stroke:#333,stroke-width:1px
  classDef remote fill:#f5f5f5,stroke:#333,stroke-width:1px
  
  Host["MCP Hosts
(Cursor, Claude Desktop)"]:::hosts Client["MCP Clients
(Protocol clients)"]:::clients Server["MCP Servers
(Lightweight programs)"]:::servers Data["Data Sources
(Files, DBs, Services)"]:::data Remote["Remote Services
(External APIs)"]:::remote Host --> Client Client --> Server Server --> Data Server --> Remote

MCP Architecture Diagram

MCP Configuration

Configuration Locations:

  • Project Configuration:
    .cursor/mcp.json in project directory
  • Global Configuration:
    ~/.cursor/mcp.json in home directory

Configuration Structure:

  • command: The executable to run
  • args: Command line arguments
  • env: Environment variables

// Example Project-specific MCP configuration
{
  "mcpServers": {
    "database-accessor": {
      "command": "python",
      "args": ["-m", "mcp_database_server"],
      "env": {
        "DB_CONNECTION": "postgres://user:pass@localhost/db",
        "API_KEY": "sk-xxxx"
      }
    },
    "documentation-lookup": {
      "command": "npx",
      "args": ["-y", "mcp-docs-server"],
      "env": {
        "DOCS_PATH": "./documentation"
      }
    }
  }
}
Source: https://docs.cursor.com/context/model-context-protocol

Using MCP in Cursor

Automatic Tool Usage:

  • Composer Agent automatically uses relevant MCP tools
  • Tools are listed under 'Available Tools' in MCP settings
  • You can intentionally prompt tool usage by mentioning the tool

MCP Tool usage in Cursor

Source: https://docs.cursor.com/context/model-context-protocol

Discussion & Key Takeaways

Core Benefits

  • Agent Capabilities - End-to-end task completion with systematic workflows
  • Codebase Understanding - Semantic indexing with incremental updates and vector embeddings
  • Customizable Experience - Rules to enforce coding standards and tailor AI behavior
  • Extensibility - MCP enables seamless integration with tools and data sources

Future Implications

  • Enhanced Developer Productivity - Reduced time on repetitive tasks
  • Customized Workflows - Tailored AI behavior through system prompts and rules
  • Secure Context Sharing - Data remains within your infrastructure
  • Ecosystem Growth - More MCP-compatible tools and services

Thank You

Questions?

Key References:

Cursor: AI-powered code editor with customizable prompts & rules

MCP: Open protocol for standardizing AI model context



This presentation was created for the Special Topics in Data Science class on Prompt Engineering.