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 "Deploy 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 MCP Get 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: LeetCode MCP Server
本地安装
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 工具均为只读,不运行或提交代码。
Available Tools
5 toolsauth_statusA
检查 LeetCode 中国站登录状态,不返回或显示任何 Cookie。
Inputs: no named parameters.
get_problemA
根据中国站题号、中文/英文标题、titleSlug 或题目 URL 获取题目信息。题目查询不需要登录。language 可指定 python3、cpp、java、typescript 等代码模板。
Inputs: query (required), language, include_hints.
get_submissions_by_dateA
获取当前登录用户某个自然日的全部 LeetCode 中国站提交。date 默认为 Asia/Shanghai 时区的今天,格式 YYYY-MM-DD;包含 AC 和失败提交。
Inputs: date, limit, cursor, status, +2 more.
loginB
通过本机安全页面登录 LeetCode 中国站并将 Cookie 保存到系统钥匙串。Cookie 不作为工具参数,也不会进入模型上下文。
Inputs: force.
logoutA
删除系统钥匙串中保存的 LeetCode 中国站凭证。
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a clear, non-overlapping responsibility: authentication lifecycle (login, logout, auth_status), problem lookup (get_problem), and submission history retrieval (get_submissions_by_date). There is no realistic ambiguity between tool purposes.
Most tools follow a readable snake_case pattern with clear verbs and nouns, such as get_problem and get_submissions_by_date. login/logout and auth_status are minor deviations but remain conventional and predictable.
Five tools is well-scoped for a focused LeetCode CN server handling authentication, problem data, and submission history. Each tool earns its place with no redundancy or bloat.
Authentication status/login/logout form a complete lifecycle, and problem fetching plus daily submission retrieval cover the core read-only workflows. Minor gaps such as broader problem search or submission detail endpoints are workable but not critical.
Maintenance
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.
Read-only Chinese Vibe Coding knowledge connector for search, docs, and repo freshness.
Search AtCoder problems and fetch public problem statements through MCP.
Related MCP Servers
- FlicenseNot gradedqualityAmaintenanceEnables automated access to LeetCode problems, solutions, contests, and public or authenticated user data across leetcode.com and leetcode.cn, including problem search, profile and submission retrieval, code execution, and note management.-
- AlicenseNot gradedqualityAmaintenanceEnables automated access to LeetCode problems, contests, solutions, and user data across leetcode.com and leetcode.cn, with optional authentication for private features such as notes, problem lists, progress tracking, and submission analysis.MIT
- AlicenseNot gradedqualityAmaintenanceEnables automated access to LeetCode problems, solutions, contests, and public or authenticated user data across leetcode.com and leetcode.cn, supporting search, submissions, notes, and daily challenges.MIT
- AlicenseNot gradedqualityAmaintenanceEnables automated access to LeetCode problems, official editorials, user-submitted solutions, contests, and user data—including notes, problem lists, and submission history—with optional authentication for private features, across both leetcode.com and leetcode.cn.MIT