An MCP server that enables automated access to LeetCode's problems, solutions, and public data—with optional authentication for user-specific features. Now also supports code submission.

This project provides a server that exposes LeetCode functionalities through the Model-Context Protocol (MCP). It allows users to interact with LeetCode data and perform actions like searching problems, fetching user profiles, and submitting solutions.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
git clone https://github.com/your-username/leetcode-mcpserver.git
cd leetcode-mcpserver
npm install
To run the server, you need to provide your LeetCode session cookie and CSRF token. You can get these from your browser's developer tools after logging into LeetCode.
You can provide the credentials as command-line arguments:
npm run start --session <YOUR_SESSION_COOKIE> --csrf <YOUR_CSRF_TOKEN>
Alternatively, you can set them as environment variables:
export LEETCODE_SESSION=<YOUR_SESSION_COOKIE>
export LEETCODE_CSRF=<YOUR_CSRF_TOKEN>
npm run start
For development, you can use the dev script to automatically restart the server on file changes:
npm run dev --session <YOUR_SESSION_COOKIE> --csrf <YOUR_CSRF_TOKEN>
npx -y @ayushjaipuriyar/leetcode-mcpserver --csrf <YOUR_CSRF_TOKEN> --session <YOUR_LEETCODE_SESSION_COOKIE>
Visual Studio Code Integration 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).
Option 1: Using Environment Variables
{
"mcp": {
"servers": {
"leetcode": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@ayushjaipuriyar/leetcode-mcpserver"],
"env": {
"LEETCODE_CSRF": "global",
"LEETCODE_SESSION": "<YOUR_LEETCODE_SESSION_COOKIE>"
}
}
}
}
}
Option 2: Using Command Line Arguments
{
"mcp": {
"servers": {
"leetcode": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@ayushjaipuriyar/leetcode-mcpserver",
"--csrf",
"global",
"--session",
"<YOUR_LEETCODE_SESSION_COOKIE>"
]
}
}
}
}
The server requires a LeetCode session cookie and CSRF token for authentication. These can be provided either as command-line arguments (--session and --csrf) or as environment variables (LEETCODE_SESSION and LEETCODE_CSRF).
CSRF required for submitting code Session just for authenticated routes
The server exposes the following tools:
The server exposes the following resources:
Stars
0
Forks
0
Watchers
0
Primary Language
TypeScript
# [1.0.0](https://github.com/ayushjaipuriyar/leetcode-mcpserver/compare/v0.1.3...v1.0.0) (2025-07-28) ### Documentation * ✏️ some stuff ([138edc3](https://github.com/ayushjaipuriyar/leetcode-mcpserver/commit/138edc34841d65fec79ebc0b995804fa41e42047)) ### BREAKING CHANGES * 🧨 NPM PUBLISH