Skip to main content
Glama
LeetCode MCP Server

LeetCode MCP Server

by AHM215

LeetCode MCP Server

Docker Pulls Build Status License: MIT

An MCP-compatible server that exposes a set of tools to interact with the LeetCode API. This allows you to fetch problems, generate code templates, run, and submit solutions programmatically.

Overview

This project provides a simple and effective way to interface with LeetCode's services. It's built using Python and the mcp framework, exposing functionalities as tools that can be easily integrated into other applications or used for automating LeetCode tasks.

Related MCP server: LeetCode MCP Server

Features

  • Fetch Problem Details: Get the full description, examples, and constraints for any LeetCode problem.

  • Code Template Generation: Generate starter code for any problem in your preferred language.

  • Run Code: Test your solution against the example test cases.

  • Submit Code: Submit your solution for evaluation against the full test suite.

  • Daily Challenge: Fetch the current daily LeetCode challenge.

  • Search Problems: Search for problems with various filters like tags, difficulty, and keywords.

Getting Started

Prerequisites

  • Python 3.12+

  • Docker (for containerized deployment)

  • Git

Configuration

To interact with the LeetCode API, you need to provide your LEETCODE_SESSION and LEETCODE_CSRFTOKEN cookies.

  1. Log in to your LeetCode account in your web browser.

  2. Open the developer tools (usually by pressing F12 or Ctrl+Shift+I).

  3. Go to the Application (or Storage) tab.

  4. Find the Cookies section and select https://leetcode.com.

  5. Locate the LEETCODE_SESSION and csrftoken cookies and copy their values.

Create a .env file in the root of the project and add your credentials:

# .env
LEETCODE_SESSION=your_leetcode_session_cookie
LEETCODE_CSRFTOKEN=your_leetcode_csrftoken

Local Installation

  1. Clone the repository:

    git clone https://github.com/AHM215/leetcode-mcp.git
    cd leetcode-mcp
  2. Install dependencies:

    pip install uv
    uv pip install -e .
  3. Run the server:

    uv run python run_server.py

    The server will start, and you can interact with it using an MCP client.

Docker Usage

Pull from Docker Hub

You can pull the pre-built Docker image from Docker Hub.

docker pull ahm215/leetcode-mcp-server:latest

Run with Docker

To run the server using Docker, you need to pass your LeetCode credentials as environment variables.

docker run -d \
  -p 8000:8000 \
  --name leetcode-mcp-server \
  -e LEETCODE_SESSION="your_leetcode_session_cookie" \
  -e LEETCODE_CSRFTOKEN="your_leetcode_csrftoken" \
  ahm215/leetcode-mcp-server:latest

Build from Source

