npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

accoding-mcp-server-test-new

v0.1.5

Published

MCP Server for Accoding API-test

Downloads

255

Readme

Accoding MCP Server

MCP Server for Accoding API - Model Context Protocol server for Accoding platform.

项目结构

accoding-mcp-server/
├── src/
│   ├── common/                    # 通用基础层
│   │   ├── constants.ts          # 常量定义(语言、分类、标签等)
│   │   └── registry-base.ts      # 注册基类(简化版,无需区分站点)
│   ├── accoding/                  # Accoding 服务层
│   │   ├── api/                  # RESTful API 调用(替代 GraphQL)
│   │   │   ├── problem-api.ts   # 题目相关 API
│   │   │   ├── user-api.ts      # 用户相关 API
│   │   │   └── contest-api.ts    # 比赛相关 API
│   │   ├── accoding-base-service.ts     # 服务接口定义
│   │   ├── accoding-service-factory.ts  # 工厂类
│   │   └── accoding-service-impl.ts     # 服务实现
│   ├── mcp/                      # MCP 工具和资源层
│   │   ├── tools/                # MCP 工具注册
│   │   │   ├── tool-registry.ts         # 工具注册基类
│   │   │   ├── problem-tools.ts         # 题目工具
│   │   │   ├── user-tools.ts             # 用户工具
│   │   │   ├── contest-tools.ts          # 比赛工具
│   │   │   └── submission-tools.ts      # 提交工具
│   │   └── resources/            # MCP 资源注册
│   │       ├── resource-registry.ts      # 资源注册基类
│   │       ├── problem-resources.ts     # 题目资源
│   │       └── contest-resources.ts     # 比赛资源
│   ├── transport/                 # 传输层
│   │   ├── http-server.ts        # HTTP 服务器实现
│   │   └── mcp-server-factory.ts # MCP Server 创建工厂
│   ├── utils/
│   │   ├── logger.ts             # 日志工具
│   │   └── http-utils.ts         # HTTP 工具函数(CORS、cookie解析)
│   └── index.ts                   # 程序入口
├── package.json
├── tsconfig.json
└── README.md

设计特点

  1. 工厂模式:使用 AccodingServiceFactory 创建服务实例
  2. 注册模式:使用 RegistryBase 统一管理工具和资源的注册
  3. 传输层抽象:支持 stdio 和 HTTP 两种传输模式
  4. 会话隔离:HTTP 模式下每个连接独立的会话和服务实例
  5. 分层架构
    • 入口层 (index.ts) - 解析参数、选择传输模式
    • 传输层 (transport/) - HTTP 服务器实现和会话管理
    • 服务层 (accoding/) - 定义接口、实现业务逻辑
    • API 层 (accoding/api/) - RESTful API 调用封装
    • 工具/资源层 (mcp/) - MCP 工具和资源的注册

安装和运行

# 安装依赖
npm install

# 编译
npm run build

# stdio 模式运行(默认,用于本地开发)
node build/index.js --session "your-cookie"

# HTTP 模式运行(用于服务器部署)
node build/index.js --mode http --port 3000

传输模式说明

stdio 模式(默认)

  • 使用标准输入输出进行通信
  • 适合本地开发和 CLI 工具集成
  • 通过 --session 参数传递 Accoding session cookie

HTTP 模式

  • 通过 HTTP POST 请求进行通信
  • 支持多客户端并发访问
  • 每个连接独立的会话隔离
  • Session cookie 通过 HTTP 请求头传递:
    • X-Accoding-Session header(优先级最高)
    • Cookie header(自动解析)

环境变量

  • ACCODING_SESSION: Accoding 会话 Cookie(stdio 模式使用,HTTP 模式从请求头获取)

HTTP 模式使用说明

启动服务器

node build/index.js --mode http --port 3000

客户端请求示例

1. 初始化连接

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "X-Accoding-Session: your-session-cookie" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "initialize",
    "params": {}
  }'

响应会包含 mcp-session-id header,后续请求需要使用此 ID。

2. 调用工具

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "mcp-session-id: <从初始化响应中获取的session-id>" \
  -H "X-Accoding-Session: your-session-cookie" \
  -d '{
    "jsonrpc": "2.0",
    "id": "2",
    "method": "tools/call",
    "params": {
      "name": "get_contest_problems",
      "arguments": {
        "contestId": "12345"
      }
    }
  }'

会话隔离

  • 每个 HTTP 连接都有独立的会话 ID
  • 每个会话都有独立的 AccodingService 实例
  • 不同客户端的 session cookie 互不影响
  • 连接关闭后自动清理会话资源

待实现功能

当前框架已搭建完成,但 API 调用部分标记为 TODO,需要根据实际的 Accoding API 文档实现:

  • [ ] problem-api.ts - 实现题目相关的 RESTful API 调用
  • [ ] user-api.ts - 实现用户相关的 RESTful API 调用
  • [ ] contest-api.ts - 实现比赛相关的 RESTful API 调用
  • [ ] submission-tools.ts - 实现提交统计功能

与 LeetCode MCP Server 的主要区别

  1. 无站点区分:不需要区分 Global/CN,只有一个实现
  2. RESTful API:使用 RESTful API 替代 GraphQL
  3. 简化注册RegistryBase 只区分认证/非认证,不需要区分站点
  4. API 目录:使用 api/ 目录替代 graphql/ 目录

服务器部署: pm2 start ecosystem.config.cjs

查看状态

pm2 status

查看日志

pm2 logs accoding-mcp pm2 logs accoding-mcp --lines 50

重启应用

pm2 restart accoding-mcp

停止应用

pm2 stop accoding-mcp

删除应用

pm2 delete accoding-mcp

监控

pm2 monit

重新加载(代码更新后)

pm2 reload accoding-mcp

自启动:

1. 先保存当前 PM2 配置

pm2 save

2. 添加到 crontab(就这一行!)

(crontab -l 2>/dev/null; echo "@reboot cd /home/minjiaxu/accoding_mcp_server && pm2 resurrect") | crontab -

3. 验证添加成功

crontab -l