home / mcp / bilibili comments mcp server

Bilibili Comments MCP Server

Fetches Bilibili video and dynamic comments for MCP clients with optional Markdown or JSON outputs.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "222wcnm-bilibili-comments-mcp": {
      "url": "https://mcp.example.com/bilibili-comments",
      "headers": {
        "BILIBILI_SESSDATA": "your_sessdata_here"
      }
    }
  }
}

This MCP server lets you fetch Bilibili video and dynamic comments through a client that supports the Model Context Protocol. It uses your Bilibili session data to access comments and provides flexible output formats for downstream processing or display.

How to use

You deploy a local MCP client that runs the Bilibili comments script and connects via MCP. Configure the client to point to the local MCP entry and supply your Bilibili session data. Once configured, you can request video comments or dynamic (feed) comments with options for pagination, sorting, and nested replies. The results can be returned as Markdown for readable viewing or JSON for programmatic processing.

How to install

# prerequisites
node and npm must be available on your system

# 1. clone the project
git clone https://github.com/222wcnm/Bilibili-Comments-MCP.git
cd Bilibili-Comments-MCP

# 2. install dependencies
npm install @modelcontextprotocol/sdk axios

Additional content

Configuration and usage details are provided here so you can run the MCP server and fetch comments smoothly. You will set up a local MCP server entry that the MCP client can start, providing your Bilibili session cookie so requests to Bilibili succeed. If you need to fetch comments, you can call the two main tools described below and choose the output format that fits your workflow.

Configuration and troubleshooting

Environment variable you must provide: - BILIBILI_SESSDATA: Your Bilibili SESSDATA value from cookies. This is needed to access comments on most pages.

How to obtain BILIBILI_SESSDATA: 1. Log in to Bilibili on the web. 2. Open browser developer tools (F12) and go to the Network tab. 3. Refresh a page and find a request to bilibili.com. 4. In the Request Headers, copy the Cookie value and extract SESSDATA=xxx from it.

Common issues and fixes: - Error code 404: The dynamic or video ID is incorrect or the content doesn’t exist anymore. Double-check the ID you provided. - Error code 101: The cookie is expired. Re-authenticate and update SESSDATA. - Error code 403: Access is restricted for this item; you may need to log in or have additional permissions to view comments.

Usage details for the two main tools

get_video_comments retrieves comments for a given video and supports paging, sorting, and nested replies. You can specify either a video ID or a BV/aid, the page number, page size, sort order, whether to include replies, and the output format (markdown or json). This tool is useful when you want a complete thread view for a video.

get_dynamic_comments retrieves comments for a dynamic (post) and also supports paging and nested replies. You provide the dynamic_id, page, pageSize, whether to include replies, and the output format (markdown or json). This is ideal for extracting comments from user posts or activity feeds.

Notes on IDs and cookies

To obtain a dynamic_id from the Bilibili mobile app, open the dynamic, click Share, choose Copy Link, and extract the numeric part of the URL.

Cookies are optional for the requests, but including a valid BILIBILI_SESSDATA improves access reliability for some pages. If you omit cookies, you may see restricted access on certain items.

Available tools

get_video_comments

Fetches comments for a specific video, with options for page, pageSize, sort order, inclusion of nested replies, and output format.

get_dynamic_comments

Fetches comments for a dynamic post, with paging, nested replies, and output format options.