LeetCode MCP Server

LeetCode MCP Server

site icon
2025.04.17 2
TypeScript编程练习竞赛分析自动化工具开发效率
LeetCode MCP Server 是一个基于 Model Context Protocol (MCP) 的服务,提供与 LeetCode API 的无缝集成,支持对 LeetCode 编程问题、竞赛、解决方案和用户数据的自动化操作和智能交互。
View on GitHub

Overview

基本能力

产品定位

LeetCode MCP Server 是一个专门为开发者设计的工具,旨在通过自动化方式提升在 LeetCode 平台上的编程练习和竞赛体验。

核心功能

  • 多站点支持:支持 leetcode.com 和 leetcode.cn 平台
  • 问题数据检索:获取详细的问题描述、约束条件、示例和解决方案
  • 用户数据访问:检索用户资料、提交历史和竞赛表现
  • 高级搜索功能:按标签、难度级别和类别筛选问题
  • 每日挑战跟踪:轻松访问每日挑战问题

适用场景

  • 自动化获取 LeetCode 问题数据
  • 跟踪用户编程练习进度
  • 分析竞赛表现
  • 批量搜索特定类型的编程问题

工具列表

问题工具

  • leetcode_daily_challenge:获取今日 LeetCode 每日挑战
  • leetcode_problem:获取指定 LeetCode 问题的详细信息
  • leetcode_search_problems:执行过滤搜索

用户工具

  • leetcode_user_profile:获取用户完整资料
  • leetcode_user_contest_ranking:获取用户竞赛排名统计

站点特定工具

  • leetcode_recent_submissions:获取用户最近提交历史(全球站)
  • leetcode_user_recent_ac_submissions:获取用户最近接受的提交(中国站)

认证工具

  • leetcode_user_status:获取认证用户当前状态
  • leetcode_problem_submission_detail:提供详细提交分析

常见问题解答

  • 高级功能需要 LeetCode 会话认证
  • 命令行参数优先于环境变量
  • 支持 JSON 格式的响应

使用教程

使用依赖

  1. Node.js 运行环境
  2. (可选)LeetCode 会话 cookie 用于认证 API 访问

安装教程

通过 Smithery 安装

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

手动安装

npm install @jinzcdev/leetcode-mcp-server -g

# 或使用全局站点配置运行
npx -y @jinzcdev/leetcode-mcp-server --site global

# 带认证运行
npx -y @jinzcdev/leetcode-mcp-server --site global --session <YOUR_LEETCODE_SESSION_COOKIE>

从源码运行

git clone https://github.com/jinzcdev/leetcode-mcp-server.git
cd leetcode-mcp-server
npm run build && node build/index.js --site global

调试方式

Visual Studio Code 集成

在用户设置(JSON)文件中添加以下配置:

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

环境变量

  • LEETCODE_SITE: LeetCode API 端点('global' 或 'cn')
  • LEETCODE_SESSION: 用于认证 API 访问的 LeetCode 会话 cookie

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。