|
| 1 | +--- |
| 2 | +name: interactive-leetcode-mcp |
| 3 | +description: Use when the user wants to practice LeetCode problems, submit solutions, or set up LeetCode integration. Covers MCP server installation, learning-guided practice flow, solution submission, and authentication. |
| 4 | +homepage: https://github.com/SPerekrestova/interactive-leetcode-mcp |
| 5 | +disable-model-invocation: true |
| 6 | +metadata: |
| 7 | + clawdbot: |
| 8 | + requires: |
| 9 | + bins: [npx] |
| 10 | + config: [~/.leetcode-mcp/credentials.json] |
| 11 | + credentials: |
| 12 | + stores: ~/.leetcode-mcp/credentials.json |
| 13 | + contents: csrftoken, LEETCODE_SESSION, createdAt timestamp |
| 14 | + permissions: "0600" |
| 15 | +--- |
| 16 | + |
| 17 | +# Interactive LeetCode MCP |
| 18 | + |
| 19 | +MCP server for LeetCode practice with learning-guided hints, solution submission, and AI-driven authentication. |
| 20 | + |
| 21 | +## Prerequisite: Ensure MCP Server Is Connected |
| 22 | + |
| 23 | +Before anything else, check whether the `get_started` tool is available. If it is, the server is connected — skip to the next section. |
| 24 | + |
| 25 | +**If `get_started` is NOT available**, the MCP server needs to be installed. **Ask the user for confirmation before proceeding** — explain that this will download and run an npm package. |
| 26 | + |
| 27 | +The npm package is [`@sperekrestova/interactive-leetcode-mcp`](https://www.npmjs.com/package/@sperekrestova/interactive-leetcode-mcp) (source: [GitHub](https://github.com/SPerekrestova/interactive-leetcode-mcp)). It runs over stdio transport. Requires Node.js >= 20. |
| 28 | + |
| 29 | +After the user confirms, add to the client's MCP configuration (the exact file varies by client): |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "mcpServers": { |
| 34 | + "leetcode": { |
| 35 | + "command": "npx", |
| 36 | + "args": ["-y", "@sperekrestova/interactive-leetcode-mcp@3.2.0"] |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +For Claude Code specifically, you can also run: |
| 43 | + |
| 44 | +```bash |
| 45 | +claude mcp add --transport stdio leetcode -- npx -y @sperekrestova/interactive-leetcode-mcp@3.2.0 |
| 46 | +``` |
| 47 | + |
| 48 | +**Pin a specific version** (shown above) rather than using `@latest` to avoid executing untested code. Users can check for newer versions at the [npm page](https://www.npmjs.com/package/@sperekrestova/interactive-leetcode-mcp) or [GitHub releases](https://github.com/SPerekrestova/interactive-leetcode-mcp/releases) and update the pinned version after reviewing the changelog. |
| 49 | + |
| 50 | +After adding the server, tell the user to restart their session so the MCP tools become available. Do not proceed with the session flow until `get_started` is accessible. |
| 51 | + |
| 52 | +## First Action: Always Call get_started |
| 53 | + |
| 54 | +At the START of every LeetCode session, call the `get_started` tool. It returns the full usage guide: prompt invocation rules, session flow, learning mode rules, auth flow, and language map. |
| 55 | + |
| 56 | +**Do not skip this** — it is a single fast call, not redundant with tool descriptions. The server has MCP prompts that must be explicitly invoked — they are NOT auto-active. The `get_started` response tells you exactly when and how. |
| 57 | + |
| 58 | +## Session Flow (Critical) |
| 59 | + |
| 60 | +``` |
| 61 | +1. Call get_started <-- FIRST, every session |
| 62 | +2. Invoke leetcode_learning_mode <-- BEFORE any problem discussion |
| 63 | +3. User picks a problem |
| 64 | +4. Invoke leetcode_problem_workflow(problemSlug, difficulty) |
| 65 | +5. Invoke leetcode_workspace_setup(language, problemSlug, codeTemplate) |
| 66 | +6. Guide user with progressive hints (4 levels) |
| 67 | +7. submit_solution when ready |
| 68 | +``` |
| 69 | + |
| 70 | +Steps 2, 4, and 5 are MCP prompt invocations. Invoke them via the Skill tool or equivalent prompt mechanism. All three must happen BEFORE the user starts coding. |
| 71 | + |
| 72 | +**Step 2 is non-negotiable.** If you skip `leetcode_learning_mode`, you will bypass the progressive hint system and may show solutions prematurely. Invoke it before searching for or discussing any problem. |
| 73 | + |
| 74 | +## Prompt Invocation Rules |
| 75 | + |
| 76 | +| Prompt | When | Params | |
| 77 | +| ------------------------------- | --------------------------------------- | ----------------------------------- | |
| 78 | +| `leetcode_learning_mode` | START of session, before any problem | none | |
| 79 | +| `leetcode_problem_workflow` | After user selects a problem | problemSlug, difficulty | |
| 80 | +| `leetcode_workspace_setup` | Before user starts coding | language, problemSlug, codeTemplate | |
| 81 | +| `leetcode_authentication_guide` | On auth need, 401 errors, expired creds | none | |
| 82 | + |
| 83 | +## Learning Mode Rules |
| 84 | + |
| 85 | +- Never show a full solution without working through hint levels 1 → 2 → 3 |
| 86 | +- Level 1: Guiding questions ("What pattern do you see?") |
| 87 | +- Level 2: General approaches ("Consider using a hash map...") |
| 88 | +- Level 3: Specific hints ("Iterate once, tracking seen values...") |
| 89 | +- Level 4: Pseudocode or partial implementation |
| 90 | +- Only show complete solutions when explicitly requested AFTER earlier hints |
| 91 | +- `get_problem_solution` returns full community solutions — Level 4 or explicit request only |
| 92 | + |
| 93 | +## Tool Quick Reference |
| 94 | + |
| 95 | +| Tool | Purpose | Auth? | |
| 96 | +| ------------------------------- | -------------------------------- | ------- | |
| 97 | +| `get_daily_challenge` | Today's challenge | No | |
| 98 | +| `get_problem` | Problem by slug | No | |
| 99 | +| `search_problems` | Find by tags/difficulty/keywords | No | |
| 100 | +| `list_problem_solutions` | Solution metadata (topicIds) | No | |
| 101 | +| `get_problem_solution` | Full solution — **Level 4 only** | No | |
| 102 | +| `submit_solution` | Submit code | No\* | |
| 103 | +| `get_user_profile` | Any user's stats | No | |
| 104 | +| `get_recent_submissions` | Recent submissions | No | |
| 105 | +| `get_recent_ac_submissions` | Accepted submissions | No | |
| 106 | +| `get_user_contest_ranking` | Contest ranking | No | |
| 107 | +| `start_leetcode_auth` | Start auth flow | No | |
| 108 | +| `save_leetcode_credentials` | Validate + save creds | No | |
| 109 | +| `check_auth_status` | Check credential state | No | |
| 110 | +| `get_user_status` | Current user info | **Yes** | |
| 111 | +| `get_problem_submission_report` | Submission detail | **Yes** | |
| 112 | +| `get_problem_progress` | Progress with filters | **Yes** | |
| 113 | +| `get_all_submissions` | All submissions | **Yes** | |
| 114 | + |
| 115 | +\*`submit_solution` requires saved credentials to succeed. |
| 116 | + |
| 117 | +## Auth Flow |
| 118 | + |
| 119 | +1. Before auth-sensitive actions → call `check_auth_status` |
| 120 | +2. If not authenticated or expired → **ask the user if they want to authenticate.** Explain that this will store LeetCode session cookies locally at `~/.leetcode-mcp/credentials.json` (owner-read/write only). Do not proceed without consent. |
| 121 | +3. After consent → invoke `leetcode_authentication_guide` prompt |
| 122 | +4. Call `start_leetcode_auth` → the prompt will guide the user through providing credentials → call `save_leetcode_credentials` with the values the user provides |
| 123 | +5. On success → retry original action |
| 124 | +6. On 401 from any tool → repeat from step 1 |
| 125 | + |
| 126 | +**Always delegate auth guidance to the `leetcode_authentication_guide` prompt.** Do not improvise your own auth instructions — the prompt handles browser-specific guidance, error recovery, and troubleshooting. |
| 127 | + |
| 128 | +**Credential storage:** The MCP server stores credentials locally at `~/.leetcode-mcp/credentials.json` with file permissions `0o600` (owner-read/write only). Only `csrftoken`, `LEETCODE_SESSION`, and a `createdAt` timestamp are stored. Credentials are never transmitted to any third party — they are used exclusively for direct LeetCode API calls. Typical credential lifetime is 7-14 days. |
| 129 | + |
| 130 | +## Submission Language Map |
| 131 | + |
| 132 | +| User says | Pass to submit_solution | |
| 133 | +| ----------------- | ----------------------- | |
| 134 | +| Python / Python 3 | `python3` | |
| 135 | +| Python 2 | `python` | |
| 136 | +| Java | `java` | |
| 137 | +| C++ | `cpp` | |
| 138 | +| JavaScript | `javascript` | |
| 139 | +| TypeScript | `typescript` | |
| 140 | + |
| 141 | +Default: "Python" without version → `python3`. |
| 142 | + |
| 143 | +## Resources (Read-Only Lookups) |
| 144 | + |
| 145 | +| Resource URI | What it provides | |
| 146 | +| --------------------------- | ------------------------------------------------ | |
| 147 | +| `categories://problems/all` | All problem categories | |
| 148 | +| `tags://problems/all` | All 60+ topic tags | |
| 149 | +| `langs://problems/all` | All supported submission languages | |
| 150 | +| `problem://{titleSlug}` | Problem detail | |
| 151 | +| `solution://{topicId}` | Solution detail (same learning-mode rules apply) | |
| 152 | + |
| 153 | +## Common Mistakes |
| 154 | + |
| 155 | +- Jumping to problem search before invoking `leetcode_learning_mode` |
| 156 | +- Showing full solutions without progressing through hint levels 1 → 2 → 3 |
| 157 | +- Not invoking `leetcode_workspace_setup` — code should live in a file, not only in chat |
| 158 | +- Guiding auth manually instead of invoking `leetcode_authentication_guide` |
| 159 | +- Passing `"Python"` to `submit_solution` instead of `"python3"` |
| 160 | +- Not calling `check_auth_status` before auth-sensitive operations |
| 161 | +- Skipping `get_started` and assuming tool descriptions are sufficient |
0 commit comments