LeetCode CN MCP
Provides read-only tools for LeetCode CN, including retrieving problem details by number, title, slug, or URL, and querying submission records for a given date with optional filters.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@LeetCode CN MCPGet problem details for LeetCode CN problem 1 with Python3"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
LeetCode CN MCP
一个面向 leetcode.cn 的安全、只读 MCP 服务,支持:
未登录或 Cookie 过期时,通过本机安全页面引导登录并保存到系统钥匙串。
根据题号、中文/英文标题、
titleSlug或题目 URL 获取题目信息。获取当前用户某个自然日的全部提交记录;默认查询上海时区当天。
LeetCode 没有为这些能力提供公开、稳定的官方 API。本项目调用中国站前端正在使用的 GraphQL/REST 接口,接口变化时可能需要升级本项目。
环境
Python 3.12+
推荐使用 uv
Related MCP server: Interactive LeetCode MCP
本地安装
uv sync --extra dev直接通过 stdio 启动 MCP 服务:
uv run leetcode-mcp用于 MCP 客户端的配置示例:
{
"mcpServers": {
"leetcode-cn": {
"command": "uv",
"args": [
"run",
"--directory",
"/absolute/path/to/leetcode-mcp",
"leetcode-mcp"
]
}
}
}登录
提交记录需要当前账号的登录 Cookie。推荐方式:
uv run leetcode-mcp auth login命令会打开一个仅监听 127.0.0.1 的一次性页面。用户只需粘贴浏览器请求中的完整
Cookie 字符串。服务会自行提取 LEETCODE_SESSION 和 csrftoken,丢弃其余 Cookie,
验证账号后将两个必要值保存到:
macOS Keychain
Windows Credential Locker
Linux Secret Service/KWallet
凭证不会作为 MCP 工具参数,不会写入项目文件,也不会进入模型上下文。
检查或删除凭证:
uv run leetcode-mcp auth status
uv run leetcode-mcp auth logout无系统钥匙串的服务器或 CI 可以使用环境变量作为只读回退:
export LEETCODE_COOKIE='csrftoken=...; ...; LEETCODE_SESSION=...'仍兼容分别设置 LEETCODE_SESSION 和 LEETCODE_CSRFTOKEN。
不要将这些值提交到 Git。
MCP 工具
auth_status
验证当前登录状态,不返回 Cookie。
login
通过 MCP URL elicitation 打开本机安全登录页。若客户端不支持 URL elicitation,使用上面的
leetcode-mcp auth login 命令。
logout
删除系统钥匙串中保存的凭证。环境变量不会被修改。
get_problem
参数:
query:题号、标题、slug 或 URL。language:可选,例如python3、cpp、java、typescript。include_hints:是否返回提示,默认false。
示例:
{"query":"1","language":"python3"}get_submissions_by_date
参数:
date:可选,YYYY-MM-DD;默认今天。timezone:默认Asia/Shanghai。status、language:可选过滤条件。limit:单次最多返回数量,范围 1–500,默认 100。cursor:结果被截断时用于继续分页。
返回所有类型的提交,而不仅是 AC。时间戳会转换成请求指定的时区。
开发与验证
uv run ruff check .
uv run pytest测试默认使用 mock 数据,不需要真实 LeetCode Cookie。真实提交记录集成测试应通过环境变量 显式提供测试账号凭证,且不能在日志或失败快照中输出它们。
安全边界
服务只绑定本机登录页,不向局域网监听。
登录 URL 带 256 位以上的一次性随机 token,并在 10 分钟后失效。
登录页禁止外部脚本、iframe、缓存和 referrer。
不读取浏览器 Cookie 数据库,不接收 LeetCode 密码。
不关闭 TLS 校验,不尝试绕过验证码或站点风控。
目前所有 LeetCode 工具均为只读,不运行或提交代码。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceA Model Context Protocol server that provides integration with LeetCode APIs, enabling automated interaction with programming problems, contests, solutions, and user data across both leetcode.com and leetcode.cn platforms.9239141MIT
- AlicenseAqualityAmaintenanceEnables interactive LeetCode practice with AI-guided authentication, problem solving, solution submission, and learning mode.2415411MIT
- FlicenseNot gradedqualityCmaintenanceEnables Claude to search and retrieve LeetCode problems, user profiles, and statistics through natural language.
- AlicenseNot gradedqualityAmaintenanceEnables interaction with public NowCoder ACM problem pages. Supports fetching problem data and checking health status.MIT
Related MCP Connectors
Search Luogu problems, fetch statements, explore problem sets and get practice recommendations.
Search Codeforces problems and inspect public problem metadata through the official Codeforces API.
Search AtCoder problems and fetch public problem statements through MCP.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/lkastar/leetcode-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server