Content
# MCP Bilibili Img Uploader


## Introduction
MCP Bilibili Img Uploader is a server project based on MCP (Model Context Protocol) that allows large language models (LLM) to call tools to upload local images to Bilibili image hosting and return permanent HTTPS links to the images. The project provides a standardized interface for easy integration with large language models, while using Cookie authentication to ensure the security of upload operations.
## Features
- **Bilibili Image Hosting Support**: Directly upload local images to Bilibili image hosting.
- **Direct Link Generation**: Automatically generate permanent HTTPS links for images after successful upload.
- **Standardized Interface**: Based on the MCP protocol, making it easy for large language models to call.
- **Cookie Authentication**: Use Bilibili's `SESSDATA` and `bili_jct` for authentication.
## Acknowledgements
The core code logic for Bilibili API interaction in this project is referenced from [bilibili-img-uploader](https://github.com/xlzy520/bilibili-img-uploader).
## System Requirements
- Python 3.8 or higher.
- `pip` for installing Python packages.
- A valid Bilibili account.
- MCP client application, such as [Claude for Desktop](https://www.claude.ai/download).
## Quick Start
### 1. Get the Code
Save the server code as `bilibili_uploader.py`.
### 2. Install Dependencies
Open a terminal and run the following command to install the necessary packages:
```bash
pip install "mcp[cli]" httpx
```
### 3. Get Bilibili Cookies
1. Log in to [www.bilibili.com](https://www.bilibili.com) in your browser.
2. Press `F12` (or `Cmd + Option + I` on Mac) to open the developer tools.
3. Find the `Application` (Chrome/Edge) or `Storage` (Firefox) tab.
4. Under `Cookies` in the left menu, select `https://www.bilibili.com`.
5. Find and copy the **Value** of the following two items:
- `SESSDATA`
- `bili_jct`
### 4. Run the Server
Open a terminal in the directory where the `bilibili_uploader.py` file is located and start the server:
```bash
python bilibili_uploader.py
```
The server will start and wait for client connections.
### 5. Connect to the MCP Client (using Claude for Desktop as an example)
1. Find and open the `claude_desktop_config.json` configuration file:
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
2. Add the following server configuration to the file, **be sure to replace the path with the absolute path to your `bilibili_uploader.py` script**:
```json
{
"mcpServers": {
"bilibili-uploader": {
"command": "python",
"args": [
"/path/to/your/project/bilibili_uploader.py"
]
}
}
}
```
3. Completely close and restart Claude for Desktop for the configuration to take effect.
### 6. Use in Conversation
- **Step 1: Set Cookies (only once per session)**
In the client, converse with the LLM and enter something like the following:
```plaintext
Please set my Bilibili Cookies. My SESSDATA is `your_sessdata_value_here` and bili_jct is `your_bili_jct_value_here`.
```
- **Step 2: Upload Image**
Enter something like the following:
```plaintext
Please upload the image `/Users/me/Desktop/photo.png` to Bilibili.
```
The LLM will call the tool to complete the upload and return the permanent HTTPS link of the image.
## Code Structure
- `bilibili_uploader.py`: The core code file, which implements the initialization of the MCP server and two tool functions `set_bilibili_cookies` and `upload_image`.
- `README.md`: Project documentation, including project introduction, features, system requirements, quick start steps, etc.
- `LICENSE`: The open source license file used by the project.
## License
This project is licensed under the MIT License, see the [LICENSE](LICENSE) file for details.