remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Integrations
Provides tools for accessing LeetCode problems, user data, search capabilities, and submission tracking across both leetcode.com and leetcode.cn platforms. Enables retrieval of detailed problem descriptions, user profiles, submission history, and contest performance statistics.
LeetCode MCP 服务器
LeetCode MCP 服务器是一个模型上下文协议 (MCP)服务器,可与 LeetCode API 无缝集成,实现与 LeetCode 的编程问题、竞赛、解决方案和用户数据的高级自动化和智能交互。
特征
- 多站点支持:支持leetcode.com和leetcode.cn平台
- 问题数据检索:获取详细的问题描述、约束、示例和解决方法
- 用户数据访问:检索用户资料、提交历史记录和竞赛表现
- 高级搜索功能:按标签、难度级别和类别过滤问题
- 每日挑战追踪:轻松访问每日挑战问题
先决条件
- Node.js 运行时环境
- (可选)LeetCode 会话 cookie,用于经过身份验证的 API 访问
安装
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 leetcode-mcp-server:
手动安装
或者,您可以克隆存储库并在本地运行它:
用法
Visual Studio Code 集成
将以下 JSON 配置添加到您的用户设置 (JSON) 文件代码中。按Ctrl/Cmd + Shift + P
并搜索Preferences: Open User Settings (JSON)
即可访问。
对于 LeetCode 中国站,将--site
参数修改为cn
。
环境变量
服务器支持以下环境变量:
LEETCODE_SITE
:LeetCode API 端点('global' 或 'cn')LEETCODE_SESSION
:用于经过身份验证的 API 访问的 LeetCode 会话 cookie
优先注意事项:
当同时指定命令行参数和环境变量时,命令行参数优先于环境变量。例如:
- 如果设置了
LEETCODE_SITE=cn
但运行leetcode-mcp-server --site global
,则服务器将使用global
。 - 如果
LEETCODE_SESSION
存在但您提供了--session "new_cookie"
,则将使用命令行会话值。
工具
该服务器提供了一套按功能和平台兼容性分类的综合工具。
问题工具
在全球和中国网站上均可使用,并可选择身份验证。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_daily_challenge | 检索今天的 LeetCode 每日挑战,包含完整的元数据 | 没有任何 |
leetcode问题 | 检索指定 LeetCode 问题的详细内容 | titleSlug (字符串,必需):问题 URL 标识符(例如,“two-sum”) |
leetcode 搜索问题 | 对 LeetCode 问题执行过滤搜索 | category (字符串,可选):问题分类tags (string [],可选):主题标签过滤器difficulty (字符串,可选):问题复杂度级别('EASY','MEDIUM','HARD') limit (数字,可选):最大结果数offset (数字,可选):分页偏移量 |
用户工具
在两个平台上提供用户特定的数据。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_user_profile | 检索 LeetCode 用户的完整个人资料信息 | username (字符串,必需):LeetCode 用户名 |
leetcode_user_contest_ranking | 获取用户的比赛排名统计信息 | username (字符串,必需):LeetCode 用户名attended (布尔值,可选):仅过滤参加过的比赛 |
全球站点特定用户工具
leetcode.com 平台独家。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_recent_submissions | 检索用户最近的提交历史记录(全局) | username (字符串,必需):LeetCode 用户名limit (数字,可选):结果限制 |
leetcode_recent_ac_submissions | 检索用户最近接受的提交(全局) | username (字符串,必需):LeetCode 用户名limit (数字,可选):结果限制 |
中国站点专用用户工具
leetcode.cn平台独家。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_user_recent_ac_submissions | 检索最近接受的投稿(中国) | username (字符串,必填):LeetCode 中国用户名limit (数字,可选):结果限制 |
经过认证的常用工具
需要会话身份验证,两个平台均可用。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_user_status | 检索已验证用户的当前状态 | 没有任何 |
leetcode_problem_submission_detail | 提供详细的提交分析 | id (数字,必填):提交ID |
leetcode_user_progress_questions | 跟踪用户解决问题的进度 | offset (数字,必需):分页偏移量limit (数字,必需):结果限制questionStatus (枚举,可选):'已尝试'或'已解决'过滤器difficulty (字符串[],可选):复杂度级别过滤器 |
全球特定站点认证工具
leetcode.com 独有的认证工具。
姓名 | 描述 | 参数 |
---|---|---|
leetcode_user_all_submissions | 检索分页提交历史记录(全局) | limit (数字,必需):结果限制offset (数字,必需):分页偏移questionSlug (字符串,可选):问题标识符过滤器 |
中国特定站点认证工具
leetcode.cn 独家认证工具。
工具名称 | 描述 | 参数 |
---|---|---|
leetcode_user_all_submissions | 检索综合提交历史记录(中国) | limit (数字,必需):结果限制offset (数字,必需):分页偏移questionSlug (字符串,可选):问题标识符lang (字符串,可选):编程语言过滤器status (字符串,可选):提交状态过滤器lastKey (字符串,可选):分页令牌 |
资源
服务器通过URI端点提供平台元数据访问的参考资源。
资源名称 | 描述 | URI |
---|---|---|
问题类别 | 完整的问题分类类别 | leetcode://problems/categories/all |
问题标签 | 算法和数据结构标签收集 | leetcode://problems/tags/all |
问题语言 | 支持的编程语言列表 | leetcode://problems/langs/all |
解决方案文章 | 一篇 LeetCode 解答文章 | 全球: leetcode://solutions/{topicId} cn: leetcode://solutions/{slug} |
验证
高级功能需要 LeetCode 会话认证:
响应格式
所有工具都返回具有以下结构的 JSON 格式的响应:
JSON_DATA_STRING
包含请求的数据或失败请求的错误消息。
执照
该项目已获得 MIT 许可。
You must be authenticated.
模型上下文协议服务器提供与 LeetCode API 的集成,实现 leetcode.com 和 leetcode.cn 平台上编程问题、竞赛、解决方案和用户数据的自动交互。