哔哩哔哩mcp工具

aqiuX17/bilibili_MCP_Stdio
2 Stars 644 次浏览 更新于 2026-08-23

> ⚠️ 重要声明:本项目仅供学习交流使用,严禁商业用途。详细声明请查看 > 🔒 隐私保护:本项目已对所有敏感信息进行脱敏处理,请在使用前配置您自己的Cookie信息 这是一个基于 FastMCP 的 B站信息获取服务器,支持通过 stdio 协议与 MCP 客户端通信,可以获取B站的各种信息,包括视频信息、用户信息、搜索功能等。 > ⚠️ 重要声明:本项目仅供学习交流使用,严禁商业用途。详细声明请查看 > 🔒 隐私保护:本项目已对所有敏感信息进行脱敏处理,请在使用前配置您自己的Cookie信息 这是一个基于 FastMCP 的 B站信息获取服务器,支持通过 stdio 协议与 MCP 客户端通信,可以获取B站的各种信息,包括视频信息、用户信息、搜索功能等。 v1.1.0 - 修复了所有已知问题,确保功能稳定运行: - ✅ 修复了MCP服务器启动异常 - ✅ 修复了编码问题 - ✅ 改进了错误处理机制 - ✅ 添加了日志记录功能 - ✅ 优化了API调用稳定性 - ✅ 添加了连接测试功能 - 支持设置B站cookie,避免反爬限制 - 自动管理cookie状态 - 安全的cookie信息显示

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "bilibili": {
      "args": [
        "/Users/octopus/Downloads/mcpnormol/main.py"
      ],
      "command": "python",
      "env": {
        "PYTHONPATH": "/Users/octopus/Downloads/mcpnormol"
      }
    }
  }
}

服务介绍

Bilibili Information Retrieval MCP Server

⚠️ Important Notice: This project is for learning and communication purposes only. Commercial use is strictly prohibited. For more details, please refer to Application Introduction and Declaration.md

🔒 Privacy Protection: All sensitive information in this project has been desensitized. Please configure your own Cookie information before use.

This is a Bilibili information retrieval server based on FastMCP, supporting communication with MCP clients via the stdio protocol. It can retrieve various types of information from Bilibili, including video information, user information, and search functionalities.

⚠️ Important Notice: This project is for learning and communication purposes only. Commercial use is strictly prohibited. For more details, please refer to Application Introduction and Declaration.md

🔒 Privacy Protection: All sensitive information in this project has been desensitized. Please configure your own Cookie information before use.

This is a Bilibili information retrieval server based on FastMCP, supporting communication with MCP clients via the stdio protocol. It can retrieve various types of information from Bilibili, including video information, user information, and search functionalities.

Preview

preview

🚀 Latest Updates

v1.1.0 - Fixed all known issues to ensure stable operation:

  • ✅ Fixed MCP server startup anomalies
  • ✅ Resolved encoding issues
  • ✅ Improved error handling mechanisms
  • ✅ Added logging functionality
  • ✅ Optimized API call stability
  • ✅ Added connection testing functionality

Features

  • Supports setting Bilibili cookies to avoid anti-crawling restrictions
  • Automatically manages cookie status
  • Secure display of cookie information (hides sensitive parts)
  • Retrieves detailed video information (title, description, views, likes, etc.)
  • Supports BV number queries
  • Automatically extracts BV numbers from Bilibili URLs
  • Retrieves video comment information
  • Retrieves basic user information
  • Supports UID queries

🔍 Search Functionality

  • Video search (currently using popular videos as a substitute to ensure stability)
  • Supports multiple sorting methods (comprehensive, views, publish time, bullet comments, favorites)
  • Pagination support
  • Retrieves trending video lists
  • Supports different categories (animation, music, games, technology, etc.)
  • Supports different time ranges (daily, three-day, weekly, monthly)

🛠️ Utility Functions

  • set_bilibili_cookies() - Set Bilibili cookies
  • get_video_info() - Get video information
  • get_user_info() - Get user information
  • search_bilibili_videos() - Search for videos
  • get_video_comments() - Get video comments
  • get_trending_videos() - Get trending videos
  • extract_bvid_from_url() - Extract BV number from URL
  • get_cookie_status() - Check cookie status
  • test_connection() - Test connection status

Install Dependencies


# 使用 uv (推荐)

uv sync



# 或者使用 pip

pip install -r requirements.txt

Usage

1. Start the Server


# Linux/Mac

./start_server.sh



# Windows

start_server.bat



# 手动启动

uv run python main.py

2. Set Cookies (Important!)

🔒 Privacy Protection Note: The cookie_example.json file in this project has been desensitized, and all sensitive information has been replaced with placeholders.

To avoid anti-crawling restrictions, you need to configure your own Bilibili cookies:

Step 1: Obtain Cookies

  1. Log in to bilibili.com
  2. Open the browser developer tools (F12)
  3. Refresh the page in the Network tab
  4. Find any request and copy the Cookie information

Step 2: Configure Cookies
Edit the cookie_example.json file and replace the placeholders with your actual Cookie values:


