README
🚀 MCP 服务器 LeetCode
一个为 LeetCode 设计的模型上下文协议(MCP)服务器,让 AI 助手能够轻松访问 LeetCode 问题、用户信息和比赛数据,为开发者和用户提供便捷服务。
✨ 主要特性
- 🚀 可快速访问 LeetCode API。
- 🔍 支持搜索问题、获取每日挑战以及查看用户资料。
- 🏆 能够查询比赛数据和排名。
- 🧩 完全支持 MCP 工具和资源。
- 📦 通过 NPM 包提供,安装和使用都很方便。
📦 安装指南
方法一:通过 Smithery 安装
# 使用指定版本进行安装
smithery install @doggybee/mcp-server-leetcode@1.0.1
方法二:全局安装
npm install -g @mcpfun/mcp-server-leetcode
方法三:本地安装
npm install --save-dev @mcpfun/mcp-server-leetcode
💻 使用示例
基础用法
在终端(CLI)中使用
# 启动 MCP 服务器
mcp-server-leetcode start
# 停止 MCP 服务器
mcp-server-leetcode stop
# 查看 MCP 服务器状态
mcp-server-leetcode status
在程序中集成使用
const { Server } = require('@mcpfun/mcp-server-leetcode');
// 初始化服务器并指定配置文件路径
const server = new Server({
configPath: './config.json'
});
// 启动服务器
server.start();
// 停止服务器
server.stop();
高级用法
针对 Claude Desktop 的配置
- 将 MCP 服务器添加为插件:
claude plugin add https://github.com/doggybee/mcp-server-leetcode
- 在
config.json中进行如下配置:
{
"mcpServer": {
"enable": true,
"port": 3001,
"host": "localhost"
}
}
📚 详细文档
可用工具
MCP 工具列表
| 工具名称 | 描述 | 示例命令或语法 |
| ---- | ---- | ---- |
| mcp-server-leetcode | 启动和管理 MCP 服务器 | mcp-server-leetcode startmcp-server-leetcode stop |
| mcp-client | 控制 LeetCode 操作 | mcp-client search "二分查找" |
资源列表
| 资源名称 | 描述 | 示例 URL 结构 |
| ---- | ---- | ---- |
| /api/problems | 获取所有问题 | http://localhost:3001/api/problems |
| /api/problem/<id> | 获取特定问题 | http://localhost:3001/api/problem/123 |
| /api/users/<username> | 获取用户资料 | http://localhost:3001/api/users/username |
本地开发
克隆仓库
git clone https://github.com/doggybee/mcp-server-leetcode.git
cd mcp-server-leetcode
安装依赖
npm install
启动开发服务器
npm run dev
📄 许可证
🔗 相关项目
- MCP 规范和文档 - MCP 详细说明和技术文档
- Claude Desktop - 支持 MCP 的 AI 助手
🙏 致谢
此项目灵感来源于 alfa-leetcode-api
Scan to contact