Skip to main content
Glama

🐮 Nowcoder MCP Server

MCP Node TypeScript License: MIT

让 AI 直接访问牛客网——搜索题目、浏览面经、获取题解,一切通过 Model Context Protocol。


✨ 功能一览

工具

描述

nowcoder_search

全站搜索(讨论、题目、职位)

nowcoder_list_problems

浏览 ACM/OJ 题库,支持难度筛选

nowcoder_get_problem

获取题目完整描述、示例、限制

nowcoder_get_problem_solutions

获取社区题解列表

nowcoder_list_topic_problems

浏览专题题库(面试 TOP101、SQL 篇等)

nowcoder_get_discussion

获取讨论帖 / 动态的完整内容

nowcoder_get_hot_topics

获取首页热门讨论

nowcoder_browse_interview

浏览面经,支持按公司筛选

Related MCP server: Scira AI MCP Server

🚀 快速开始

前置条件

  • Node.js ≥ 18

  • 系统已安装 Chromium 依赖(用于 Playwright)

安装

git clone https://github.com/yourname/nowcoder-mcp-server.git
cd nowcoder-mcp-server
npm install
npm run build

postinstall 脚本会自动下载 Playwright Chromium。

运行

Stdio 模式(默认,用于 Claude Desktop / Cursor 等本地客户端):

npm start

HTTP 模式(用于远程部署):

npm run start:http
# 默认监听 http://0.0.0.0:3000/mcp

🔌 接入你的 AI 工具

Claude Desktop

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "nowcoder": {
      "command": "node",
      "args": ["/path/to/nowcoder-mcp-server/dist/index.js"]
    }
  }
}

Cursor

编辑 .cursor/mcp.json:

{
  "mcpServers": {
    "nowcoder": {
      "command": "node",
      "args": ["/path/to/nowcoder-mcp-server/dist/index.js"]
    }
  }
}

VS Code (GitHub Copilot)

编辑 .vscode/mcp.json:

{
  "servers": {
    "nowcoder": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/nowcoder-mcp-server/dist/index.js"]
    }
  }
}

远程 HTTP 连接

如果你已将服务部署到公网(参见部署指南),在支持 Streamable HTTP 的客户端中直接填入 URL:

{
  "mcpServers": {
    "nowcoder": {
      "url": "https://your-domain.com/mcp"
    }
  }
}

🛠 工具详细说明

所有工具均支持 response_format 参数("markdown" 或 "json",默认 "markdown")。设为 "json" 时,列表类工具返回带分页元数据的结构化 JSON,详情类工具返回结构化对象。错误响应统一携带 isError: true 标记。

在牛客网上搜索讨论帖、面经、编程题、职位等内容。

// 搜索 Java 面经
{ "query": "Java面经", "type": "discuss", "page": 1 }

// 搜索算法题,返回 JSON
{ "query": "二叉树", "type": "problem", "response_format": "json" }

参数

类型

必填

说明

query

string

是

搜索关键词

type

string

否

"all" / "discuss" / "problem" / "job",默认 "all"

page

number

否

页码,默认 1

response_format

string

否

"markdown" / "json",默认 "markdown"

nowcoder_list_problems — 浏览题库

列出 ACM/OJ 编程题目,返回 ID、标题、难度、通过率。

{ "difficulty": 3, "page": 1 }
{ "keyword": "二叉树", "response_format": "json" }

参数

类型

必填

说明

keyword

string

否

搜索关键词

difficulty

number

否

0(全部) 1-5(星级),默认 0

page

number

否

页码,默认 1

response_format

string

否

"markdown" / "json"

nowcoder_get_problem — 题目详情

获取完整的题目描述,包含输入输出格式、示例数据和时空限制。

{ "problemId": "1001" }
{ "problemId": "1001", "response_format": "json" }

参数

类型

必填

说明

problemId

string

是

题目 ID

response_format

string

否

"markdown" / "json"

nowcoder_get_problem_solutions — 题解列表

获取社区提交的题解,包含作者、标题、摘要、点赞数。

