Skip to main content
Glama
jinzcdev

LeetCode MCP Server

LeetCode MCP 服务器

NPM 版本 GitHub 许可证 铁匠徽章 中文文档 星星

LeetCode MCP 服务器是一个模型上下文协议 (MCP)服务器,可与 LeetCode API 无缝集成,实现与 LeetCode 的编程问题、竞赛、解决方案和用户数据的高级自动化和智能交互。

特征

  • 🌐多站点支持:支持 leetcode.com(全球)和 leetcode.cn(中国)平台

  • 📊问题数据检索:获取详细的问题描述、约束、示例、官方社论和用户提交的解决方案

  • 👤用户数据访问:检索用户个人资料、提交历史记录和竞赛表现

  • 🔒私人数据访问:创建和查询用户笔记、跟踪问题解决进度以及分析提交详细信息(AC/WA 分析)

  • 🔍高级搜索功能:按标签、难度级别、类别和关键字过滤问题

  • 📅每日挑战访问:轻松访问每日挑战问题

Related MCP server: Linear MCP Server

先决条件

  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)即可访问。

选项 1:使用环境变量

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

选项 2:使用命令行参数

{
  "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 每日挑战题

获取问题

✅

✅

❌

检索特定 LeetCode 问题的详细信息

搜索问题

✅

✅

❌

使用多个过滤条件搜索 LeetCode 问题

用户

工具

全球的

中国

需要授权

描述

获取用户配置文件

✅

✅

❌

检索 LeetCode 用户的个人资料信息

获取用户竞赛排名

✅

✅

❌

获取用户的比赛排名统计信息

获取最近的 ac 提交

✅

✅

❌

检索用户最近接受的提交

获取最近的提交

✅

❌

❌

检索用户最近的提交历史记录

获取用户状态

✅

✅

✅

检索当前用户的当前状态

获取问题提交报告

✅

✅

✅

针对特定问题提供详细的提交分析

获取问题进度

✅

✅

✅

检索当前用户的问题解决进度

获取所有提交

✅

✅

✅

检索当前用户的提交历史记录

笔记

工具

全球的

中国

需要授权

描述

搜索笔记

❌

✅

✅

使用过滤选项搜索用户注释

获取注释

❌

✅

✅

根据问题 ID 检索特定问题的注释

创建注释

❌

✅

✅

为特定问题创建新注释

更新说明

❌

✅

✅

使用新内容更新现有笔记

解决方案

工具

全球的

中国

需要授权

描述

列出问题解决方案

✅

✅

❌

检索特定问题的社区解决方案列表

获取问题解决方案

✅

✅

❌

检索特定解决方案的完整内容

工具参数

问题

  • get_daily_challenge - 检索今天的 LeetCode 每日挑战问题及其完整详细信息

    • 无需参数

  • get_problem - 检索有关特定 LeetCode 问题的详细信息

    • titleSlug :问题的 URL slug/标识符(字符串,必需)

  • search_problems - 根据多个过滤条件搜索 LeetCode 问题

    • category :问题类别过滤器(字符串,可选,默认值:“all-code-essentials”)

    • tags :用于过滤问题的主题标签列表(string[],可选)

    • difficulty :问题难度级别过滤器(枚举:“EASY”,“MEDIUM”,“HARD”,可选)

    • searchKeywords :在问题标题和描述中搜索的关键字(字符串,可选)

    • limit :返回的最大问题数量(数字,可选,默认值:10)

    • offset :要跳过的问题数量(数字,可选)

用户

  • get_user_profile - 检索有关 LeetCode 用户的个人资料信息

    • username :LeetCode 用户名(字符串,必需)

  • get_user_contest_ranking - 检索用户的比赛排名信息

    • username :LeetCode 用户名(字符串,必需)

    • attended :是否仅包含用户参加过的比赛(布尔值,可选,默认值:true)

  • get_recent_submissions - 检索用户在 LeetCode Global 上的最近提交

    • username :LeetCode 用户名(字符串,必需)

    • limit :返回的最大提交数量(数字,可选,默认值:10)

  • get_recent_ac_submissions - 检索用户最近接受的提交

    • username :LeetCode 用户名(字符串,必需)

    • limit :返回的最大提交数量(数字,可选,默认值:10)

  • **get_user_status——**检索当前用户的状态

    • 无需参数

  • get_problem_submission_report - 检索有关特定提交的详细信息

    • id :数字提交 ID(数字,必需)

  • get_problem_progress - 检索当前用户的问题解决进度

    • offset :要跳过的问题数量(数字,可选,默认值:0)

    • limit :返回的最大问题数量(数字,可选,默认值:100)

    • questionStatus :按问题状态过滤(枚举:“ATTEMPTED”,“SOLVED”,可选)

    • difficulty :按难度级别过滤(string[],可选)

  • get_all_submissions - 检索用户提交的分页列表

    • limit :返回的最大提交数量(数字,默认值:20)

    • offset :要跳过的提交次数(数字,默认值:0)

    • questionSlug :可选问题标识符(字符串,可选)

    • lang :编程语言过滤器(字符串,可选,仅限 CN)

    • status :提交状态过滤器(枚举:“AC”、“WA”,可选,仅限 CN)

    • lastKey :用于检索下一页的分页令牌(字符串,可选,仅限 CN)

笔记

  • search_notes - 搜索 LeetCode 中国用户笔记

    • keyword :用于过滤笔记的搜索词(字符串,可选)

    • limit :返回的最大注释数(数字,可选,默认值:10)

    • skip :要跳过的注释数(数字,可选,默认值:0)

    • orderBy :返回注释的排序顺序(枚举:“ASCENDING”,“DESCENDING”,可选,默认值:“DESCENDING”)

  • get_note - 检索特定 LeetCode 问题的用户注释

    • questionId :LeetCode 问题的问题 ID(字符串,必需)

    • limit :返回的最大注释数(数字,可选,默认值:10)

    • skip :要跳过的注释数(数字,可选,默认值:0)

  • create_note - 为特定的 LeetCode 问题创建新的注释

    • questionId :LeetCode 问题的问题 ID(字符串,必需)

    • content :笔记内容,支持 markdown 格式(字符串,必填)

    • summary :注释的可选简短摘要或标题(字符串,可选)

  • update_note - 使用新内容或摘要更新现有注释

    • noteId :要更新的注释的 ID(字符串,必需)

    • content :笔记的新内容,支持 markdown 格式(字符串,必需)

    • summary :注释的可选新简短摘要或标题(字符串,可选)

解决方案

  • list_problem_solutions - 检索特定问题的社区解决方案列表

    • questionSlug :问题的 URL slug/标识符(字符串,必需)

    • limit :返回的最大解决方案数量(数字,可选,默认值:10)

    • skip :跳过的解决方案数量(数字,可选)

    • userInput :用于过滤解决方案的搜索词(字符串,可选)

    • tagSlugs :用于过滤解决方案的标签标识符数组(string[],可选,默认值:[])

    • orderBy :返回解决方案的排序标准

      • 全局:枚举:“HOT”、“MOST_RECENT”、“MOST_VOTES”,可选,默认值:“HOT”

      • CN:枚举:“DEFAULT”、“MOST_UPVOTE”、“HOT”、“NEWEST_TO_OLDEST”、“OLDEST_TO_NEWEST”,可选,默认值:“DEFAULT”

  • get_problem_solution - 检索特定解决方案的完整内容

    • topicId :解决方案的唯一主题 ID(字符串,必需,仅限全局)

    • slug :解决方案的唯一 slug/标识符(字符串,必需,仅限 CN)

可用资源

资源名称

全球的

中国

需要授权

描述

问题类别

✅

✅

❌

所有问题分类类别的列表

问题标签

✅

✅

❌

算法和数据结构标签的详细集合

问题语言

✅

✅

❌

所有受支持的编程语言的完整列表

问题细节

✅

✅

❌

提供有关特定问题的详细信息

问题解决

✅

✅

❌

提供特定解决方案的完整内容

资源 URI

  • 问题类别- 所有问题分类类别的列表

    • URI: categories://problems/all

  • 问题标签- 算法和数据结构标签的详细集合

    • URI: tags://problems/all

  • problem-langs - LeetCode 支持的所有编程语言的完整列表

    • URI: langs://problems/all

  • 问题详情- 提供有关特定 LeetCode 问题的详细信息

    • URI: problem://{titleSlug}

    • 参数:

      • titleSlug :LeetCode URL 中出现的问题标识符

  • 问题解决方案- 提供特定解决方案的完整内容

    • 全局 URI: solution://{topicId}

      • 参数:

        • topicId :解决方案的唯一主题ID

    • CN URI: solution://{slug}

      • 参数:

        • slug :解决方案的唯一 slug/标识符

验证

用户特定数据访问需要 LeetCode 会话认证:

  1. 登录 LeetCode(全球或中国站)

  2. 从浏览器开发者工具中提取LEETCODE_SESSION cookie

  3. 使用--session标志或LEETCODE_SESSION环境变量配置服务器

响应格式

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

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

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

执照

该项目已获得 MIT 许可。

Available Tools

1 tool
get_problem_solutionA

Retrieves full content of a community solution article (read-only, no auth). Requires topicId from list_problem_solutions. Returns article text, author, and metadata as JSON. Use list_problem_solutions first to discover solutions and obtain topicId.

ParametersJSON Schema
NameRequiredDescriptionDefault
topicIdYesSolution topicId from list_problem_solutions response

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description fully covers behavioral traits: read-only, no authentication, and return format (JSON with text, author, metadata).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three concise sentences, front-loaded with purpose and safety, no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Complete for a simple retrieval tool with one parameter and no output schema; mentions return fields and prerequisite step. Could specify error cases, but not required.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, baseline 3. The description adds value by explaining the topicId's origin from list_problem_solutions, which is not in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Retrieves full content of a community solution article' with specific verb and resource. It is unambiguous and needs no sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly instructs to first use list_problem_solutions to obtain topicId, providing clear prerequisite and sequential usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv1.4.0
    • Addedget_problem_solution
    • Removedget_user_contest_ranking
  2. 9 tool updatesv1.4.0
    • Removedget_daily_challenge
    • Removedget_problem
    • Removedget_problem_solution
    • Removedget_recent_ac_submissions
    • Removedget_recent_submissions
    • Changedget_user_contest_ranking2 fields changed
      • changedInput schema / properties / attended / description
        Previous value: -"Whether to include only the contests the user has participated in (true) or all contests (false); defaults to true"New value: +"true = only contests the user attended (default); false = include all contests in history"
      • changedInput schema / properties / username / description
        Previous value: -"LeetCode username to retrieve contest ranking information for"New value: +"LeetCode username whose contest ranking to fetch"
    • Removedget_user_profile
    • Removedlist_problem_solutions
    • Removedsearch_problems
  3. 1 tool updatev1.0.0
    • Changedget_daily_challenge1 field changed
      • removedInput schema / additionalProperties
        Removed value: -false
  4. 9 tool updates
    • First observedget_daily_challenge
    • First observedget_problem
    • First observedget_problem_solution
    • First observedget_recent_ac_submissions
    • First observedget_recent_submissions
    • First observedget_user_contest_ranking
    • First observedget_user_profile
    • First observedlist_problem_solutions
    • First observedsearch_problems

TDQS

A4.2/5.0

Scored across 1 tool

Disambiguation4/5

Only one tool exists, so there is no ambiguity with other tools. However, the tool's dependency on a missing listing tool could cause confusion for agents trying to use it.

Naming Consistency5/5

With a single tool, naming is trivially consistent. The pattern 'get_problem_solution' follows verb_noun convention.

Tool Count1/5

A single tool for a LeetCode server is far too few. Expected operations (list problems, get problem details, submit solutions, etc.) are missing, making the surface extremely limited.

Completeness1/5

The only tool requires a topicId from a non-existent list_problem_solutions tool, rendering it unusable. The surface is severely incomplete.

Maintenance

ActivityInactive
ResponsivenessSlow

Related MCP Connectors

Related MCP Servers