Skip to main content
Glama

LeetCode CN MCP

一个面向 leetcode.cn 的安全、只读 MCP 服务,支持:

  • 未登录或 Cookie 过期时,通过本机安全页面引导登录并保存到系统钥匙串。

  • 根据题号、中文/英文标题、titleSlug 或题目 URL 获取题目信息。

  • 获取当前用户某个自然日的全部提交记录;默认查询上海时区当天。

LeetCode 没有为这些能力提供公开、稳定的官方 API。本项目调用中国站前端正在使用的 GraphQL/REST 接口,接口变化时可能需要升级本项目。

环境

  • Python 3.12+

  • 推荐使用 uv

Related MCP server: Interactive LeetCode MCP

本地安装

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_SESSIONcsrftoken,丢弃其余 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_SESSIONLEETCODE_CSRFTOKEN

不要将这些值提交到 Git。

MCP 工具

auth_status

验证当前登录状态,不返回 Cookie。

login

通过 MCP URL elicitation 打开本机安全登录页。若客户端不支持 URL elicitation,使用上面的 leetcode-mcp auth login 命令。

logout

删除系统钥匙串中保存的凭证。环境变量不会被修改。

get_problem

参数:

  • query:题号、标题、slug 或 URL。

  • language:可选,例如 python3cppjavatypescript

  • include_hints:是否返回提示,默认 false

示例:

{"query":"1","language":"python3"}

get_submissions_by_date

参数:

  • date:可选,YYYY-MM-DD;默认今天。

  • timezone:默认 Asia/Shanghai

  • statuslanguage:可选过滤条件。

  • 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 tools
auth_statusA

检查 LeetCode 中国站登录状态,不返回或显示任何 Cookie。

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.2/5.0
Behavior4/5

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

With zero annotations, the description carries the full behavioral burden and meaningfully addresses the main safety concern of an auth-related tool: '不返回或显示任何 Cookie' (does not return or display any Cookie). This reassures the agent the call is safe and won't leak credentials. The only gap is that it doesn't describe what the successful response contains.

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?

A single compact sentence front-loads the purpose and appends the safety qualifier. There is no redundancy, no restatement of the tool name, and every clause earns its place.

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?

For a zero-parameter status check, the description covers purpose, platform scope, and the key safety behavior. The only real gap is the return format — there is no output schema, so an agent doesn't know whether the result is a boolean, enum, or object. Given the tool's simplicity, this is a minor omission rather than a critical one.

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?

The schema has zero properties, so there are no parameters to document; per the 0-parameter baseline, a 4 applies. The description's no-Cookie clause is behavioral information, not parameter semantics, and the schema already fully covers the (empty) argument surface.

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 uses a specific verb (检查/check) and resource (登录状态/login status), and further narrows scope to LeetCode 中国站 (China site). This clearly distinguishes it from siblings like login and logout, which mutate auth state, and get_problem/get_submissions_by_date, which retrieve other data.

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

Usage Guidelines3/5

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

The role of the tool — verifying whether a session exists — is implied by the description and the sibling set (login/logout), but there is no explicit guidance on when to call it versus alternatives ('use login if no session', 'call before authenticated requests'). An agent can infer the usage, but nothing is stated outright.

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

get_problemA

根据中国站题号、中文/英文标题、titleSlug 或题目 URL 获取题目信息。题目查询不需要登录。language 可指定 python3、cpp、java、typescript 等代码模板。

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes
languageNo
include_hintsNo

TDQS

A3.5/5.0
Behavior3/5

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

With no annotations, the description carries the full burden. It adds useful behavioral context: no login required, multiple query identifier types accepted, and language selects a code template. It does not disclose what happens with include_hints, output shape, or failure behavior, leaving notable transparency gaps.

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?

Two compact sentences with no filler. The primary behavior and query formats are front-loaded, and the login note is a single efficient clause. Every sentence adds value.

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

Completeness3/5

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

The tool has 3 parameters, no output schema, and no annotations. The description covers query and language semantics, but include_hints is left undefined and the return value is not characterized. For a simple read tool this is adequate but not fully complete.

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

Parameters3/5

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

Since schema description coverage is 0%, the description must compensate. It gives meaningful meaning for query (possible identifier formats) and language (python3, cpp, java, typescript code templates), but it does not explain the include_hints parameter at all, and the language list is only illustrative.

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

Purpose4/5

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

The description clearly states a specific verb and resource: retrieving problem information by Chinese site problem number, title, titleSlug, or URL. It does not explicitly differentiate itself from sibling tools, but the resource scope (problems vs. auth/submissions) is unambiguous.

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

Usage Guidelines3/5

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

The description implies when to use the tool (whenever problem info is needed) and provides the helpful note that login is not required. However, it does not mention when not to use it, nor does it compare against the sibling tools such as get_submissions_by_date.

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

get_submissions_by_dateA