{

  "SESSDATA": "你的SESSDATA值",

  "bili_jct": "你的bili_jct值",

  "DedeUserID": "你的用户ID",

  "DedeUserID__ckMd5": "你的MD5值",

  "buvid3": "你的buvid3值",

  "buvid4": "你的buvid4值"

}

Important Reminder:

  • ⚠️ Please keep your Cookie information secure and do not share it with others
  • 🔄 Cookies have an expiration date; if authentication fails, update them promptly
  • 🚫 Do not submit real Cookies to public code repositories

3. Test the Functionality

Run the test script to verify the functionality:


# 基本功能测试

uv run python simple_test.py



# 完整功能测试

uv run python test_bilibili.py



# 最终功能测试

uv run python final_test.py

Usage Examples

Retrieve Video Information

# 获取BV号为 BV1xx411c7mu 的视频信息
result = get_video_info("BV1xx411c7mu")

Search for Videos

# 搜索"Python教程",第1页,按点击量排序
result = search_bilibili_videos("Python教程", 1, "click")
# 获取全站3日热门视频
result = get_trending_videos(0, 3)

# 获取游戏分区周榜
result = get_trending_videos(4, 7)

Category ID Explanation

Category ID Category Name
0 Entire Site
1 Animation
3 Music
4 Games
5 Technology
36 Technology
119 Ghost
129 Dance
155 Life
160 Fashion
162 Entertainment
21 Daily
75 Movies
76 TV Series
77 Documentaries
Sort Value Description
totalrank Comprehensive Ranking
click Click Volume
pubdate Publication Date
dm Danmaku Count
stow Favorites Count

Precautions

  1. Cookie Setting: It is strongly recommended to set a valid Bilibili cookie to avoid anti-crawling restrictions.
  2. Request Frequency: Avoid making requests too frequently, and it's suggested to add appropriate delays between requests.
  3. Error Handling: All API calls include error handling, and the returned error messages will help diagnose issues.
  4. Data Format: The returned data is in JSON format, which is convenient for program processing.
  5. Stability: The current version has fixed all known issues to ensure stable operation.

Technical Architecture

  • FastMCP: Built on the FastMCP framework
  • Requests: Handles HTTP requests
  • BeautifulSoup: Parses HTML content (as a fallback)
  • JSON: For data serialization and deserialization
  • Regular Expressions: For URL parsing and BV number extraction
  • Logging System: Complete logging and error tracking

Troubleshooting

Common Issues

  1. Encoding Errors: Fixed, the current version supports Chinese.
  2. API Restrictions: Using cookies can avoid most restrictions.
  3. Connection Timeouts: Reasonable timeout settings have been configured.
  4. Data Parsing: Improved stability of JSON parsing.

📞 Contact Information

For technical questions, suggestions, or cooperation intentions, please contact:

Email: aqiuX17@yeah.net

⚖️ Usage Declaration

This project is for learning and communication purposes only, and commercial use is strictly prohibited.

For detailed usage declarations, disclaimer, and privacy protection information, please refer to:

📋 Application Introduction and Declaration.md

Important Reminders

  • ✅ Allowed: Personal learning, technical research, academic exchanges
  • ❌ Prohibited: Commercial use, profit-making activities, large-scale data collection
  • ❌ Prohibited: Any behavior that violates Bilibili's terms of service
  • 🔒 Privacy: Please keep sensitive information such as cookies secure

By using this project, you agree to comply with the relevant declarations and terms.


Last Updated: January 2025 | Version: v1.1.0

Debugging Methods

  1. Check log output
  2. Use test_connection() to test the connection
  3. Check the status of the cookie
  4. Run test scripts to verify functionality

License

MIT License

Contributions

Feel free to submit Issues and Pull Requests to improve this project!


🚀 Latest Updates

v1.1.0 - Fixed all known issues to ensure stable operation:

  • ✅ Fixed MCP server startup anomalies
  • ✅ Fixed encoding issues
  • ✅ Improved error handling mechanisms
  • ✅ Added logging functionality
  • ✅ Optimized API call stability
  • ✅ Added connection testing functionality

Feature Highlights

  • Supports setting Bilibili cookies to avoid anti-crawling restrictions
  • Automatically manages cookie status
  • Secure display of cookie information (hides sensitive parts)
  • Retrieves detailed video information (title, description, views, likes, etc.)
  • Supports BV number queries
  • Automatically extracts BV numbers from Bilibili URLs
  • Retrieves video comment information
  • Retrieves basic user information
  • Supports UID queries

🔍 Search Functionality

  • Video search (currently uses popular videos as a substitute to ensure stability)
  • Supports multiple sorting methods (comprehensive ranking, click volume, publication date, danmaku count, favorites count)
  • Pagination support
  • Retrieves trending video lists
  • Supports different categories (animation, music, games, technology, etc.)
  • Supports different time ranges (daily, three-day, weekly, monthly rankings)