{ "problemId": "1001", "page": 1 }
{ "problemId": "1001", "response_format": "json" }

参数

类型

必填

说明

problemId

string

是

题目 ID

page

number

否

页码,默认 1

response_format

string

否

"markdown" / "json"

nowcoder_list_topic_problems — 专题题库

获取牛客网特定专题的题目列表。

{ "topicId": "295", "page": 1 }
{ "topicId": "199", "response_format": "json" }

参数

类型

必填

说明

topicId

string

是

专题 ID(见下表)

page

number

否

页码,默认 1

response_format

string

否

"markdown" / "json"

常用专题:

ID

专题名称

295

面试 TOP101

199

SQL 篇

196

面试高频题目

182

笔试大厂真题

383

算法学习篇

389

笔试模板必刷

260

前端篇

nowcoder_get_discussion — 讨论帖详情

获取讨论帖的完整内容,支持 Markdown 或结构化 JSON 输出。

{ "url": "353154004265934848" }
{ "url": "https://www.nowcoder.com/discuss/353154004265934848", "response_format": "json" }

参数

类型

必填

说明

url

string

是

完整 URL、discuss ID 或 feed UUID

response_format

string

否

"markdown" / "json"

nowcoder_get_hot_topics — 热门内容

无需参数,返回牛客网当前热门讨论和话题(最多 20 条)。

nowcoder_browse_interview — 浏览面经

浏览面试经验分享,支持按公司名称筛选。

{ "page": 1 }
{ "company": "字节跳动", "page": 1, "response_format": "json" }

参数

类型

必填

说明

company

string

否

公司名称筛选

page

number

否

页码,默认 1

response_format

string

否

"markdown" / "json"

JSON 响应格式

列表类工具在 response_format: "json" 时返回 PaginatedResult 结构:

{
  "items": [ ... ],
  "page": 1,
  "count": 10,
  "has_more": true
}
  • has_more 基于当前页是否有结果推断(爬虫场景无法获取精确总数)

  • 详情类工具返回对应的结构化对象

⚙️ 环境变量

变量

默认值

说明

TRANSPORT

stdio

传输模式:stdio / http / https

PORT

3000

HTTP 模式监听端口

HOST

0.0.0.0

HTTP 模式监听地址(本地开发建议 127.0.0.1)

ALLOWED_ORIGINS

*

CORS 允许的来源,多个用逗号分隔

SSL_CERT

—

自定义 SSL 证书路径

SSL_KEY

—

自定义 SSL 私钥路径

🌐 部署到服务器

方案一:Caddy 反向代理(推荐)

最简单的公网部署方案,Caddy 自动管理 Let's Encrypt 证书:

# 1. 以 HTTP 模式启动 MCP 服务
TRANSPORT=http PORT=3001 node dist/index.js

# 2. 安装 Caddy 并配置反向代理
apt install caddy
cat > /etc/caddy/Caddyfile << EOF
your-domain.com {
    reverse_proxy localhost:3001
}
EOF
systemctl restart caddy

MCP 地址:https://your-domain.com/mcp

没有域名? 可以使用 your-ip.sslip.io 作为免费域名,Caddy 同样能自动获取证书。

方案二:Systemd 服务

cp deploy/nowcoder-mcp.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now nowcoder-mcp

方案三:ngrok 内网穿透

# 启动 HTTP 模式
TRANSPORT=http node dist/index.js &

# 使用 ngrok 暴露
ngrok http 3000

MCP 地址:https://xxxx.ngrok-free.app/mcp

🏗 项目结构

src/
├── index.ts              # 入口,Stdio / HTTP / HTTPS 传输
├── constants.ts          # 配置常量
├── types.ts              # TypeScript 类型定义
├── schemas/
│   └── index.ts          # Zod 输入校验
├── services/
│   ├── browser.ts        # Playwright 浏览器管理(连接池、重试、反检测)
│   └── scraper.ts        # 页面解析工具(HTML→Markdown、截断)
└── tools/
    ├── search.ts         # 全站搜索
    ├── problems.ts       # 题库相关(列表、详情、题解、专题)
    ├── discussions.ts    # 讨论帖 & 热门内容
    └── interview.ts      # 面经浏览

