LeetCode MCP Server

LeetCode MCP Server

By jinzcdev GitHub

MCP server for LeetCode API, enabling advanced automation and intelligent interaction with LeetCode problems, contests, solutions and user data.

algorithm leetcode
Overview

What is LeetCode MCP Server?

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

How to use LeetCode MCP Server?

To use the LeetCode MCP Server, install it via npm and run the server with the desired configuration. You can also integrate it with Visual Studio Code for enhanced functionality.

Key features of LeetCode MCP Server?

  • Multi-site support for leetcode.com and leetcode.cn
  • Detailed problem data retrieval including descriptions and examples
  • Access to user data such as profiles and submission history
  • Advanced search capabilities for filtering problems
  • Daily challenge tracking

Use cases of LeetCode MCP Server?

  1. Automating problem retrieval and submission processes.
  2. Analyzing user performance in contests.
  3. Facilitating daily coding challenges.

FAQ from LeetCode MCP Server?

  • What platforms does it support?

It supports both leetcode.com and leetcode.cn.

  • Is authentication required?

Authentication is optional but recommended for accessing private user data.

  • What programming languages are supported?

The server supports multiple programming languages as specified in the LeetCode API.

Content

LeetCode MCP Server

NPM Version GitHub License Stars smithery badge

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.

LeetCode Server MCP server

Features

  • Multi-site Support: Supports both leetcode.com and leetcode.cn platforms
  • Problem Data Retrieval: Obtain detailed problem descriptions, constraints, examples, and solution approaches
  • User Data Access: Retrieve user profiles, submission history, and contest performance
  • Advanced Search Capabilities: Filter problems by tags, difficulty levels, and categories
  • Daily Challenge Tracking: Easily access daily challenge problems

Prerequisites

  1. Node.js runtime environment
  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 and run the server
npm run build && node build/index.js --site global

Usage

Visual Studio Code Integration

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

{
  "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.

Environment Variables

The server supports the following environment variables:

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

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.

Tools

The server provides a comprehensive suite of tools categorized by functionality and platform compatibility.

Problem Tools

Available on both Global and China sites, with optional authentication.

Tool NameDescriptionParameters
leetcode_daily_challengeRetrieves today's LeetCode Daily Challenge with complete metadataNone
leetcode_problemRetrieves comprehensive details for a specified LeetCode problemtitleSlug (string, required): Problem URL identifier (e.g., 'two-sum')
leetcode_search_problemsExecutes filtered searches across LeetCode problemscategory (string, optional): Problem classification
tags (string[], optional): Topic tags filter
difficulty (string, optional): Problem complexity level ('EASY', 'MEDIUM', 'HARD')
limit (number, optional): Maximum results count
offset (number, optional): Pagination offset

User Tools

Provides user-specific data across both platforms.

Tool NameDescriptionParameters
leetcode_user_profileRetrieves complete profile information for a LeetCode userusername (string, required): LeetCode username
leetcode_user_contest_rankingObtains contest ranking statistics for a userusername (string, required): LeetCode username
attended (boolean, optional): Filter for attended contests only

Global Site-Specific User Tools

Exclusive to leetcode.com platform.

Tool NameDescriptionParameters
leetcode_recent_submissionsRetrieves a user's recent submission history (Global)username (string, required): LeetCode username
limit (number, optional): Results limit
leetcode_recent_ac_submissionsRetrieves a user's recent accepted submissions (Global)username (string, required): LeetCode username
limit (number, optional): Results limit

China Site-Specific User Tools

Exclusive to leetcode.cn platform.

Tool NameDescriptionParameters
leetcode_user_recent_ac_submissionsRetrieves recent accepted submissions (China)username (string, required): LeetCode China username
limit (number, optional): Results limit

Authenticated Common Tools

Requires session authentication, available on both platforms.

Tool NameDescriptionParameters
leetcode_user_statusRetrieves authenticated user's current statusNone
leetcode_problem_submission_detailProvides detailed submission analysisid (number, required): Submission ID
leetcode_user_progress_questionsTracks user's problem-solving progressoffset (number, required): Pagination offset
limit (number, required): Results limit
questionStatus (enum, optional): 'ATTEMPTED' or 'SOLVED' filter
difficulty (string[], optional): Complexity level filter

Global Site-Specific Authenticated Tools

Authenticated tools exclusive to leetcode.com.

NameDescriptionParameters
leetcode_user_all_submissionsRetrieves paginated submission history (Global)limit (number, required): Results limit
offset (number, required): Pagination offset
questionSlug (string, optional): Problem identifier filter

China Site-Specific Authenticated Tools

Authenticated tools exclusive to leetcode.cn.

Tool NameDescriptionParameters
leetcode_user_all_submissionsRetrieves comprehensive submission history (China)limit (number, required): Results limit
offset (number, required): Pagination offset
questionSlug (string, optional): Problem identifier
lang (string, optional): Programming language filter
status (string, optional): Submission status filter
lastKey (string, optional): Pagination token

Resources

The server provides reference resources for platform metadata access via URI endpoints.

Resource NameDescriptionURI
problem-categoriesComplete problem classification categoriesleetcode://problems/categories/all
problem-tagsAlgorithmic and data structure tags collectionleetcode://problems/tags/all
problem-langsSupported programming languages listleetcode://problems/langs/all
solution-articleA LeetCode solution articleglobal: leetcode://solutions/{topicId}
cn: leetcode://solutions/{slug}

Authentication

Advanced features require LeetCode session authentication:

  1. Log in to LeetCode (Global or China site)
  2. Extract LEETCODE_SESSION cookie from browser developer tools
  3. Configure server with --session flag or LEETCODE_SESSION environment variable

Response Format

All tools return JSON-formatted responses with the following structure:

{
  "content": [
    {
      "type": "text",
      "text": "JSON_DATA_STRING"
    }
  ]
}

The JSON_DATA_STRING contains either the requested data or an error message for failed requests.

License

This project is licensed under the MIT License.

No tools information available.
LeetCode Crawler
LeetCode Crawler by louisfghbvc

mcp server for craw the interview questions in discussion

crawler leetcode
View Details