获取当前登录用户某个自然日的全部 LeetCode 中国站提交。date 默认为 Asia/Shanghai 时区的今天,格式 YYYY-MM-DD;包含 AC 和失败提交。

ParametersJSON Schema
NameRequiredDescriptionDefault
dateNo
limitNo
cursorNo
statusNo
languageNo
timezoneNoAsia/Shanghai

TDQS

A3.8/5.0
Behavior3/5

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

With no annotations, the description carries the disclosure burden and does reveal non-obvious behavior: the Asia/Shanghai timezone default, YYYY-MM-DD date format, inclusion of both AC and failed submissions, and the 'current user' scope. However, it omits auth requirements, pagination behavior, and what happens with invalid or missing login.

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?

One dense sentence conveys the core action, scope, default date, timezone, format, and inclusion set with no filler. All content earns its place.

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

Completeness3/5

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

For basic use (just a date), the description plus schema defaults are sufficient. But with no output schema and 0% parameter coverage, the description under-specifies pagination, filter values, and authentication-state behavior, so it is not fully complete for advanced invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description should compensate. It adds meaning for date (default, timezone, format) and timezone, but says nothing about limit, cursor, status, or language, leaving most parameters semantically underspecified.

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 uses a specific verb ('获取'/'get'), identifies the resource (current logged-in user's LeetCode China submissions), and scopes it to a calendar date. This clearly distinguishes it from siblings like auth_status, get_problem, login, and logout.

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

Usage Guidelines4/5

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

It provides clear context: the tool targets the current logged-in user and defaults to Asia/Shanghai today. It does not explicitly name alternatives or when-not-to-use conditions, but there are no directly competing siblings, so the context is sufficient.

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

loginB

通过本机安全页面登录 LeetCode 中国站并将 Cookie 保存到系统钥匙串。Cookie 不作为工具参数,也不会进入模型上下文。

ParametersJSON Schema
NameRequiredDescriptionDefault
forceNo

TDQS

B3.4/5.0
Behavior4/5

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

With no annotations, the description carries the behavioral disclosure burden. It usefully reveals that the Cookie is persisted to the keychain and deliberately kept out of the model context, which is a significant security-relevant behavior. However, it does not explain what happens if the user is already logged in or whether the operation is destructive.

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?

The description is a single concise sentence that front-loads the action and purpose, then adds a key privacy detail. No word is wasted and all content is relevant.

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

Completeness3/5

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

For a simple one-parameter login tool, the description covers the main purpose and an important security behavior. Yet it misses the meaning of the only parameter, force, and gives no guidance on when a forced re-login might be needed or how to verify auth state.

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

Parameters1/5

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

Schema description coverage is 0%, so the description must compensate by explaining the force parameter, but it never mentions force at all. The parameter is entirely unexplained, leaving the agent unable to infer the effect or meaning of force.

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 a specific action (login to LeetCode China) and its key outcome (saving the Cookie to the system keychain). It is easily distinguished from siblings like auth_status, logout, and data-retrieval tools.

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

Usage Guidelines2/5

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

The description does not say when to use login versus auth_status or logout, nor does it mention prerequisites. It implies authentication is needed but gives no explicit usage context or alternatives.

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

logoutA

删除系统钥匙串中保存的 LeetCode 中国站凭证。

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.2/5.0
Behavior4/5

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

With no annotations provided, the description carries the full burden of disclosing side effects. It clearly states that the tool deletes credentials from the system keychain, which is the core behavioral trait. It does not mention whether remote sessions are invalidated, but for a credential-removal operation this is reasonably transparent.

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?

The description is a single, focused sentence with no filler or redundant information. It front-loads the action and resource without unnecessary context or repeated tool name.

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?

For a parameterless tool with no output schema, the description sufficiently explains what the tool does and where it operates. It could add a note about the result or idempotency, but the core behavioral contract is complete enough for an agent to select and invoke it correctly.

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?

The input schema has zero parameters, so the baseline is 4. The description does not need to explain parameter semantics; it appropriately focuses on what operation the tool performs. There is no gap here.

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 uses a specific verb ('删除' / delete) and states the exact resource affected: LeetCode China credentials stored in the system keychain. This clearly distinguishes logout from siblings like login and auth_status, as it is the only one that removes stored credentials.

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

Usage Guidelines3/5

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

The intended usage is implied by the tool name and description: it should be called when the user wants to clear the saved LeetCode China credentials. However, there is no explicit guidance about when to use this instead of auth_status or login, nor any 'when not to use' conditions.

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. Dates show when Glama detected each change.

  1. 5 tool updatesv0.1.0
    • First observedauth_status
    • First observedget_problem
    • First observedget_submissions_by_date
    • First observedlogin
    • First observedlogout

TDQS

A3.9/5.0
Disambiguation5/5

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.

Naming Consistency4/5

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.

Tool Count5/5

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.

Completeness4/5

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

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lkastar/leetcode-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server