哔哩哔哩mcp工具
> ⚠️ 重要声明:本项目仅供学习交流使用,严禁商业用途。详细声明请查看 > 🔒 隐私保护:本项目已对所有敏感信息进行脱敏处理,请在使用前配置您自己的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

🚀 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
🔐 Cookie Management
- Supports setting Bilibili cookies to avoid anti-crawling restrictions
- Automatically manages cookie status
- Secure display of cookie information (hides sensitive parts)
📹 Video-related Functions
- Retrieves detailed video information (title, description, views, likes, etc.)
- Supports BV number queries
- Automatically extracts BV numbers from Bilibili URLs
- Retrieves video comment information
👤 User-related Functions
- 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
📊 Trending Content
- 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 cookiesget_video_info()- Get video informationget_user_info()- Get user informationsearch_bilibili_videos()- Search for videosget_video_comments()- Get video commentsget_trending_videos()- Get trending videosextract_bvid_from_url()- Extract BV number from URLget_cookie_status()- Check cookie statustest_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.jsonfile 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
- Log in to bilibili.com
- Open the browser developer tools (F12)
- Refresh the page in the Network tab
- 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")
Retrieve Trending Videos
# 获取全站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
- Cookie Setting: It is strongly recommended to set a valid Bilibili cookie to avoid anti-crawling restrictions.
- Request Frequency: Avoid making requests too frequently, and it's suggested to add appropriate delays between requests.
- Error Handling: All API calls include error handling, and the returned error messages will help diagnose issues.
- Data Format: The returned data is in JSON format, which is convenient for program processing.
- 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
- Encoding Errors: Fixed, the current version supports Chinese.
- API Restrictions: Using cookies can avoid most restrictions.
- Connection Timeouts: Reasonable timeout settings have been configured.
- 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
- Check log output
- Use
test_connection()to test the connection - Check the status of the cookie
- 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
🔐 Cookie Management
- Supports setting Bilibili cookies to avoid anti-crawling restrictions
- Automatically manages cookie status
- Secure display of cookie information (hides sensitive parts)
📹 Video-related Features
- Retrieves detailed video information (title, description, views, likes, etc.)
- Supports BV number queries
- Automatically extracts BV numbers from Bilibili URLs
- Retrieves video comment information
👤 User-related Features
- 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
📊 Trending Content
- 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 cookiesget_video_info()- Get video informationget_user_info()- Get user informationsearch_bilibili_videos()- Search for videosget_video_comments()- Get video commentsget_trending_videos()- Get trending videosextract_bvid_from_url()- Extract BV number from URLget_cookie_status()- Check cookie statustest_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.jsonfile 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
- Log in to bilibili.com
- Open the browser developer tools (F12)
- Refresh the page under the Network tab
- 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")
Get Popular Videos
# 获取全站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
- Cookie Setup: It is strongly recommended to set a valid Bilibili cookie to avoid anti-crawling restrictions.
- Request Frequency: Avoid making too frequent requests; it's suggested to add appropriate delays between requests.
- Error Handling: All API calls include error handling, and the returned error messages will help diagnose issues.
- Data Format: The returned data is in JSON format, which is convenient for program processing.
- 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
- Encoding Errors: Fixed, the current version supports Chinese.
- API Restrictions: Using cookies can avoid most restrictions.
- Connection Timeouts: Reasonable timeout settings have been configured.
- 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
- Check log output
- Use
test_connection()to test the connection - Check the status of the cookie
- 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!