leetcode-mcp-server
leetcode-mcp-server
LeetCode MCP server implementation for LeetCode API integration, enabling automated access to programming problems, user data, and contest information.
LeetCode MCP Server
LeetCode MCP Server is a service based on the Model Context Protocol (MCP), providing seamless integration with the LeetCode API for advanced automation and intelligent interaction with LeetCode programming problems, contests, solutions, and user data.
Features
- 🌐 Multi-site Support: Supports both leetcode.com (global) and leetcode.cn (China) sites
- 🔌 Dual Transport Modes: Runs by default as a stdio process or in Streamable HTTP server mode, suitable for web integration scenarios
- 📊 Problem Data Retrieval: Fetches detailed problem descriptions, constraints, examples, official solutions, and user-submitted solutions
- 👤 User Data Access: Retrieves user profiles, submission history, and contest performance
- 🔒 Private Data Access: Creates and queries user notes, tracks problem-solving progress, and analyzes submission details (AC/WA reports)
- 🔍 Advanced Search Functionality: Filters problems by tags, difficulty levels, categories, and keywords
- 📅 Daily Problem Access: Easy access to the daily problem
Prerequisites
- Node.js (v20.x or higher)
- (Optional) LeetCode session cookie for authorized API access
Installation
# Install from npm
npm install @jinzcdev/leetcode-mcp-server -g
# Run with the China site config (stdio transport, default)
npx -y @jinzcdev/leetcode-mcp-server --site cn
# Run with authentication (to access private data)
npx -y @jinzcdev/leetcode-mcp-server --site cn --session
# Run as a Streamable HTTP server
npx -y @jinzcdev/leetcode-mcp-server --transport http --port 3000 --site cnAlternatively, 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 (stdio transport)
node build/index.js --site cn
# Or run as a Streamable HTTP server
node build/index.js --transport http --port 3000 --site cnUsage
The server supports two transport modes:
| Transport Mode | Description |
|---|---|
stdio (default) | Standard input/output transport, suitable for local MCP clients |
http | Streamable HTTP transport, suitable for web integration and remote access |
Command Line Arguments
| Argument | Alias | Default Value | Description |
|---|---|---|---|
--site | -s | global | LeetCode API site: global (leetcode.com) or cn (leetcode.cn) |
--session | -c | — | LeetCode session cookie for authorized access |
--transport | -t | stdio | Transport mode: stdio or http |
--port | — | 3000 | HTTP service port (for Streamable HTTP only) |
--host | — | 127.0.0.1 | HTTP service host (for Streamable HTTP only) |
--endpoint | — | /mcp | HTTP endpoint path (for Streamable HTTP only) |
MCP Client Configuration (stdio)
Add the following server configuration to your MCP client's configuration file:
Method 1: Using Environment Variables
{
"mcpServers": {
"leetcode": {
"command": "npx",
"args": ["-y", "@jinzcdev/leetcode-mcp-server"],
"env": {
"LEETCODE_SITE": "cn",
"LEETCODE_SESSION": ""
}
}
}
}Method 2: Using Command Line Arguments
{
"mcpServers": {
"leetcode": {
"command": "npx",
"args": [
"-y",
"@jinzcdev/leetcode-mcp-server",
"--site",
"cn",
"--session",
""
]
}
}
}For the global LeetCode site, change the --site parameter to global.
[!NOTE]
The location and JSON structure of the configuration file may vary among different MCP clients. Some clients use an
mcp.serverswrapper or atypefield. Please refer to the documentation of the client you are using and adjust the example accordingly.
MCP Client Configuration (Streamable HTTP)
First, start the server in HTTP mode:
npx -y @jinzcdev/leetcode-mcp-server --transport http --port 3000 --site cnThen, connect to the server in your MCP client:
PLACEHOLDER_CODE_5To access authenticated APIs, pass the session cookie when starting the server:
npx -y @jinzcdev/leetcode-mcp-server --transport http --port 3000 --site cn --session[!NOTE] Some MCP clients require specifying
"type": "http"or"type": "streamableHttp"in addition to theurlfield. Please refer to the documentation of the client you are using for the correct HTTP transport configuration format.
[!TIP]
The service supports the following optional environment variables:
LEETCODE_SITE: LeetCode API endpoint (globalorcn, default isglobal)LEETCODE_SESSION: LeetCode session cookie for authorizing API access (default is empty)LEETCODE_TRANSPORT: Transport mode (stdioorhttp, default isstdio)LEETCODE_HTTP_PORT: Streamable HTTP service port (default is3000)LEETCODE_HTTP_HOST: Streamable HTTP service host (default is127.0.0.1)LEETCODE_HTTP_ENDPOINT: Streamable HTTP endpoint path (default is/mcp)Priority Explanation:
When both command-line arguments and environment variables are specified, command-line arguments take precedence. For example:
- If
LEETCODE_SITE=cnis set but you runleetcode-mcp-server --site global, the server will useglobal.- If
LEETCODE_SESSIONexists but you provide--session "new_cookie", the value from the command line will be used.
Available Tools
Problems
| Tool | Global | China | Requires Auth | Description |
|---|---|---|---|---|
| get_daily_challenge | ✅ | ✅ | ❌ | Get today's LeetCode daily challenge |
| get_problem | ✅ | ✅ | ❌ | Get details of a specific LeetCode problem |
| search_problems | ✅ | ✅ | ❌ | Search LeetCode problems with filters |
User
| Tool | Global | China | Requires Auth | Description |
|---|---|---|---|---|
| get_user_profile | ✅ | ✅ | ❌ | Get LeetCode user profile information |
| get_user_contest_ranking | ✅ | ✅ | ❌ | Get user's contest ranking statistics |
| get_recent_ac_submissions | ✅ | ✅ | ❌ | Get user's recent accepted submissions |
| get_recent_submissions | ✅ | ❌ | ❌ | Get user's recent submission history |
| get_user_status | ✅ | ✅ | ✅ | Get user's current status |
| get_problem_submission_report | ✅ | ✅ | ✅ | Provide detailed submission analysis |
| get_problem_progress | ✅ | ✅ | ✅ | Get user's problem solving progress |
| get_all_submissions | ✅ | ✅ | ✅ | Get paginated list of user submissions |
Submission / Run
| Tool | Global | China | Requires Auth | Description |
|---|---|---|---|---|
| run_code | ✅ | ✅ | ✅ | Run code and poll /check/ until completion |
| submit_solution | ✅ | ✅ | ✅ | Submit code and poll /check/ until completion |
Notes
| Tool | Global | China | Requires Auth | Description |
|---|---|---|---|---|
| search_notes | ❌ | ✅ | ✅ | Search user notes with filters |
| get_note | ❌ | ✅ | ✅ | Get note for a specific problem by ID |
| create_note | ❌ | ✅ | ✅ | Create a new note for a specific problem |
| update_note | ❌ | ✅ | ✅ | Update an existing note with new content |
Solutions| Tool | Global Site | China Site | Requires Authentication | Description |
| -------------------------- | :---------: | :--------: | :---------------------: | ------------------------------------ | | list_problem_solutions | ✅ | ✅ | ❌ | Get a list of community solution articles for a specific problem | | get_problem_solution | ✅ | ✅ | ❌ | Get the full content of a specific solution article |
Tool Parameters
Problems
get_daily_challenge - Get today's LeetCode daily challenge and full details
- No parameters required
get_problem - Get details of a specific LeetCode problem
titleSlug: URL identifier of the problem (string, required)
search_problems - Search LeetCode problems based on multiple filters
category: Problem category filter (string, optional, default: "all-code-essentials")tags: List of topic tags to filter problems (array of strings, optional)difficulty: Difficulty level filter (enum: "EASY", "MEDIUM", "HARD", optional)searchKeywords: Keywords to search in the problem title and description (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 - Get profile information of a LeetCode user
username: LeetCode username (string, required)
get_user_contest_ranking - Get contest ranking information of a user
username: LeetCode username (string, required)attended: Whether to include only contests the user has attended (boolean, optional, default: true)
get_recent_submissions - Get recent submissions of a user on the global LeetCode site
username: LeetCode username (string, required)limit: Maximum number of submissions to return (number, optional, default: 10)
get_recent_ac_submissions - Get recent accepted submissions of a user
username: LeetCode username (string, required)limit: Maximum number of submissions to return (number, optional, default: 10)
get_user_status - Get the status of the currently authenticated user
- No parameters required
get_problem_submission_report - Get detailed information about a specific submission
id: Numeric ID of the submission (number, required)
get_problem_progress - Get the problem-solving status of the authenticated user
offset: Number of problems to skip (number, optional, default: 0)limit: Maximum number of problems to return (number, optional, default: 100)questionStatus: Filter by problem status (enum: "ATTEMPTED", "SOLVED", optional)difficulty: Filter by difficulty levels (array of strings, optional)
get_all_submissions - Get a paginated list of user submissions
limit: Maximum number of submissions to return (number, default: 20)offset: Number of submissions to skip (number, default: 0)questionSlug: Optional question identifier (string, optional)lang: Programming language filter (string, optional, China site only)status: Submission status filter (enum: "AC", "WA", optional, China site only)lastKey: Pagination token for retrieving the next page (string, optional, China site only)
Submissions / Runs
run_code - Run code for a specified problem and wait for completion (requires authentication)
titleSlug: URL identifier of the problem (string, required)lang: Programming language (string enum, required)typedCode: Source code to run (string, required)dataInput: Custom input for the run (string, optional)timeoutMs: Polling timeout in milliseconds (number, optional, default: 120000)pollIntervalMs: Polling interval in milliseconds (number, optional, default: 1500)
submit_solution - Submit code for a specified problem and wait for completion (requires authentication)
titleSlug: URL 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, default: 1500)
Notes
search_notes - Search for user notes on LeetCode China
keyword: Keyword to filter the notes (string, optional)limit: Maximum number of notes to return (number, optional, default: 10)skip: Number of notes to skip (number, optional, default: 0)orderBy: Order in which to return the notes (enum: "ASCENDING", "DESCENDING", optional, default: "DESCENDING")
get_note - Get user notes for a specific LeetCode problem
questionId: The ID of the LeetCode problem (string, required)limit: Maximum number of notes to return (number, optional, default: 10)skip: Number of notes to skip (number, optional, default: 0)
create_note - Create a new note for a specific LeetCode problem
questionId: The ID of the LeetCode problem (string, required)content: Note content, supports markdown format (string, required)summary: Optional short summary or title for the note (string, optional)
update_note - Update an existing note with new content or summary
noteId: The ID of the note to update (string, required)content: New content for the note, supports markdown format (string, required)summary: Optional new short summary or title (string, optional)
Solutions
list_problem_solutions - Get a list of community solution articles for a specific problem
questionSlug: URL identifier of the problem (string, required)limit: Maximum number of solution articles to return (number, optional, default: 10)skip: Number of solution articles to skip (number, optional)userInput: Keyword to filter the solution articles (string, optional)tagSlugs: Array of tag identifiers to filter the solution articles (array of strings, optional, default: [])orderBy: Sorting condition for the solution articles- Global site: enum: "HOT", "MOST_RECENT", "MOST_VOTES", optional, default: "HOT"
- China site: enum: "DEFAULT", "MOST_UPVOTE", "HOT", "NEWEST_TO_OLDEST", "OLDEST_TO_NEWEST", optional, default: "DEFAULT"
get_problem_solution - Get the full content of a specific solution article
topicId: Unique topic ID of the solution article (string, required, global site only)slug: Unique identifier of the solution article (string, required, China site only)
Available Resources
| Resource Name | Global Site | China Site | Requires Authentication | Description |
|---|---|---|---|---|
| problem-categories | ✅ | ✅ | ❌ | List of all problem category types |
| problem-tags | ✅ | ✅ | ❌ | Detailed collection of algorithm and data structure tags |
| problem-langs | ✅ | ✅ | ❌ | Complete list of supported programming languages |
| problem-detail | ✅ | ✅ | ❌ | Provides details for a specific problem |
| problem-solution | ✅ | ✅ | ❌ | Provides the full content of a specific solution article |
Resource URIs
problem-categories - List of all problem category types
- URI:
categories://problems/all
- URI:
problem-tags - Detailed collection of algorithm and data structure tags
- URI:
tags://problems/all
- URI:
problem-langs - Complete list of all programming languages supported by LeetCode
- URI:
langs://problems/all
- URI:
problem-detail - Provides details for a specific LeetCode problem
- URI:
problem://{titleSlug} - Parameters:
titleSlug: Identifier of the problem as shown in the LeetCode URL
- URI:
problem-solution - Provides the full content of a specific solution article
- Global site URI:
solution://{topicId}- Parameters:
topicId: Unique topic ID of the solution article
- Parameters:
- China site URI:
solution://{slug}- Parameters:
slug: Unique identifier of the solution article
- Parameters:
- Global site URI:
Authentication
Access to user-specific data requires LeetCode session authentication:1. Log in to LeetCode (Global Site or China Site) 2. Extract the LEETCODE_SESSION cookie from the browser developer tools 3. Configure the server using the --session flag or the LEETCODE_SESSION environment variable
Response Format
All tools return a JSON formatted response with the following structure:
json
{
"content": [
{
"type": "text",
"text": "JSON_DATA_STRING"
}
]
}JSON_DATA_STRING contains the requested data or an error message for failed requests.
License
This project is licensed under the MIT License.
**Official site: ** https://github.com/jinzcdev/leetcode-mcp-server **Status: ** active **Last verified: ** 2026-08-30
Categories & Tags
- Categories:
development,memory,data - Tags:
research and data,knowledge and memory,developer tools,leetcode,编程,力扣,算法,数据结构,chinese
MCP Configuration
- Transport:
stdio - Command:
npx - Args:
-y @jinzcdev/leetcode-mcp-server --site cn
This config can be imported into ChatSpeed from the resource index. Verify the command, arguments, and permission source are trustworthy before importing.
Data source
Resource file: resources/mcp/jinzcdev-leetcode.json. Content last verified on 2026-08-30; free quotas and service limits may change with official policies.