LeetCode MCP Server

by jinzcdev
Verified

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平台
  • 问题数据检索:获取详细的问题描述、约束、示例和解决方法
  • 用户数据访问:检索用户资料、提交历史记录和竞赛表现
  • 高级搜索功能:按标签、难度级别和类别过滤问题
  • 每日挑战追踪:轻松访问每日挑战问题

先决条件

  1. Node.js 运行时环境
  2. (可选)LeetCode 会话 cookie,用于经过身份验证的 API 访问

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 leetcode-mcp-server:

npx -y @smithery/cli install @jinzcdev/leetcode-mcp-server --client claude

手动安装

# Install from npm npm install @jinzcdev/leetcode-mcp-server -g # Or 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>

或者,您可以克隆存储库并在本地运行它:

# Clone the repository git clone https://github.com/jinzcdev/leetcode-mcp-server.git # Navigate to the project directory cd leetcode-mcp-server # Build and run the server npm run build && node build/index.js --site global

用法

Visual Studio Code 集成

将以下 JSON 配置添加到您的用户设置 (JSON) 文件代码中。按Ctrl/Cmd + Shift + P并搜索Preferences: Open User Settings (JSON)即可访问。

{ "mcp": { "servers": { "leetcode": { "type": "stdio", "command": "npx", "args": [ "-y", "@jinzcdev/leetcode-mcp-server", "--site", "global", "--session", "<YOUR_LEETCODE_SESSION_COOKIE>" ] } } } }

对于 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 会话认证:

  1. 登录 LeetCode(全球中国站)
  2. 从浏览器开发者工具中提取LEETCODE_SESSION cookie
  3. 使用--session标志或LEETCODE_SESSION环境变量配置服务器

响应格式

所有工具都返回具有以下结构的 JSON 格式的响应:

{ "content": [ { "type": "text", "text": "JSON_DATA_STRING" } ] }

JSON_DATA_STRING包含请求的数据或失败请求的错误消息。

执照

该项目已获得 MIT 许可。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

模型上下文协议服务器提供与 LeetCode API 的集成,实现 leetcode.com 和 leetcode.cn 平台上编程问题、竞赛、解决方案和用户数据的自动交互。

  1. Features
    1. Prerequisites
      1. Installation
        1. Installing via Smithery
        2. Manual Installation
      2. Usage
        1. Visual Studio Code Integration
      3. Environment Variables
        1. Tools
          1. Problem Tools
          2. User Tools
          3. Global Site-Specific User Tools
          4. China Site-Specific User Tools
          5. Authenticated Common Tools
          6. Global Site-Specific Authenticated Tools
          7. China Site-Specific Authenticated Tools
        2. Resources
          1. Authentication
            1. Response Format
              1. License
                ID: 4gwka0r9rw