🔧 开发

# 开发模式(热重载)
npm run dev

# HTTP 模式开发
npm run dev:http

# 构建
npm run build

# 清理
npm run clean

技术要点

  • MCP 规范合规:错误响应携带 isError: true,列表工具返回分页元数据(PaginatedResult),支持 response_format 双格式输出

  • 无状态 HTTP:每个请求独立处理,不维护服务端会话,适合水平扩展和无状态部署

  • Playwright + Stealth 插件:使用 playwright-extra 搭配反检测插件,规避网站的爬虫检测

  • 智能重试:对超时、网络错误、限流自动指数退避重试(最多 3 次)

  • 资源优化:拦截图片、字体、样式表等非必要资源,加速页面加载

  • CORS 安全:通过 ALLOWED_ORIGINS 环境变量配置允许的跨域来源,默认 *

  • 内容安全:25,000 字符自动截断,防止上下文窗口溢出

📄 License

MIT


免责声明:本项目仅供学习和研究使用。请遵守牛客网的使用条款,合理使用,避免高频请求对其服务造成影响。

Available Tools

8 tools
nowcoder_browse_interview浏览面经A
Read-onlyIdempotent

浏览牛客网面试经验,支持按公司名筛选。

Args:

  • company (string): 公司名称(可选),如 "字节跳动", "阿里巴巴", "腾讯"

  • page (number): 页码,从1开始

  • response_format (string): 输出格式 - "markdown"(默认, 人类可读) 或 "json"(机器可解析)

Returns: 面经列表,包含标题、公司、作者、摘要、时间

Examples:

  1. 浏览全部面经第1页: { "page": 1 }

  2. 按公司筛选面经: { "company": "字节跳动", "page": 1 }

  3. 获取JSON格式结果用于程序处理: { "company": "阿里巴巴", "page": 2, "response_format": "json" }

Error Handling:

  • 若页面加载超时,将返回超时错误提示,建议稍后重试

  • 若网络异常,将返回网络连接失败提示

  • 若未找到指定公司的面经,将返回空结果提示并建议更换关键词

Inputs: page, company, response_format.

nowcoder_get_discussion获取讨论帖详情A
Read-onlyIdempotent

获取牛客网讨论帖或动态的完整内容。

Args:

Returns: 帖子内容,包含标题、作者、时间、正文、标签、链接

Examples:

  • 获取帖子详情 (markdown): { "url": "353154004265934848" }

  • 获取帖子详情 (json): { "url": "353154004265934848", "response_format": "json" }

Error Handling:

  • 页面加载超时时返回超时错误提示

  • 网络连接失败时返回网络错误提示

Inputs: url (required), response_format.

nowcoder_get_hot_topics获取热门内容A
Read-only

获取牛客网当前热门讨论和话题。

Returns: 热门话题列表,包含标题和链接(最多20条)

Examples:

  • 获取热门内容: 无需参数,直接调用即可

Error Handling:

  • 页面加载超时时返回超时错误提示

  • 网络连接失败时返回网络错误提示

  • 无热门内容时返回空结果提示

Inputs: no named parameters.

nowcoder_get_problem获取题目详情A
Read-onlyIdempotent

获取牛客网特定编程题目的完整描述,包括题面、输入输出格式、示例和限制。

Args:

  • problemId (string): 题目ID

  • response_format (string): 输出格式 - "markdown"(默认) 或 "json"

Returns: 题目详情,包含标题、时间/内存限制、题目描述

Examples:

  • 获取题目: { "problemId": "1001" }

  • JSON格式: { "problemId": "1001", "response_format": "json" }

Error Handling:

  • 题目不存在时返回错误提示

  • 页面加载超时时返回超时提示

Inputs: problemId (required), response_format.

nowcoder_get_problem_solutions获取题解A
Read-onlyIdempotent

获取牛客网特定题目的社区题解列表。

Args:

  • problemId (string): 题目ID

  • page (number): 页码

  • response_format (string): 输出格式 - "markdown"(默认) 或 "json"