🛠️ Utility Functions

  • set_bilibili_cookies() - Set Bilibili cookies
  • get_video_info() - Get video information
  • get_user_info() - Get user information
  • search_bilibili_videos() - Search for videos
  • get_video_comments() - Get video comments
  • get_trending_videos() - Get trending videos
  • extract_bvid_from_url() - Extract BV number from URL
  • get_cookie_status() - Check cookie status
  • test_connection() - Test connection status

Installation Dependencies


# 使用 uv (推荐)

uv sync



# 或者使用 pip

pip install -r requirements.txt

Usage Instructions

1. Start the Server


# Linux/Mac

./start_server.sh



# Windows

start_server.bat



# 手动启动

uv run python main.py

2. Set Cookies (Important!)

🔒 Privacy Protection Notice: The cookie_example.json file in this project has been desensitized, and all sensitive information has been replaced with placeholders.

To avoid anti-crawling restrictions, you need to configure your own Bilibili cookies:Step 1: Obtain Cookie

  1. Log in to bilibili.com
  2. Open the browser developer tools (F12)
  3. Refresh the page under the Network tab
  4. Find any request and copy the Cookie information

Step 2: Configure Cookie
Edit the cookie_example.json file, replacing the placeholder with your actual Cookie value:


{

  "SESSDATA": "你的SESSDATA值",

  "bili_jct": "你的bili_jct值",

  "DedeUserID": "你的用户ID",

  "DedeUserID__ckMd5": "你的MD5值",

  "buvid3": "你的buvid3值",

  "buvid4": "你的buvid4值"

}

Important Notice:

  • ⚠️ Please keep your Cookie information secure and do not disclose it to others
  • 🔄 Cookies have an expiration time; if you encounter authentication failures, please update them promptly
  • 🚫 Do not submit real Cookies to public code repositories

3. Test Functionality

Run the test script to verify functionality:


# 基本功能测试

uv run python simple_test.py



# 完整功能测试

uv run python test_bilibili.py



# 最终功能测试

uv run python final_test.py

Usage Examples

Get Video Information

# 获取BV号为 BV1xx411c7mu 的视频信息
result = get_video_info("BV1xx411c7mu")

Search Videos

# 搜索"Python教程",第1页,按点击量排序
result = search_bilibili_videos("Python教程", 1, "click")
# 获取全站3日热门视频
result = get_trending_videos(0, 3)

# 获取游戏分区周榜
result = get_trending_videos(4, 7)

Section ID Explanation

Section ID Section Name
0 Entire Site
1 Animation
3 Music
4 Games
5 Technology
36 Technology
119 Ghost
129 Dance
155 Life
160 Fashion
162 Entertainment
21 Daily Life
75 Movies
76 TV Series
77 Documentaries

Sorting Method Explanation

Sort Value Description
totalrank Comprehensive
click Clicks
pubdate Publish Date
dm Bullet Chats
stow Favorites

Precautions

  1. Cookie Setup: It is strongly recommended to set a valid Bilibili cookie to avoid anti-crawling restrictions.
  2. Request Frequency: Avoid making too frequent requests; it's suggested to add appropriate delays between requests.
  3. Error Handling: All API calls include error handling, and the returned error messages will help diagnose issues.
  4. Data Format: The returned data is in JSON format, which is convenient for program processing.
  5. Stability: The current version has fixed all known issues to ensure stable operation.

Technical Architecture

  • FastMCP: Built on the FastMCP framework
  • Requests: Handles HTTP requests
  • BeautifulSoup: Parses HTML content (as a fallback)
  • JSON: Data serialization and deserialization
  • Regular Expressions: URL parsing and BV number extraction
  • Logging System: Complete logging and error tracking

Troubleshooting

Common Issues

  1. Encoding Errors: Fixed, the current version supports Chinese.
  2. API Restrictions: Using cookies can avoid most restrictions.
  3. Connection Timeouts: Reasonable timeout settings have been configured.
  4. Data Parsing: Improved stability of JSON parsing.

📞 Contact

For technical questions, suggestions, or cooperation intentions, feel free to contact us:

Email: aqiuX17@yeah.net

⚖️ Usage Declaration

This project is for learning and communication purposes only, commercial use is strictly prohibited.

For detailed usage declarations, disclaimer, and privacy protection, please refer to:

📋 Application Introduction and Declaration.md

Important Notice

  • ✅ Allowed: Personal learning, technical research, academic exchanges
  • ❌ Prohibited: Commercial use, profit-making activities, large-scale data collection
  • ❌ Prohibited: Any behavior that violates Bilibili's terms of service
  • 🔒 Privacy: Please keep sensitive information such as Cookies secure

By using this project, you agree to comply with the relevant statements and terms.


Last Update: January 2025 | Version: v1.1.0

Debugging Methods

  1. Check log output
  2. Use test_connection() to test the connection
  3. Check the status of the cookie
  4. Run the test script to verify functionality

License

MIT License

Contributions

Feel free to submit Issues and Pull Requests to improve this project!


🎉 The current version has fixed all known issues and is stable and reliable!

相关 MCP 服务