MCP server for LeetCode. Automate fetching problems, running code, and submitting solutions.
114
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.
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.
To interact with the LeetCode API, you need to provide your LEETCODE_SESSION and LEETCODE_CSRFTOKEN cookies.
F12 or Ctrl+Shift+I).https://leetcode.com.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
Clone the repository:
git clone https://github.com/AHM215/leetcode-mcp.git
cd leetcode-mcp
Install dependencies:
pip install uv
uv pip install -e .
Run the server:
mcp
The server will start, and you can interact with it using an MCP client.
You can pull the pre-built Docker image from Docker Hub.
docker pull ahm215/leetcode-mcp-server:latest
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
You can also build the Docker image from the source code.
docker build -t leetcode-mcp-server .
leetcode-mcp-server as the image name.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"
]
}
The server exposes the following tools:
fetch_problem_plain_textFetches the plain text content of a LeetCode problem given its URL.
link (str): The full URL of the LeetCode problem.generate_templateGenerates a language-specific code template for a given LeetCode problem.
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").run_codeExecutes code against the example test cases for a LeetCode problem.
problem_slug (str): The slug of the problem.code_lang (str): The language slug.code (str): The code to be executed.submit_codeSubmits code for a LeetCode problem for evaluation against the full test suite.
problem_slug (str): The slug of the problem.code_lang (str): The language slug.code (str): The code to be submitted.get_daily_challengeRetrieves today's LeetCode Daily Challenge problem.
get_problemRetrieves details about a specific LeetCode problem.
titleSlug (str): The slug of the problem.search_problemsSearches for LeetCode problems based on various filters.
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.Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or find any bugs.
git checkout -b feature/AmazingFeature).git commit -m 'Add some AmazingFeature').git push origin feature/AmazingFeature).This project is licensed under the MIT License. See the LICENSE file for details.
Content type
Image
Digest
sha256:761da110a…
Size
96.9 MB
Last updated
about 1 year ago
docker pull ahm215/leetcode-mcp-server:v1.0.0