Back to MCP Servers

Leetcode

MCP server enabling automated access to **LeetCode**'s programming problems, solutions, submissions and public data with optional authentication for user-specific features (e.g., notes), supporting both `leetcode.com` (global) and `leetcode.cn` (China) sites.

coding-agents
By jinzcdev
12320Updated 3 months agoTypeScriptMIT

Installation

npx -y leetcode-mcp-server

Configuration

{
  "mcpServers": {
    "leetcode-mcp-server": {
      "command": "npx",
      "args": ["-y", "leetcode-mcp-server"]
    }
  }
}

How to use

  1. Run the installation command above (if needed)
  2. Open your Claude Code settings file (~/.claude/settings.json)
  3. Add the configuration to the mcpServers section
  4. Restart Claude Code to apply changes

LeetCode MCP Server

NPM Version NPM Downloads GitHub License Chinese Doc Stars

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

<a href="https://glama.ai/mcp/servers/@jinzcdev/leetcode-mcp-server"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@jinzcdev/leetcode-mcp-server/badge" alt="LeetCode Server MCP server" /> </a>

Features

  • 🌐 Multi-site Support: Support​ both leetcode.com (Global) and leetcode.cn (China) platforms
  • πŸ“Š Problem Data Retrieval: Obtain detailed problem descriptions, constraints, examples, official editorials, and ​user-submitted solutions
  • πŸ‘€ User Data Access: Retrieve user profiles, submission history, and contest performance
  • πŸ”’ ​Private Data Access: Create and query user notes, track problem-solving progress, and analyze submission details (AC/WA analysis)
  • πŸ” Advanced Search Capabilities: Filter problems by tags, difficulty levels, categories, and keywords
  • πŸ“… Daily Challenge Access: Easily access daily challenge problems

Prerequisites

  1. Node.js (v20.x or above)
  2. (Optional) LeetCode session cookie for authenticated API access

Installation

Installing via Smithery

To install leetcode-mcp-server for Claude Desktop automatically via Smithery:

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

Manual Installation

# Install from npm
npm install @jinzcdev/leetcode-mcp-server -g

# Or 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>

Alternatively, you can clone the repository and run it locally:

# 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

Usage

Visual Studio Code Integration

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

Option 1: 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>"
        }
      }
    }
  }
}

Option 2: 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, modify the --site parameter to cn.

[!TIP]

The server supports the following optional environment variables:

  • LEETCODE_SITE: LeetCode API endpoint ('global' or 'cn', default: 'global')
  • LEETCODE_SESSION: LeetCode session cookie for authenticated API access (default: empty)

Priority Note: Command-line arguments take precedence over environment variables when both are specified. For example:

  • If LEETCODE_SITE=cn is set but you run leetcode-mcp-server --site global, the server will use global.
  • If LEETCODE_SESSION exists but you provide --session "new_cookie", the command-line session value will be used.

Available Tools

Problems

ToolGlobalCNAuth RequiredDescription
get_daily_challengeβœ…βœ…βŒRetrieves today's LeetCode Daily Challenge problem
get_problemβœ…βœ…βŒRetrieves details for a specific LeetCode problem
search_problemsβœ…βœ…βŒSearches for LeetCode problems with multiple filter criteria

Users

ToolGlobalCNAuth RequiredDescription
get_user_profileβœ…βœ…βŒRetrieves profile information for a LeetCode user
get_user_contest_rankingβœ…βœ…βŒObtains contest ranking statistics for a user
get_recent_ac_submissionsβœ…βœ…βŒRetrieves a user's recent accepted submissions
get_recent_submissionsβœ…βŒβŒRetrieves a user's recent submissions history
get_user_statusβœ…βœ…βœ…Retrieves current user's current status
get_problem_submission_reportβœ…βœ…βœ…Provides detailed submission analysis for a specific problem
get_problem_progressβœ…βœ…βœ…Retrieves current user's problem-solving progress
get_all_submissionsβœ…βœ…βœ…Retrieves current user's submission history

Submissions

ToolGlobalCNAuth RequiredDescription
run_codeβœ…βœ…βœ…Runs code for a problem and polls /check/ until finished
submit_solutionβœ…βœ…βœ…Submits code for a problem and polls /check/ until finished

Notes

ToolGlobalCNAuth RequiredDescription
search_notesβŒβœ…βœ…Searches for user notes with filtering options
get_noteβŒβœ…βœ…Retrieves notes for a specific problem by question ID
create_noteβŒβœ…βœ…Creates a new note for a specific problem
update_noteβŒβœ…βœ…Updates an existing note with new content

Solutions

ToolGlobalCNAuth RequiredDescription
list_problem_solutionsβœ…βœ…βŒRetrieves a list of community solutions for a specific problem
get_problem_solutionβœ…βœ…βŒRetrieves the complete content of a specific solution

Tool Parameters

Problems

  • get_daily_challenge - Retrieves today's LeetCode Daily Challenge problem with complete details

    • No parameters required
  • get_problem - Retrieves details about a specific LeetCode problem

    • titleSlug: The URL slug/identifier of the problem (string, required)
  • search_problems - Searches for LeetCode problems based on multiple filter criteria

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

Users

  • get_user_profile - Retrieves profile information about a LeetCode user

    • username: LeetCode username (string, required)
  • get_user_contest_ranking - Retrieves a user's contest ranking information

    • username: LeetCode username (string, required)
    • attended: Whether to include only the contests the user has participated in (boolean, optional, default: true)
  • get_recent_submissions - Retrieves a user's recent submissions on LeetCode Global

    • username: LeetCode username (string, required)
    • limit: Maximum number of submissions to return (number, optional, default: 10)
  • get_recent_ac_submissions - Retrieves a user's recent accepted submissions

    • username: LeetCode username (string, required)
    • limit: Maximum number of submissions to return (number, optional, default: 10)
  • get_user_status - Retrieves the current user's status

    • No parameters required
  • get_problem_submission_report - Retrieves detailed information about a specific submission

    • id: The numerical submission ID (number, required)
  • get_problem_progress - Retrieves the current user's problem-solving 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 question status (enum: "ATTEMPTED", "SOLVED", optional)
    • difficulty: Filter by difficulty levels (string[], optional)
  • get_all_submissions - Retrieves paginated list of user's submissions

    • limit: Maximum number of submissions to return (number, default: 20)
    • offset: Number of submissions to skip (number, default: 0)
    • questionSlug: Optional problem identifier (string, optional)
    • lang: Programming language filter (string, optional, CN only)
    • status: Submission status filter (enum: "AC", "WA", optional, CN only)
    • lastKey: Pagination token for retrieving next page (string, optional, CN only)

Submissions

  • run_code - Runs code for a specific problem and waits until finished (requires authentication)

    • titleSlug: The URL slug/identifier of the problem (string, required)
    • lang: Programming language (string enum, required)
    • typedCode: Source code to run (string, required)
    • dataInput: Custom input to run (string, optional)
    • timeoutMs: Polling timeout in milliseconds (number, optional, default: 120000)
    • pollIntervalMs: Polling interval in milliseconds (number, optional, default: 1500)
  • submit_solution - Submits code for a specific problem and waits until finished (requires authentication)

    • titleSlug: The URL slug/identifier of the problem (string, required)
    • lang: Programming language (string enum, required)
    • typedCode: Source code to submit (string, required)
    • timeoutMs: Polling timeout in milliseconds (number, optional, default: 120000)
    • pollIntervalMs: Polling interval in milliseconds (number, optional, d

…

View source on GitHub