Skip to main content
Glama
prabhattripathi9351

leetcode-github-assistant

{"type": "text", "text": "🤖 LeetCode GitHub MCP 助手

将你的个人 LeetCode 题解仓库变成一个可查询的 AI 工具——就在 Claude Desktop 中。

GitHub 仓库 → 元数据索引 → MCP 服务器 → Claude Desktop(自然语言查询)

Python 3.x | MCP SDK | GitHub REST API | LeetCode GraphQL API | MIT 许可证


🧠 这是什么?

该项目使用**模型上下文协议(MCP)**将个人 GitHub 仓库中已解决的 LeetCode 题目直接连接到 Claude Desktop。无需手动浏览 GitHub 来查找“我解决过的所有数组问题”或寻找某个特定的解决方案文件,你只需用自然语言向 Claude Desktop 提问——它就会使用直接来自你仓库的实时数据进行回答。

作为个人生产力工具而构建,通过对话使 DSA/LeetCode 练习变得可搜索和可回顾,而不是手动翻找文件。

它提供:

  • 每个已解决问题的主题标签(array、dynamic-programming、graph 等)

  • 每个问题的难度(简单/中等/困难),直接从 LeetCode 获取

  • 完整的解决方案代码,按需从 GitHub 实时获取


Related MCP server: LeetCode MCP Server

✨ 功能特性

功能

描述

🔍 基于主题的搜索

询问任何主题(例如“array”、“dynamic-programming”),即可获得所有匹配的已解决问题及其难度

📄 实时代码检索

按名称或 slug 直接从 GitHub 获取任何问题的完整解决方案代码

🏷️ 自动打标签

难度和主题标签自动从 LeetCode 自己的 GraphQL API 获取——无需手动打标签

⚡ 快速并行索引

使用多线程并发获取每个问题的元数据,而不是逐个获取

🔌 原生 Claude Desktop 集成

作为本地 MCP 服务器运行——无需切换浏览器标签页,无需复制粘贴链接


🏗️ 架构与流水线

┌─────────────────────────┐
│   GitHub Repo            │   → your solved LeetCode .py/.cpp/.java files
│   Daily_leet_code         │
└────────────┬─────────────┘
             │  GitHub REST API (recursive file listing)
             ▼
┌─────────────────────────┐
│  build_index_github.py   │   → extracts slug from filename
│      (Indexer)            │   → queries LeetCode GraphQL for
└────────────┬─────────────┘     difficulty + topic tags (parallel)
             │  writes
             ▼
┌─────────────────────────┐
│      index.json           │   → local structured metadata store
└────────────┬─────────────┘
             │  loaded at startup
             ▼
┌─────────────────────────┐
│    mcp_server.py          │   → exposes 2 tools over stdio:
│   (MCP Server)             │     search_by_topic, get_solution_code
└────────────┬─────────────┘
             │  MCP / JSON-RPC over stdio
             ▼
┌─────────────────────────┐
│     Claude Desktop        │   → "array topic ke problems batao"
│   (spawns server locally) │   → "0877-stone-game ka code dikhao"
└─────────────────────────┘

架构图

MCP 解释

🛠️ 技术栈

类别

技术

语言

Python 3.x

MCP 服务器

mcp SDK(mcp.server.Server,stdio 传输)

数据源

GitHub REST API、LeetCode GraphQL API

并发

concurrent.futures.ThreadPoolExecutor

HTTP 客户端

requests

客户端

Claude Desktop(本地 MCP 服务器配置)


📁 项目结构

Leetcode_mcp_server/
├── build_index_github.py   # Indexer: scans GitHub repo, builds index.json
├── mcp_server.py            # MCP server: exposes search_by_topic & get_solution_code
├── index.json                # Auto-generated metadata index (gitignored)
├── requirements.txt          # Python dependencies
└── .gitignore

🔌 工具参考(MCP 工具)

工具

输入

描述

search_by_topic

topic: string(例如 \"array\")

返回所有标记了该主题的已解决问题及其难度

get_solution_code

problem_name: string(例如 \"0877-stone-game.py\" 或 \"stone-game\")

从 GitHub 实时获取并返回完整的解决方案代码


🚀 快速开始

前提条件

  • Python 3.10+

  • 一个包含你已解决 LeetCode 题目的 GitHub 仓库(公开,或为私有仓库添加令牌)

  • 已安装 Claude Desktop

1. 克隆并安装依赖

git clone https://github.com/<your-username>/<this-repo>.git
cd <this-repo>
pip install -r requirements.txt

2. 配置你的仓库名称

打开 build_index_github.py 并设置:

GITHUB_REPO = "your-username/your-leetcode-repo"

3. 构建索引

python build_index_github.py

这将创建包含每个问题难度和主题标签的 index.json。

4. 连接到 Claude Desktop

打开 Claude Desktop → 设置 → 开发者 → 编辑配置,然后添加:

{
  "mcpServers": {
    "leetcode-github-assistant": {
      "command": "python",
      "args": ["/absolute/path/to/mcp_server.py"]
    }
  }
}

💡 在 Windows 上,请在路径中使用双反斜杠(例如 \"D:\\\\Leetcode_mcp_server\\\\mcp_server.py\"),如果 python 不在系统 PATH 中,请使用 python.exe 的完整路径。

5. 重启 Claude Desktop

完全退出(在任务管理器中结束任务,而不仅仅是关闭窗口)并重新打开。检查 设置 → 开发者——服务器应显示状态为 running。

6. 开始提问

"array topic ke problems batao"
"show me the code for two-sum"

🗺️ 路线图构想

  • 添加基于难度的筛选工具(例如“显示所有困难问题”)

  • 添加“随机题目推荐”工具用于练习

  • 每当有新提交推送到仓库时自动同步索引(webhook 或定时重建)

  • 通过 GitHub 个人访问令牌支持私有仓库

  • 为 LeetCode GraphQL 调用添加重试/缓存逻辑以减少索引时间


🤝 贡献

这是一个个人学习项目,但欢迎提出问题和建议——随时可以提交 PR 或 issue。


旨在让个人 LeetCode 练习变得对话化——与其翻遍 GitHub 文件夹,不如直接提问。"}

Related MCP Connectors

Related MCP Servers