You can also build the Docker image from the source code.

  1. Clone the repository (if you haven't already).

  2. Build the image:

    docker build -t leetcode-mcp-server .
  3. Run the container as shown in the "Run with Docker" section, using leetcode-mcp-server as the image name.

Claude Desktop Usage

If you want to run this server as a tool in a Claude Desktop environment, you can use the following JSON configuration. This defines a tool that runs the Docker container and passes the necessary credentials.

Note: You must replace the placeholder values for --leetcode-session and --csrftoken with your actual LeetCode cookies.

"docker-leetcode-mcp-server": {
  "type": "stdio",
  "command": "docker",
  "args": [
    "run",
    "-i",
    "--rm",
    "ahm215/leetcode-mcp-server:v1.0.0",
    "--leetcode-session",
    "your_leetcode_session_cookie",
    "--csrftoken",
    "your_leetcode_csrftoken"
  ]
}

Available Tools (API)

The server exposes the following tools:


fetch_problem_plain_text

Fetches the plain text content of a LeetCode problem given its URL.

  • Parameters:

    • link (str): The full URL of the LeetCode problem.

  • Returns: (str) The plain text description of the problem.


generate_template

Generates a language-specific code template for a given LeetCode problem.

  • Parameters:

    • problem_slug (str): The slug of the problem from its URL (e.g., "two-sum").

    • code_lang (str): The language slug (e.g., "python3", "java", "cpp").

  • Returns: (str) The code template.


run_code

Executes code against the example test cases for a LeetCode problem.

  • Parameters:

    • problem_slug (str): The slug of the problem.

    • code_lang (str): The language slug.

    • code (str): The code to be executed.

  • Returns: (dict) The results of the execution.


submit_code

Submits code for a LeetCode problem for evaluation against the full test suite.

  • Parameters:

    • problem_slug (str): The slug of the problem.

    • code_lang (str): The language slug.

    • code (str): The code to be submitted.

  • Returns: (dict) The submission result.


get_daily_challenge

Retrieves today's LeetCode Daily Challenge problem.

  • Parameters: None

  • Returns: (dict) Details of the daily challenge problem.


get_problem

Retrieves details about a specific LeetCode problem.

  • Parameters:

    • titleSlug (str): The slug of the problem.

  • Returns: (dict) Detailed information about the problem.


search_problems

Searches for LeetCode problems based on various filters.

  • Parameters:

    • category (str, optional): The category to search in. Defaults to "all-code-essentials".

    • tags (List[str], optional): A list of tags to filter by.

    • difficulty (str, optional): The difficulty level ("EASY", "MEDIUM", "HARD").

    • searchKeywords (str, optional): Keywords to search for.

    • limit (int, optional): The number of results to return. Defaults to 10.

    • offset (int, optional): The offset for pagination. Defaults to 0.

  • Returns: (dict) A list of problems matching the criteria.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or find any bugs.

  1. Fork the repository.

  2. Create your feature branch (git checkout -b feature/AmazingFeature).

  3. Commit your changes (git commit -m 'Add some AmazingFeature').

  4. Push to the branch (git push origin feature/AmazingFeature).

  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Available Tools

7 tools
fetch_problem_plain_textC

Fetches the plain text content of a LeetCode problem given its URL.

Inputs: link (required). Returns: result

generate_templateB

Generates a language-specific code template for a given LeetCode problem slug.

Inputs: code_lang (required), problem_slug (required). Returns: result

get_daily_challengeA

Retrieves today's LeetCode Daily Challenge problem with complete details, including problem description, constraints, and examples.

Inputs: no named parameters.

get_problemC

Retrieves details about a specific LeetCode problem, including its description, examples, constraints, and related information.

Inputs: titleSlug (required).

run_codeC

Executes code against the example test cases for a LeetCode problem and returns the results.

Inputs: code (required), code_lang (required), problem_slug (required).

search_problemsA

Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support.

Inputs: tags, limit, offset, category, +2 more.

submit_codeC

Submits the code for a LeetCode problem for evaluation against the full test suite.

Inputs: code (required), code_lang (required), problem_slug (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: fetching problem text, generating templates, running/submitting code, retrieving daily challenge, getting full problem details, and searching. No two tools overlap in functionality.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern with underscores (e.g., fetch_problem_plain_text, run_code, submit_code). No mixing of styles.

    Tool Count5/5

    Seven tools is well-scoped for a LeetCode problem-solving assistant, covering essential operations from retrieval to submission without unnecessary extras.

    Completeness4/5

    The tool set covers core workflows: fetch, template, run, submit, search, and daily challenge. Minor gaps like user account management or submission history are absent but not critical for the primary use case.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      A
      maintenance
      A Model Context Protocol server that provides integration with LeetCode APIs, enabling automated interaction with programming problems, contests, solutions, and user data across both leetcode.com and leetcode.cn platforms.
      9
      389 npm
      160
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      An MCP server that provides structured, AI-powered guidance for LeetCode problems, including approach analysis, hints, complexity breakdowns, and optimization directions without spoiling solutions.
      6
      1
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      A tutorial and working MCP server that connects to your LeetCode profile, enabling AI assistants to check solved problems and recommend new ones by topic and difficulty.
      1
      -