Skip to main content

Prerequisites

  • Cursor IDE installed
  • Pylance MCP Server running (local or cloud)
  • Active subscription (Hobby, Pro, or Enterprise)

Installation Steps

1

Install MCP Extension

Open Cursor settings and enable MCP support:
Cursor > Settings > Features > Model Context Protocol
Toggle Enable MCP to ON
2

Configure MCP Server

Create or edit ~/.cursor/mcp_config.json:
{
  "mcpServers": {
    "pylance": {
      "command": "python",
      "args": ["-m", "pylance_mcp.server"],
      "env": {
        "PYTHONPATH": "/path/to/your/workspace"
      }
    }
  }
}
3

Authenticate

On first use, Cursor will prompt for authentication:
  1. Click Sign in with Clerk
  2. Complete OAuth flow in browser
  3. Return to Cursor
4

Verify Connection

Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P):
MCP: Check Server Status
Should show: ✅ Pylance MCP: Connected

Configuration Options

Local Deployment

For maximum privacy, run Pylance MCP locally:
~/.cursor/mcp_config.json
{
  "mcpServers": {
    "pylance": {
      "command": "python",
      "args": ["-m", "pylance_mcp.server"],
      "env": {
        "PYTHONPATH": "${workspaceFolder}",
        "PYTHONWARNINGS": "ignore",
        "MCP_PORT": "3000"
      }
    }
  }
}

Cloud Deployment

Connect to hosted Pylance MCP:
~/.cursor/mcp_config.json
{
  "mcpServers": {
    "pylance": {
      "url": "https://api.pylancemcp.dev",
      "apiKey": "${PYLANCE_API_KEY}",
      "workspace": "${workspaceFolder}"
    }
  }
}
Never commit API keys to version control. Use environment variables or Cursor’s secret storage.

Usage Examples

Code Completion

Type naturally and press Tab to accept suggestions:
def calculate_

Hover Documentation

Hover over any symbol for instant documentation:
import requests  # Hover shows: "requests 2.31.0 - HTTP library"

response = requests.get(url)  # Hover shows: get(url, params=None, **kwargs) -> Response

Go to Definition

Cmd+Click (Mac) or Ctrl+Click (Windows) on any symbol:
from mymodule import MyClass  # Click "MyClass" → jumps to definition

obj = MyClass()  # Click "MyClass" → jumps to definition

Find References

Right-click → Find All References:
def important_function():  # Right-click here
    pass

# Shows all usages:
# ├── main.py:45
# ├── utils.py:12
# └── tests/test_main.py:67

Rename Symbol

Right-click → Rename Symbol (F2):
# Before
old_name = 42

# After renaming to "new_name"
new_name = 42
All references update automatically across your workspace.

Advanced Features

Workspace Settings

Configure per-workspace settings in .cursor/workspace.json:
.cursor/workspace.json
{
  "pylanceMcp": {
    "pythonPath": ".venv/bin/python",
    "analysis": {
      "typeCheckingMode": "strict",
      "diagnosticMode": "workspace",
      "stubPath": "typings"
    },
    "formatting": {
      "provider": "black",
      "lineLength": 100
    }
  }
}

Keybindings

Customize keyboard shortcuts in keybindings.json:
keybindings.json
[
  {
    "key": "ctrl+space",
    "command": "pylance.triggerCompletion",
    "when": "editorTextFocus && editorLangId == python"
  },
  {
    "key": "shift+f12",
    "command": "pylance.findAllReferences",
    "when": "editorTextFocus && editorLangId == python"
  }
]

Troubleshooting

Symptoms: “Failed to start Pylance MCP server”Solutions:
  • Check Python is in PATH: which python or where python
  • Verify installation: python -m pylance_mcp.server --version
  • Check logs: ~/.cursor/logs/mcp-pylance.log
Symptoms: No autocomplete suggestions appearSolutions:
  • Ensure file is saved (Pylance analyzes saved files)
  • Check file encoding (must be UTF-8)
  • Restart Cursor: Cmd+Shift+P → “Reload Window”
  • Clear cache: Delete ~/.cursor/cache/pylance/
Symptoms: Completions take >2 secondsSolutions:
  • Reduce diagnosticMode to “openFilesOnly”
  • Exclude large directories in .cursorignore:
    node_modules/
    .venv/
    __pycache__/
    *.pyc
    
  • Upgrade subscription tier for higher rate limits
Symptoms: “Unauthorized” or “Invalid API key”Solutions:

Best Practices

Enable Auto-Save: Pylance analyzes saved files for best results
Use Type Hints: Add type annotations for better completions
Organize Imports: Keep imports at top of file for faster analysis
Configure .cursorignore: Exclude virtual environments and caches
Large Workspaces: Workspaces >10,000 files may need diagnosticMode: "openFilesOnly"

Performance Tips

Optimize Cursor for large Python projects:
settings.json
{
  "pylance.analysis.memory.keepLibraryAst": false,
  "pylance.analysis.memory.keepLibraryLocalVariables": false,
  "pylance.analysis.extraCommitChars": false,
  "pylance.analysis.completeFunctionParens": true,
  "files.watcherExclude": {
    "**/.git/**": true,
    "**/.venv/**": true,
    "**/node_modules/**": true,
    "**/__pycache__/**": true
  }
}

Video Tutorial

Next Steps