Returns: 题解列表,包含作者、标题、摘要、点赞数

Examples:

  • 获取题解: { "problemId": "1001", "page": 1 }

  • JSON格式: { "problemId": "1001", "response_format": "json" }

Error Handling:

  • 题目无题解时返回空结果提示

  • 页面加载超时时返回超时提示

Inputs: problemId (required), page, response_format.

nowcoder_list_problems浏览编程题库A
Read-onlyIdempotent

列出牛客网 ACM/OJ 编程题目,支持按关键词和难度筛选。

Args:

  • keyword (string): 搜索关键词(可选)

  • difficulty (number): 难度 0(全部) 1-5(星级)

  • page (number): 页码

  • response_format (string): 输出格式 - "markdown"(默认, 人类可读) 或 "json"(机器可解析)

Returns: 题目列表,包含 ID、标题、难度、通过率、标签

Examples:

  • 浏览全部题目: { "page": 1 }

  • 按难度筛选: { "difficulty": 3, "page": 1 }

  • 搜索关键词(JSON格式): { "keyword": "二叉树", "response_format": "json" }

Error Handling:

  • 页面加载超时时返回超时提示

  • 网络连接失败时提示检查网络

  • 无匹配题目时建议调整筛选条件

Inputs: page, keyword, difficulty, response_format.

nowcoder_list_topic_problems浏览专题题库A
Read-onlyIdempotent

获取牛客网特定专题(如面试TOP101、SQL篇)的题目列表。

常用 topicId:

  • 295: 面试TOP101

  • 199: SQL篇

  • 196: 面试高频题目

  • 182: 笔试大厂真题

  • 383: 算法学习篇

  • 389: 笔试模板必刷

  • 372: 输入输出练习

  • 260: 前端篇

  • 301: Verilog篇

  • 195: SHELL篇

Args:

  • topicId (string): 专题ID

  • page (number): 页码

  • response_format (string): 输出格式 - "markdown"(默认) 或 "json"

Returns: 专题题目列表,包含编号、标题、难度、通过率

Examples:

  • 面试TOP101: { "topicId": "295", "page": 1 }

  • SQL篇(JSON格式): { "topicId": "199", "response_format": "json" }

Error Handling:

  • 专题不存在时返回错误提示

  • 页面加载超时时返回超时提示

Inputs: topicId (required), page, response_format.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

    TDQS

    A3.8/5.0

    Scored across 8 tools

    Disambiguation4/5

    Most tools target clearly distinct resources or actions, such as problem details, problem solutions, topic problem lists, discussions, and interview experiences. There is some overlap because nowcoder_search can search problems/discussions/jobs, which may overlap with nowcoder_list_problems, nowcoder_get_discussion, and nowcoder_browse_interview, but the type filters and descriptions make the intended use mostly clear.

    Naming Consistency4/5

    All tools use the nowcoder_ prefix and snake_case, and most follow a predictable verb_noun pattern. Minor deviations exist, such as nowcoder_search lacking a clear noun, browse_interview instead of list/get, and slight pluralization differences, but the set remains readable and consistent overall.

    Tool Count5/5

    Eight tools are well-scoped for a read-only Nowcoder browsing server. Each tool maps to a distinct content retrieval need, and there is no obvious redundancy or missing bulk operation that would justify a different count.

    Completeness4/5

    The surface covers the core browsing lifecycle for problems, solutions, topic lists, discussions, hot topics, and interview experiences. Some adjacent Nowcoder content such as contests, rankings, user profiles, or submission history is missing, but these are not central to the apparent read-only browsing purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides AI-powered search capabilities through three specialized tools: web search, people search, and X platform (formerly Twitter) search, all accessible via a Model Context Protocol interface.
      83
      -
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI agents and developers to search, retrieve, and analyze HackerNews content including advanced post search, front page access, full comment trees, and user profile lookups through the Model Context Protocol.
      4
      80 npm
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to search real content from Xiaohongshu and Zhihu, supporting keyword search, note details, and question retrieval.
      8
      4
      MIT