Skip to main content
Glama
prabhattripathi9351

leetcode-github-assistant

README.md
πŸ€– LeetCode GitHub MCP Assistant

**Turn your personal LeetCode solutions repo into a queryable AI tool β€” right inside Claude Desktop.**

GitHub Repo β†’ Metadata Index β†’ MCP Server β†’ Claude Desktop (natural language queries)

Python 3.x | MCP SDK | GitHub REST API | LeetCode GraphQL API | MIT License

---

## 🧠 What is this?

This project connects a personal GitHub repository of solved LeetCode problems directly to **Claude Desktop** using the **Model Context Protocol (MCP)**. Instead of manually browsing GitHub to find "all array problems I've solved" or hunting for one specific solution file, you can just ask Claude Desktop in plain language β€” and it answers using live data pulled straight from your repo.

*Built as a personal productivity tool to make DSA/LeetCode practice searchable and reviewable through conversation, instead of manual file digging.*

It surfaces:
- Every solved problem tagged by **topic** (array, dynamic-programming, graph, etc.)
- Each problem's **difficulty** (easy/medium/hard), pulled from LeetCode itself
- The **full solution code**, fetched live from GitHub on demand

---

## ✨ Features

| Capability | Description |
|---|---|
| πŸ” **Topic-based search** | Ask for any topic (e.g. "array", "dynamic-programming") and get every matching solved problem with its difficulty |
| πŸ“„ **Live code retrieval** | Fetch the complete solution code for any problem by name or slug, straight from GitHub |
| 🏷️ **Auto-tagging** | Difficulty and topic tags are pulled automatically from LeetCode's own GraphQL API β€” no manual tagging needed |
| ⚑ **Fast parallel indexing** | Uses multithreading to fetch metadata for every problem concurrently instead of one-by-one |
| πŸ”Œ **Native Claude Desktop integration** | Runs as a local MCP server β€” no browser tab switching, no copy-pasting links |

---

## πŸ—οΈ Architecture & Pipeline

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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"
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
![Architecture Diagram](./architecture.png.png)

![MCP Explained](./mcp-explained.png.png)
---

## πŸ› οΈ Tech Stack

| Category | Technology |
|---|---|
| Language | Python 3.x |
| MCP Server | `mcp` SDK (`mcp.server.Server`, stdio transport) |
| Data Source | GitHub REST API, LeetCode GraphQL API |
| Concurrency | `concurrent.futures.ThreadPoolExecutor` |
| HTTP Client | `requests` |
| Client | Claude Desktop (local MCP server config) |

---

## πŸ“ Project Structure

```
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
```

---

## πŸ”Œ Tool Reference (MCP Tools)

| Tool | Input | Description |
|---|---|---|
| `search_by_topic` | `topic: string` (e.g. `"array"`) | Returns all solved problems tagged with that topic, with difficulty |
| `get_solution_code` | `problem_name: string` (e.g. `"0877-stone-game.py"` or `"stone-game"`) | Fetches and returns the full solution code live from GitHub |

---

## πŸš€ Getting Started

### Prerequisites
- Python 3.10+
- A GitHub repo of your own solved LeetCode problems (public, or add a token for private repos)
- [Claude Desktop](https://claude.ai/download) installed

### 1. Clone & install dependencies
```bash
git clone https://github.com/<your-username>/<this-repo>.git
cd <this-repo>
pip install -r requirements.txt
```

### 2. Configure your repo name
Open `build_index_github.py` and set:
```python
GITHUB_REPO = "your-username/your-leetcode-repo"
```

### 3. Build the index
```bash
python build_index_github.py
```
This creates `index.json` with every problem's difficulty and topic tags.

### 4. Connect to Claude Desktop
Open Claude Desktop β†’ **Settings β†’ Developer β†’ Edit Config**, and add:
```json
{
  "mcpServers": {
    "leetcode-github-assistant": {
      "command": "python",
      "args": ["/absolute/path/to/mcp_server.py"]
    }
  }
}
```

> πŸ’‘ On Windows, use double backslashes in the path (e.g. `"D:\\Leetcode_mcp_server\\mcp_server.py"`), and use `python.exe`'s full path if `python` isn't on your system PATH.

### 5. Restart Claude Desktop
Fully quit (End Task in Task Manager, not just close the window) and reopen. Check **Settings β†’ Developer** β€” the server should show status `running`.

### 6. Ask away
```
"array topic ke problems batao"
"show me the code for two-sum"
```

---

## πŸ—ΊοΈ Roadmap Ideas

- [ ] Add difficulty-based filtering tool (e.g. "show me all hard problems")
- [ ] Add a "random problem suggestion" tool for practice
- [ ] Auto-sync index whenever new commits are pushed to the repo (webhook or scheduled rebuild)
- [ ] Support private repos via GitHub personal access token
- [ ] Add retry/caching logic for LeetCode GraphQL calls to reduce indexing time

---

## 🀝 Contributing

This is a personal learning project, but issues and suggestions are welcome β€” feel free to open a PR or an issue.

---

*Built to make personal LeetCode practice conversational β€” instead of digging through GitHub folders, just ask.*

Maintenance

ActivityMaintained
ResponsivenessNo issues