一个基于 Model Context Protocol (MCP) 的 LeetCode 服务器,让你的 AI 助手能够访问 LeetCode 的问题、用户信息和竞赛数据。
- 🚀 快速访问 LeetCode API
- 🔍 搜索问题、获取每日挑战、查看用户信息
- 🏆 查询竞赛数据和排名
- 🧩 完整支持 MCP 工具和资源
- 📦 提供命令行接口和可编程 API
npm install -g @mcpfun/mcp-server-leetcode然后可以直接使用命令行运行:
mcp-server-leetcodenpm install @mcpfun/mcp-server-leetcode在 Claude for Desktop 的 claude_desktop_config.json 文件中添加:
{
"mcpServers": {
"leetcode": {
"command": "mcp-server-leetcode"
}
}
}对于本地开发:
{
"mcpServers": {
"leetcode": {
"command": "node",
"args": ["/path/to/dist/index.js"]
}
}
}import { LeetCodeService } from '@mcpfun/mcp-server-leetcode';
// 初始化服务
const leetcodeService = new LeetCodeService();
// 获取每日挑战
const dailyChallenge = await leetcodeService.getDailyChallenge();
// 搜索问题
const problems = await leetcodeService.searchProblems({
difficulty: 'MEDIUM',
tags: 'array+dynamic-programming'
});| 工具名 | 描述 | 参数 |
|---|---|---|
get-daily-challenge |
获取每日挑战 | 无 |
get-problem |
获取指定问题详情 | titleSlug (字符串) |
search-problems |
搜索满足条件的问题 | tags (可选), difficulty (可选), limit (默认20), skip (默认0) |
| 工具名 | 描述 | 参数 |
|---|---|---|
get-user-profile |
获取用户信息 | username (字符串) |
get-user-submissions |
获取用户提交历史 | username (字符串), limit (可选, 默认20) |
get-user-contest-ranking |
获取用户竞赛排名 | username (字符串) |
| 工具名 | 描述 | 参数 |
|---|---|---|
get-contest-details |
获取竞赛详情 | contestSlug (字符串) |
leetcode://daily-challenge: 每日挑战leetcode://problem/{titleSlug}: 问题详情leetcode://problems{?tags,difficulty,limit,skip}: 问题列表
leetcode://user/{username}/profile: 用户资料leetcode://user/{username}/submissions{?limit}: 用户提交leetcode://user/{username}/contest-ranking: 用户竞赛排名
克隆仓库并安装依赖:
git clone https://github.com/doggybee/mcp-server-leetcode.git
cd mcp-server-leetcode
npm install以开发模式运行:
npm run dev构建项目:
npm run buildMIT
- Model Context Protocol - MCP 规范和文档
- Claude for Desktop - 支持 MCP 的 AI 助手
- 这个项目受到 alfa-leetcode-api 的启发