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 implementation for LeetCode API integration, enabling automated access to programming problems, user data, and contest information.
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.
To install leetcode-mcp-server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @jinzcdev/leetcode-mcp-server --client claude
# 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
Add the following JSON configuration to your User Settings (JSON) file. 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
.
The server supports the following environment variables:
LEETCODE_SITE
: LeetCode API endpoint ('global' or 'cn')LEETCODE_SESSION
: LeetCode session cookie for authenticated API accessPriority Note:
Command-line arguments take precedence over environment variables when both are specified. For example:
LEETCODE_SITE=cn
is set but you run leetcode-mcp-server --site global
, the server will use global
.LEETCODE_SESSION
exists but you provide --session "new_cookie"
, the command-line session value will be used.Tool | Global | CN | Auth Required | Description |
---|---|---|---|---|
get_daily_challenge | ✅ | ✅ | ❌ | Retrieves today's LeetCode Daily Challenge problem |
get_problem | ✅ | ✅ | ❌ | Retrieves details for a specific LeetCode problem |
search_problems | ✅ | ✅ | ❌ | Searches for LeetCode problems with multiple filter criteria |
Tool | Global | CN | Auth Required | Description |
---|---|---|---|---|
get_user_profile | ✅ | ✅ | ❌ | Retrieves profile information for a LeetCode user |
get_user_contest_ranking | ✅ | ✅ | ❌ | Obtains contest ranking statistics for a user |
get_recent_ac_submissions | ✅ | ✅ | ❌ | Retrieves a user's recent accepted submissions |
get_recent_submissions | ✅ | ❌ | ❌ | Retrieves a user's recent submissions history |
get_user_status | ✅ | ✅ | ✅ | Retrieves current user's current status |
get_problem_submission_report | ✅ | ✅ | ✅ | Provides detailed submission analysis for a specific problem |
get_problem_progress | ✅ | ✅ | ✅ | Retrieves current user's problem-solving progress |
get_all_submissions | ✅ | ✅ | ✅ | Retrieves current user's submission history |
Tool | Global | CN | Auth Required | Description |
---|---|---|---|---|
search_notes | ❌ | ✅ | ✅ | Searches for user notes with filtering options |
get_note | ❌ | ✅ | ✅ | Retrieves notes for a specific problem by question ID |
create_note | ❌ | ✅ | ✅ | Creates a new note for a specific problem |
update_note | ❌ | ✅ | ✅ | Updates an existing note with new content |
Tool | Global | CN | Auth Required | Description |
---|---|---|---|---|
list_problem_solutions | ✅ | ✅ | ❌ | Retrieves a list of community solutions for a specific problem |
get_problem_solution | ✅ | ✅ | ❌ | Retrieves the complete content of a specific solution |
get_daily_challenge - Retrieves today's LeetCode Daily Challenge problem with complete details
No parameters required
get_problem - Retrieves details about a specific LeetCode problem
titleSlug
: The URL slug/identifier of the problem (string, required)
search_problems - Searches for LeetCode problems based on multiple filter criteria
category
: Problem category filter (string, optional, default: "all-code-essentials")tags
: List of topic tags to filter problems by (string[], optional)difficulty
: Problem difficulty level filter (enum: "EASY", "MEDIUM", "HARD", optional)searchKeywords
: Keywords to search in problem titles and descriptions (string, optional)limit
: Maximum number of problems to return (number, optional, default: 10)offset
: Number of problems to skip (number, optional)get_user_profile - Retrieves profile information about a LeetCode user
username
: LeetCode username (string, required)
get_user_contest_ranking - Retrieves a user's contest ranking information
username
: LeetCode username (string, required)
attended
: Whether to include only the contests the user has participated in (boolean, optional, default: true)
get_recent_submissions - Retrieves a user's recent submissions on LeetCode Global
username
: LeetCode username (string, required)
limit
: Maximum number of submissions to return (number, optional, default: 10)
get_recent_ac_submissions - Retrieves a user's recent accepted submissions
username
: LeetCode username (string, required)
limit
: Maximum number of submissions to return (number, optional, default: 10)
get_user_status - Retrieves the current user's status
No parameters required
get_problem_submission_report - Retrieves detailed information about a specific submission
id
: The numerical submission ID (number, required)
get_problem_progress - Retrieves the current user's problem-solving progress
offset
: Number of questions to skip (number, optional, default: 0)
limit
: Maximum number of questions to return (number, optional, default: 100)questionStatus
: Filter by question status (enum: "ATTEMPTED", "SOLVED", optional)difficulty
: Filter by difficulty levels (string[], optional)
get_all_submissions - Retrieves paginated list of user's submissions
limit
: Maximum number of submissions to return (number, default: 20)offset
: Number of submissions to skip (number, default: 0)questionSlug
: Optional problem identifier (string, optional)lang
: Programming language filter (string, optional, CN only)status
: Submission status filter (enum: "AC", "WA", optional, CN only)lastKey
: Pagination token for retrieving next page (string, optional, CN only)search_notes - Searches for user notes on LeetCode China
keyword
: Search term to filter 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
: Sort order for returned notes (enum: "ASCENDING", "DESCENDING", optional, default: "DESCENDING")
get_note - Retrieves user notes for a specific LeetCode problem
questionId
: The question 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 - Creates a new note for a specific LeetCode problem
questionId
: The question ID of the LeetCode problem (string, required)
content
: The content of the note, supports markdown format (string, required)summary
: An optional short summary or title for the note (string, optional)
update_note - Updates an existing note with new content or summary
noteId
: The ID of the note to update (string, required)
content
: The new content for the note, supports markdown format (string, required)summary
: An optional new short summary or title for the note (string, optional)list_problem_solutions - Retrieves a list of community solutions for a specific problem
questionSlug
: The URL slug/identifier of the problem (string, required)
limit
: Maximum number of solutions to return (number, optional, default: 10)skip
: Number of solutions to skip (number, optional)userInput
: Search term to filter solutions (string, optional)tagSlugs
: Array of tag identifiers to filter solutions (string[], optional, default: [])orderBy
: Sorting criteria for the returned solutions
get_problem_solution - Retrieves the complete content of a specific solution
topicId
: Unique topic ID of the solution (string, required, Global only)
slug
: Unique slug/identifier of the solution (string, required, CN only)Resource Name | Global | CN | Auth Required | Description |
---|---|---|---|---|
problem-categories | ✅ | ✅ | ❌ | A list of all problem classification categories |
problem-tags | ✅ | ✅ | ❌ | A detailed collection of algorithmic and data structure tags |
problem-langs | ✅ | ✅ | ❌ | A complete list of all supported programming languages |
problem-detail | ✅ | ✅ | ❌ | Provides details about a specific problem |
problem-solution | ✅ | ✅ | ❌ | Provides the complete content of a specific solution |
problem-categories - A list of all problem classification categories
URI: categories://problems/all
problem-tags - A detailed collection of algorithmic and data structure tags
URI: tags://problems/all
problem-langs - A complete list of all programming languages supported by LeetCode
URI: langs://problems/all
problem-detail - Provides details about a specific LeetCode problem
URI: problem://{titleSlug}
Parameters:
titleSlug
: Problem identifier as it appears in the LeetCode URLproblem-solution - Provides the complete content of a specific solution
solution://{topicId}
topicId
: Unique topic ID of the solutionsolution://{slug}
slug
: Unique slug/identifier of the solutionUser-specific data access requires LeetCode session authentication:
LEETCODE_SESSION
cookie from browser developer tools--session
flag or LEETCODE_SESSION
environment variableAll 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.
This project is licensed under the MIT License.
[
{
"description": "Retrieves today's LeetCode Daily Challenge problem with complete details, including problem description, constraints, and examples",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
},
"name": "get_daily_challenge"
},
{
"description": "Retrieves details about a specific LeetCode problem, including its description, examples, constraints, and related information",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"titleSlug": {
"description": "The URL slug/identifier of the problem (e.g., 'two-sum', 'add-two-numbers') as it appears in the LeetCode URL",
"type": "string"
}
},
"required": [
"titleSlug"
],
"type": "object"
},
"name": "get_problem"
},
{
"description": "Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"category": {
"default": "all-code-essentials",
"description": "Problem category filter (e.g., 'algorithms', 'database', 'shell') to narrow down the problem domain",
"enum": [
"all-code-essentials",
"algorithms",
"database",
"pandas",
"javascript",
"shell",
"concurrency"
],
"type": "string"
},
"difficulty": {
"description": "Problem difficulty level filter to show only problems of a specific difficulty",
"enum": [
"EASY",
"MEDIUM",
"HARD"
],
"type": "string"
},
"limit": {
"default": 10,
"description": "Maximum number of problems to return in a single request (for pagination)",
"type": "number"
},
"offset": {
"description": "Number of problems to skip (for pagination)",
"type": "number"
},
"searchKeywords": {
"description": "Keywords to search in problem titles and descriptions",
"type": "string"
},
"tags": {
"description": "List of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree'])",
"items": {
"enum": [
"array",
"string",
"hash-table",
"dynamic-programming",
"math",
"sorting",
"greedy",
"depth-first-search",
"binary-search",
"database",
"tree",
"breadth-first-search",
"matrix",
"bit-manipulation",
"two-pointers",
"binary-tree",
"heap-priority-queue",
"prefix-sum",
"stack",
"simulation",
"graph",
"counting",
"sliding-window",
"design",
"backtracking",
"enumeration",
"linked-list",
"union-find",
"ordered-set",
"monotonic-stack",
"number-theory",
"trie",
"segment-tree",
"recursion",
"divide-and-conquer",
"queue",
"combinatorics",
"binary-search-tree",
"bitmask",
"memoization",
"geometry",
"binary-indexed-tree",
"hash-function",
"topological-sort",
"string-matching",
"shortest-path",
"rolling-hash",
"game-theory",
"data-stream",
"interactive",
"monotonic-queue",
"brainteaser",
"doubly-linked-list",
"merge-sort",
"randomized",
"quickselect",
"counting-sort",
"iterator",
"probability-and-statistics",
"concurrency",
"bucket-sort",
"suffix-array",
"line-sweep",
"minimum-spanning-tree",
"shell",
"reservoir-sampling",
"strongly-connected-component",
"eulerian-circuit",
"radix-sort",
"biconnected-component",
"rejection-sampling"
],
"type": "string"
},
"type": "array"
}
},
"type": "object"
},
"name": "search_problems"
},
{
"description": "Retrieves profile information about a LeetCode user, including user stats, solved problems, and profile details",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"username": {
"description": "LeetCode username to retrieve profile information for",
"type": "string"
}
},
"required": [
"username"
],
"type": "object"
},
"name": "get_user_profile"
},
{
"description": "Retrieves a user's recent accepted (AC) submissions on LeetCode China, with details about each successfully solved problem",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"limit": {
"default": 10,
"description": "Maximum number of accepted submissions to return (optional, defaults to server-defined limit)",
"type": "number"
},
"username": {
"description": "LeetCode China username to retrieve recent accepted submissions for",
"type": "string"
}
},
"required": [
"username"
],
"type": "object"
},
"name": "get_recent_ac_submissions"
},
{
"description": "Retrieves a user's contest ranking information on LeetCode, including overall ranking, participation history, and performance metrics across contests",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"attended": {
"default": true,
"description": "Whether to include only the contests the user has participated in (true) or all contests (false); defaults to true",
"type": "boolean"
},
"username": {
"description": "LeetCode username to retrieve contest ranking information for",
"type": "string"
}
},
"required": [
"username"
],
"type": "object"
},
"name": "get_user_contest_ranking"
},
{
"description": "Retrieves a list of community solutions for a specific LeetCode problem, including only metadata like article slug. To view the full content of a solution, use the 'get_problem_solution' tool with the slug returned by this tool.",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"limit": {
"default": 10,
"description": "Maximum number of solutions to return per request. Used for pagination and controlling response size. Default is 20 if not specified. Must be a positive integer. If not provided or set to a very large number, the system may still apply internal limits.",
"minimum": 1,
"type": "number"
},
"orderBy": {
"default": "DEFAULT",
"description": "Sorting criteria for the returned solutions. 'DEFAULT' uses the default algorithm, 'MOST_UPVOTE' sorts by the number of upvotes (highest first), 'HOT' prioritizes trending solutions with recent engagement, 'NEWEST_TO_OLDEST' sorts by publication date (newest first), and 'OLDEST_TO_NEWEST' sorts by publication date (oldest first).",
"enum": [
"DEFAULT",
"MOST_UPVOTE",
"HOT",
"NEWEST_TO_OLDEST",
"OLDEST_TO_NEWEST"
],
"type": "string"
},
"questionSlug": {
"description": "The URL slug/identifier of the problem to retrieve solutions for (e.g., 'two-sum', 'add-two-numbers'). This is the same string that appears in the LeetCode problem URL after '/problems/'",
"type": "string"
},
"skip": {
"description": "Number of solutions to skip before starting to collect results. Used in conjunction with 'limit' for implementing pagination. Default is 0 if not specified. Must be a non-negative integer.",
"type": "number"
},
"tagSlugs": {
"default": [],
"description": "Array of tag identifiers to filter solutions by programming languages (e.g., 'python', 'java') or problem algorithm/data-structure approaches (e.g., 'dynamic-programming', 'recursion'). Only solutions tagged with at least one of the specified tags will be returned.",
"items": {
"type": "string"
},
"type": "array"
},
"userInput": {
"description": "Search term to filter solutions by title, content, or author name. Case insensitive. Useful for finding specific approaches or algorithms mentioned in solutions.",
"type": "string"
}
},
"required": [
"questionSlug"
],
"type": "object"
},
"name": "list_problem_solutions"
},
{
"description": "Retrieves the complete content and metadata of a specific solution, including the full article text, author information, and related navigation links",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"slug": {
"description": "The unique slug/identifier of the solution to retrieve. This slug can be obtained from the 'node.slug' field in the response of the 'list_problem_solutions' tool. A URL-friendly slug string to identify solutions.",
"type": "string"
}
},
"required": [
"slug"
],
"type": "object"
},
"name": "get_problem_solution"
}
]