|
1 | | -# LeetCode MCP Server |
| 1 | +# MCP Server LeetCode |
2 | 2 |
|
3 | | -A Model Context Protocol (MCP) server for LeetCode that interacts with the LeetCode API using GraphQL queries. |
| 3 | +[](https://www.npmjs.com/package/@mcpfun/mcp-server-leetcode) |
| 4 | +[](https://github.com/doggybee/mcp-server-leetcode/blob/main/LICENSE) |
4 | 5 |
|
5 | | -## Features |
| 6 | +一个基于 Model Context Protocol (MCP) 的 LeetCode 服务器,让你的 AI 助手能够访问 LeetCode 的问题、用户信息和竞赛数据。 |
6 | 7 |
|
7 | | -- Access LeetCode problems, user information, and contest data |
8 | | -- Structured access through MCP tools and resources |
9 | | -- Comprehensive error handling |
10 | | -- Modular architecture |
| 8 | +## 特点 |
11 | 9 |
|
12 | | -## Available Tools |
| 10 | +- 🚀 快速访问 LeetCode API |
| 11 | +- 🔍 搜索问题、获取每日挑战、查看用户信息 |
| 12 | +- 🏆 查询竞赛数据和排名 |
| 13 | +- 🧩 完整支持 MCP 工具和资源 |
| 14 | +- 📦 提供命令行接口和可编程 API |
13 | 15 |
|
14 | | -### Problem-related Tools |
15 | | -- `get-daily-challenge`: Retrieve the daily challenge problem |
16 | | -- `get-problem`: Get detailed information about a specific problem by its slug |
17 | | -- `search-problems`: Search for problems based on difficulty, tags, and other criteria |
| 16 | +## 安装 |
18 | 17 |
|
19 | | -### User-related Tools |
20 | | -- `get-user-profile`: Retrieve profile information for a LeetCode user |
21 | | -- `get-user-submissions`: Get submission history for a user |
22 | | -- `get-user-contest-ranking`: Retrieve contest ranking information for a user |
| 18 | +### 全局安装 |
23 | 19 |
|
24 | | -### Contest-related Tools |
25 | | -- `get-contest-details`: Get information about a specific contest |
26 | | -- `get-user-contest-ranking`: Retrieve a user's performance in contests |
| 20 | +```bash |
| 21 | +npm install -g @mcpfun/mcp-server-leetcode |
| 22 | +``` |
| 23 | + |
| 24 | +然后可以直接使用命令行运行: |
| 25 | + |
| 26 | +```bash |
| 27 | +mcp-server-leetcode |
| 28 | +``` |
27 | 29 |
|
28 | | -## Resources |
| 30 | +### 本地安装 |
29 | 31 |
|
30 | | -### Problem Resources |
31 | | -- `leetcode://daily-challenge`: Current daily challenge problem |
32 | | -- `leetcode://problem/{titleSlug}`: Detailed information about a specific problem |
33 | | -- `leetcode://problems{?tags,difficulty,limit,skip}`: List of problems matching query parameters |
| 32 | +```bash |
| 33 | +npm install @mcpfun/mcp-server-leetcode |
| 34 | +``` |
34 | 35 |
|
35 | | -### User Resources |
36 | | -- `leetcode://user/{username}/profile`: User profile information |
37 | | -- `leetcode://user/{username}/submissions{?limit}`: User's submission history |
38 | | -- `leetcode://user/{username}/contest-ranking`: User's contest ranking data |
| 36 | +## 使用方法 |
39 | 37 |
|
40 | | -## Usage Examples |
| 38 | +### 与 Claude for Desktop 集成 |
41 | 39 |
|
42 | | -### Problem Search |
| 40 | +在 Claude for Desktop 的 `claude_desktop_config.json` 文件中添加: |
43 | 41 |
|
| 42 | +```json |
| 43 | +{ |
| 44 | + "mcpServers": { |
| 45 | + "leetcode": { |
| 46 | + "command": "mcp-server-leetcode" |
| 47 | + } |
| 48 | + } |
| 49 | +} |
44 | 50 | ``` |
45 | | -What are the top 5 easy array problems on LeetCode? |
| 51 | + |
| 52 | +对于本地开发: |
| 53 | + |
| 54 | +```json |
| 55 | +{ |
| 56 | + "mcpServers": { |
| 57 | + "leetcode": { |
| 58 | + "command": "node", |
| 59 | + "args": ["/path/to/dist/index.js"] |
| 60 | + } |
| 61 | + } |
| 62 | +} |
46 | 63 | ``` |
47 | 64 |
|
48 | | -This will use the `search-problems` tool with parameters for difficulty level "EASY" and the "array" tag. |
| 65 | +### 作为库使用 |
49 | 66 |
|
50 | | -### Problem Details |
| 67 | +```javascript |
| 68 | +import { LeetCodeService } from '@mcpfun/mcp-server-leetcode'; |
51 | 69 |
|
52 | | -``` |
53 | | -Show me details of the "two-sum" problem on LeetCode. |
| 70 | +// 初始化服务 |
| 71 | +const leetcodeService = new LeetCodeService(); |
| 72 | + |
| 73 | +// 获取每日挑战 |
| 74 | +const dailyChallenge = await leetcodeService.getDailyChallenge(); |
| 75 | + |
| 76 | +// 搜索问题 |
| 77 | +const problems = await leetcodeService.searchProblems({ |
| 78 | + difficulty: 'MEDIUM', |
| 79 | + tags: 'array+dynamic-programming' |
| 80 | +}); |
54 | 81 | ``` |
55 | 82 |
|
56 | | -This will use the `get-problem` tool with the titleSlug "two-sum" to retrieve comprehensive information about the problem. |
| 83 | +## 可用工具 |
57 | 84 |
|
58 | | -### User Profile |
| 85 | +### 问题相关工具 |
59 | 86 |
|
60 | | -``` |
61 | | -What is the LeetCode profile information for user "username123"? |
62 | | -``` |
| 87 | +| 工具名 | 描述 | 参数 | |
| 88 | +|--------|------|------| |
| 89 | +| `get-daily-challenge` | 获取每日挑战 | 无 | |
| 90 | +| `get-problem` | 获取指定问题详情 | `titleSlug` (字符串) | |
| 91 | +| `search-problems` | 搜索满足条件的问题 | `tags` (可选), `difficulty` (可选), `limit` (默认20), `skip` (默认0) | |
63 | 92 |
|
64 | | -This will use the `get-user-profile` tool to retrieve statistics and profile data for the specified user. |
| 93 | +### 用户相关工具 |
65 | 94 |
|
66 | | -### Daily Challenge |
| 95 | +| 工具名 | 描述 | 参数 | |
| 96 | +|--------|------|------| |
| 97 | +| `get-user-profile` | 获取用户信息 | `username` (字符串) | |
| 98 | +| `get-user-submissions` | 获取用户提交历史 | `username` (字符串), `limit` (可选, 默认20) | |
| 99 | +| `get-user-contest-ranking` | 获取用户竞赛排名 | `username` (字符串) | |
67 | 100 |
|
68 | | -``` |
69 | | -What is today's LeetCode daily challenge? |
70 | | -``` |
| 101 | +### 竞赛相关工具 |
71 | 102 |
|
72 | | -This will use the `get-daily-challenge` tool to retrieve the current day's challenge problem. |
| 103 | +| 工具名 | 描述 | 参数 | |
| 104 | +|--------|------|------| |
| 105 | +| `get-contest-details` | 获取竞赛详情 | `contestSlug` (字符串) | |
73 | 106 |
|
74 | | -## Quick Start |
| 107 | +## 可用资源 |
75 | 108 |
|
76 | | -### Install Dependencies |
77 | | -```bash |
78 | | -npm install |
79 | | -``` |
| 109 | +### 问题资源 |
80 | 110 |
|
81 | | -### Build the Project |
82 | | -```bash |
83 | | -npm run build |
84 | | -``` |
| 111 | +- `leetcode://daily-challenge`: 每日挑战 |
| 112 | +- `leetcode://problem/{titleSlug}`: 问题详情 |
| 113 | +- `leetcode://problems{?tags,difficulty,limit,skip}`: 问题列表 |
| 114 | + |
| 115 | +### 用户资源 |
| 116 | + |
| 117 | +- `leetcode://user/{username}/profile`: 用户资料 |
| 118 | +- `leetcode://user/{username}/submissions{?limit}`: 用户提交 |
| 119 | +- `leetcode://user/{username}/contest-ranking`: 用户竞赛排名 |
| 120 | + |
| 121 | +## 本地开发 |
| 122 | + |
| 123 | +克隆仓库并安装依赖: |
85 | 124 |
|
86 | | -### Run the Server |
87 | 125 | ```bash |
88 | | -npm start |
| 126 | +git clone https://github.com/doggybee/mcp-server-leetcode.git |
| 127 | +cd mcp-server-leetcode |
| 128 | +npm install |
89 | 129 | ``` |
90 | 130 |
|
91 | | -### Development Mode |
| 131 | +以开发模式运行: |
| 132 | + |
92 | 133 | ```bash |
93 | 134 | npm run dev |
94 | 135 | ``` |
95 | 136 |
|
96 | | -## Integration Guide |
97 | | - |
98 | | -Connect to this server using Claude for Desktop or other MCP-compatible clients. |
| 137 | +构建项目: |
99 | 138 |
|
100 | | -### Configuration Example (Claude for Desktop) |
101 | | - |
102 | | -Add the following to your Claude for Desktop `claude_desktop_config.json` file: |
103 | | - |
104 | | -```json |
105 | | -{ |
106 | | - "mcpServers": { |
107 | | - "leetcode": { |
108 | | - "command": "node", |
109 | | - "args": ["/path/to/leetcode-mcp-server/dist/index.js"] |
110 | | - } |
111 | | - } |
112 | | -} |
| 139 | +```bash |
| 140 | +npm run build |
113 | 141 | ``` |
114 | 142 |
|
115 | | -## Clean Installation |
| 143 | +## 许可证 |
116 | 144 |
|
117 | | -For a fresh setup, you can use the provided script: |
| 145 | +MIT |
118 | 146 |
|
119 | | -```bash |
120 | | -./clean-install.sh |
121 | | -``` |
| 147 | +## 相关项目 |
| 148 | + |
| 149 | +- [Model Context Protocol](https://modelcontextprotocol.io) - MCP 规范和文档 |
| 150 | +- [Claude for Desktop](https://claude.ai/download) - 支持 MCP 的 AI 助手 |
122 | 151 |
|
123 | | -This script will remove existing node_modules and dist directories, install dependencies, and build the project. |
| 152 | +## 致谢 |
124 | 153 |
|
125 | | -## References |
126 | | -- Inspired by [alfa-leetcode-api](https://github.com/alfaarghya/alfa-leetcode-api) |
127 | | -- Implemented using the [Model Context Protocol](https://modelcontextprotocol.io) specification |
| 154 | +- 这个项目受到 [alfa-leetcode-api](https://github.com/alfaarghya/alfa-leetcode-api) 的启发 |
0 commit comments