✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more

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.

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.

Featured Templates

View More
AI Characters
Sarcastic AI Chat Bot
128 1437
Customer service
Service ERP
125 754
AI Assistants
Image to text with Claude 3
150 1119
AI Assistants
AI Chatbot Starter Kit v0.1
129 665

Start your free trial

Build your solution today. No credit card required.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.