The LeetCode MCP Server provides seamless integration with LeetCode APIs, enabling advanced automation and intelligent interaction with LeetCode's programming problems, contests, solutions, and user data through the Model Context Protocol (MCP).
For Claude Desktop users, you can install automatically via Smithery:
npx -y @smithery/cli install @jinzcdev/leetcode-mcp-server --client claude
Install from npm:
# Global installation
npm install @jinzcdev/leetcode-mcp-server -g
# 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>
Or run directly from the repository:
# 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
node build/index.js --site global
Add the following configuration to your VS Code User Settings (JSON). 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"],
"env": {
"LEETCODE_SITE": "global",
"LEETCODE_SESSION": "<YOUR_LEETCODE_SESSION_COOKIE>"
}
}
}
}
}
{
"mcp": {
"servers": {
"leetcode": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@jinzcdev/leetcode-mcp-server",
"--site",
"global",
"--session",
"<YOUR_LEETCODE_SESSION_COOKIE>"
]
}
}
}
}
For LeetCode China site, change the --site
parameter to cn
.
For get_problem:
titleSlug: The URL slug/identifier of the problem (string, required)
For search_problems:
category: Problem category filter (string, optional, default: "all-code-essentials")
tags: List of topic tags to filter by (string[], optional)
difficulty: Problem difficulty level (enum: "EASY", "MEDIUM", "HARD", optional)
searchKeywords: Keywords to search in titles and descriptions (string, optional)
limit: Maximum number of problems to return (number, optional, default: 10)
offset: Number of problems to skip (number, optional)
For get_user_profile:
username: LeetCode username (string, required)
For get_user_contest_ranking:
username: LeetCode username (string, required)
attended: Include only participated contests (boolean, optional, default: true)
For get_problem_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 status (enum: "ATTEMPTED", "SOLVED", optional)
difficulty: Filter by difficulty levels (string[], optional)
For list_problem_solutions:
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
The server provides several resource URIs that can be accessed directly:
categories://problems/all
tags://problems/all
langs://problems/all
problem://{titleSlug}
solution://{topicId}
solution://{slug}
To access user-specific data:
LEETCODE_SESSION
cookie--session
flag or LEETCODE_SESSION
environment variableTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "leetcode" '{"type":"stdio","command":"npx","args":["-y","@jinzcdev/leetcode-mcp-server","--site","global"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"leetcode": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@jinzcdev/leetcode-mcp-server",
"--site",
"global"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"leetcode": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@jinzcdev/leetcode-mcp-server",
"--site",
"global"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect