LeetCode MCP server

Connects to LeetCode's programming platform for accessing problem descriptions, searching by tags and difficulty, retrieving user profiles, and viewing community solutions to enhance algorithm learning and contest preparation.
Back to servers
Setup instructions
Provider
jinzcdev
Release date
Apr 14, 2025
Language
TypeScript
Package
Stats
1.3K downloads
35 stars

The LeetCode MCP Server provides seamless integration with LeetCode APIs, enabling advanced automation and intelligent interaction with LeetCode's programming problems, contests, solutions, and user data through the Model Context Protocol (MCP).

Installation Options

Quick Installation via Smithery

For Claude Desktop users, you can install automatically via Smithery:

npx -y @smithery/cli install @jinzcdev/leetcode-mcp-server --client claude

Manual Installation

Install from npm:

# Global installation
npm install @jinzcdev/leetcode-mcp-server -g

# Run with Global site configuration
npx -y @jinzcdev/leetcode-mcp-server --site global

# Run with authentication for accessing private data
npx -y @jinzcdev/leetcode-mcp-server --site global --session <YOUR_LEETCODE_SESSION_COOKIE>

Or run directly from the repository:

# Clone the repository
git clone https://github.com/jinzcdev/leetcode-mcp-server.git

# Navigate to the project directory
cd leetcode-mcp-server

# Build the project
npm install && npm run build

# Run the server
node build/index.js --site global

Setting Up in Visual Studio Code

Add the following configuration to your VS Code User Settings (JSON). Access this by pressing Ctrl/Cmd + Shift + P and searching for Preferences: Open User Settings (JSON).

Using Environment Variables

{
  "mcp": {
    "servers": {
      "leetcode": {
        "type": "stdio",
        "command": "npx",
        "args": ["-y", "@jinzcdev/leetcode-mcp-server"],
        "env": {
          "LEETCODE_SITE": "global",
          "LEETCODE_SESSION": "<YOUR_LEETCODE_SESSION_COOKIE>"
        }
      }
    }
  }
}

Using Command Line Arguments

{
  "mcp": {
    "servers": {
      "leetcode": {
        "type": "stdio",
        "command": "npx",
        "args": [
          "-y",
          "@jinzcdev/leetcode-mcp-server",
          "--site",
          "global",
          "--session",
          "<YOUR_LEETCODE_SESSION_COOKIE>"
        ]
      }
    }
  }
}

For LeetCode China site, change the --site parameter to cn.

Available Tools

Problem Tools

  • get_daily_challenge: Retrieves today's LeetCode Daily Challenge problem
  • get_problem: Gets details for a specific LeetCode problem by titleSlug
  • search_problems: Searches for problems with filters for category, tags, difficulty, and keywords

User Tools

  • get_user_profile: Retrieves profile information for any LeetCode user
  • get_user_contest_ranking: Gets contest ranking statistics for a user
  • get_recent_ac_submissions: Retrieves a user's recent accepted submissions
  • get_recent_submissions: Gets a user's recent submission history (Global site only)
  • get_user_status: Retrieves authenticated user's current status
  • get_problem_submission_report: Provides detailed submission analysis for a problem
  • get_problem_progress: Gets authenticated user's problem-solving progress
  • get_all_submissions: Retrieves authenticated user's submission history

Note Tools (LeetCode China only)

  • search_notes: Searches for user notes with filtering options
  • get_note: Retrieves notes for a specific problem
  • create_note: Creates a new note for a specific problem
  • update_note: Updates an existing note with new content

Solution Tools

  • list_problem_solutions: Gets community solutions for a specific problem
  • get_problem_solution: Retrieves the complete content of a specific solution

Tool Parameters

Problem Parameters

For get_problem:

titleSlug: The URL slug/identifier of the problem (string, required)

For search_problems:

category: Problem category filter (string, optional, default: "all-code-essentials")
tags: List of topic tags to filter by (string[], optional)
difficulty: Problem difficulty level (enum: "EASY", "MEDIUM", "HARD", optional)
searchKeywords: Keywords to search in titles and descriptions (string, optional)
limit: Maximum number of problems to return (number, optional, default: 10)
offset: Number of problems to skip (number, optional)

User Parameters

For get_user_profile:

username: LeetCode username (string, required)

For get_user_contest_ranking:

username: LeetCode username (string, required)
attended: Include only participated contests (boolean, optional, default: true)

For get_problem_progress:

offset: Number of questions to skip (number, optional, default: 0)
limit: Maximum number of questions to return (number, optional, default: 100)
questionStatus: Filter by status (enum: "ATTEMPTED", "SOLVED", optional)
difficulty: Filter by difficulty levels (string[], optional)

Solution Parameters

For list_problem_solutions:

questionSlug: The URL slug/identifier of the problem (string, required)
limit: Maximum number of solutions to return (number, optional, default: 10)
skip: Number of solutions to skip (number, optional)
userInput: Search term to filter solutions (string, optional)
tagSlugs: Array of tag identifiers to filter solutions (string[], optional, default: [])
orderBy: Sorting criteria for the returned solutions

Using Available Resources

The server provides several resource URIs that can be accessed directly:

  • problem-categories: categories://problems/all
  • problem-tags: tags://problems/all
  • problem-langs: langs://problems/all
  • problem-detail: problem://{titleSlug}
  • problem-solution:
    • Global: solution://{topicId}
    • CN: solution://{slug}

Authentication

To access user-specific data:

  1. Log in to LeetCode Global or LeetCode China
  2. Use browser developer tools to extract your LEETCODE_SESSION cookie
  3. Configure the server with this cookie using the --session flag or LEETCODE_SESSION environment variable

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "leetcode" '{"type":"stdio","command":"npx","args":["-y","@jinzcdev/leetcode-mcp-server","--site","global"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "leetcode": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "@jinzcdev/leetcode-mcp-server",
                "--site",
                "global"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "leetcode": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "@jinzcdev/leetcode-mcp-server",
                "--site",
                "global"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later