Content
# J2MCP
A ready-to-use MCP plugin developed in Java
## Features
- 🚀 Supports message forwarding for group chats and private chats
- 🔔 Supports @ message recognition and processing
- 🔄 Supports message queue and retry mechanism
- 🔒 Supports API Token authentication
- 🌐 Supports multiple Webhook address configurations
- 📝 Real-time log display
- 🎯 Supports custom listener objects
- 💾 Configuration file auto-save
- 🔄 Automatic reconnection and error recovery
- 🔍 Supports automatic file encoding detection
## System Requirements
- Windows 10 or higher
- Python 3.9 or higher (only required for source code execution)
- WeChat PC version 3.9.x
## Tutorial
https://zerotrue.xyz/article/1d6484d9-4c67-80eb-926d-ff6fb1588f60
## Installation Steps
### Method 1: Direct Run (Recommended)
1. Download the latest version of `RuoYuBot.exe` from the [Releases](https://github.com/Obito-404/RuoYuBot/releases) page
2. Double-click to run `RuoYuBot.exe`
3. The configuration file will be automatically created on the first run
### Method 2: Source Code Execution
1. Clone the repository:
```bash
git clone https://github.com/Obito-404/RuoYuBot.git
cd ruoyubot
```
2. Install dependencies:
```bash
# Create a virtual environment (recommended)
python -m venv venv
.\venv\Scripts\activate # Windows
source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt
```
3. Run the program:
```bash
python main.py
```
4. Packaging command:
```bash
pyinstaller --noconfirm --onefile --windowed --name "RuoYuBot" --icon "D:/ruoyubot/icon.ico" --hidden-import comtypes --hidden-import comtypes.stream --hidden-import comtypes.gen --hidden-import win32com --hidden-import win32com.client "D:/ruoyubot/main.py"
```
## Dependency Description
Main dependencies:
- wxauto: WeChat automation operations
- requests: HTTP requests
- flask: Web server
- pywin32: Windows system API
- chardet: File encoding detection
- werkzeug: Flask server components
## Configuration Description
The program will automatically create a `config.ini` configuration file on the first run, which includes the following configuration items:
- `listen_list`: Names of group chats or friends to listen to (comma-separated)
- `webhook_urls`: Target addresses for message forwarding (one per line)
- `port`: Local webhook server port
- `retry_count`: Number of retries for message sending
- `retry_delay`: Retry delay time (in seconds)
- `log_level`: Log level
- `api_token`: API authentication token
## Usage Instructions
1. After starting the program, WeChat will automatically open (if not already running)
2. Configure in the GUI:
- Add the group chats or friends to listen to
- Set the webhook callback address
- Configure the API Token
- Set the local port
3. Click the "Start" button to launch the service
## Webhook Interface Description
### Message Receiving Format
```json
{
"target_user": "Group chat name/Friend name",
"message": "Message content",
"timestamp": "2024-01-01 12:00:00",
"is_group": true/false,
"sender": "Sender name",
"chat_name": "Group chat name",
"is_at_me": true/false
}
```
### Message Sending Format
```json
{
"target_user": "Group chat name/Friend name",
"message": "Message to be sent",
"is_group": true/false,
"at_list": ["List of members to @"]
}
```
## Notes
1. Ensure WeChat is logged in and remains online
2. The names of the objects to listen to must match exactly (case-sensitive)
3. It is recommended to regularly check the logs and handle exceptions promptly
4. Please keep the API Token secure to avoid leakage
5. The configuration file uses UTF-8 encoding and supports Chinese characters
## Frequently Asked Questions
1. Q: The program cannot start WeChat, showing an invalid window handle?
A: Please ensure that WeChat PC version 3.9.x is installed and logged in.
2. Q: Message forwarding failed?
A: Check if the webhook address is correct, if the network connection is normal, and if the API Token is configured correctly.
3. Q: Cannot receive group chat messages?
A: Confirm if the group chat name is correct and if it has been added to the listening list.
4. Q: The configuration file appears garbled?
A: The program will automatically detect and convert the configuration file encoding to UTF-8.
## Contribution Guidelines
Feel free to submit Issues and Pull Requests to help improve the project.
## License
MIT License
## Contact Information
If you have any questions or suggestions, please submit an Issue.
## 1. Introduction
Recently, the release of MCP (Model Context Protocol) led by Anthropic has gained significant attention. Those familiar with large models from A should be no strangers to Anthropic, as they released the Claude 3.5 Sonnet model, including the current strongest programming AI model, 3.7 Sonnet. Today, we will analyze what MCP is and whether it is needed under AI large models.
## 2. What is MCP?
MCP (Model Context Protocol) is a standard protocol for interaction between large models and data sources. It aims to achieve persistent and dynamic sharing of context information across models and sessions. It facilitates context transfer, version control, and collaborative reasoning between models through standardized interfaces, addressing the issue of fragmented context in complex AI tasks.
So why is there a need to redefine context management for A|? When we first started using A| large models, we often encountered issues such as context mysteriously disappearing, leading to semantic gaps in conversations. Additionally, different models, such as ChatGPT and DeepSeek, do not share memory, or different versions cannot track changes in context history, which are essentially information silos.
Therefore, we need a dedicated protocol or technology that can connect our context across models and versions, solving the problem of memory sharing. If we observe the entire development process of AI automation, we can see that AI automation is divided into three stages: AI Chat, AI Composer, and AI Agent.
- AI Chat typically only provides suggestions and code snippets, requiring users to manually copy, debug, and integrate in a human-machine collaboration mode.
- AI Composer, compared to AI Chat, supports partial automatic code modification, where we only need to confirm acceptance or rejection. However, it is still limited to context operations on code.
- AI Agent can complete end-to-end task loops. It is a fully autonomous intelligent agent that makes decisions, modifies, and adjusts the required code blocks or autonomously extracts necessary information. We only need to monitor the actions. However, its cross-system collaboration capability is somewhat lacking. Therefore, the further evolutionary path is naturally to enhance the cross-model or cross-system capabilities of AI Agent. It serves as an intermediary layer, acting as the intelligent routing hub for AI Agent.
Friends familiar with Java distributed systems should find this process similar to the development of distributed systems. MCP is more like a standard protocol for RPC. I am not sure if this analogy is appropriate.
## 3. MCP Architecture
The Model Context Protocol (MCP) follows a client-host-server architecture, where each host can run multiple client instances. This architecture allows users to integrate AI functionalities across applications while maintaining clear security boundaries and isolating issues. MCP is built on JSON-RPC, providing a stateful session protocol focused on context exchange and sampling coordination between clients and servers. The official MCP system architecture diagram:

It can be observed that MCP is based on a three-layer hierarchical model:
**MCP Host**: The host application running the A| model or agent, such as the Claude desktop version or AI assistants in certain IDEs. The host application establishes connections with the outside world through the built-in MCP client and initiates the connection.
**MCP Client**: The protocol client component embedded in the host application. Each MCP client maintains a one-to-one connection with a specific MCP server to send requests or receive responses. A host application can run multiple MCP clients, thus connecting to multiple different servers simultaneously.
**MCP Server**: A lightweight program running independently, encapsulating specific capabilities of a data source or service, and providing them externally through a standardized MCP interface. Each MCP server acts as an "adapter" that exposes the functionalities of underlying data sources/tools (local files, databases, third-party APIs, etc.) in a unified format for client calls.
**Local Data Sources**: Data resources deployed in the user's local environment, such as local file systems, databases, application services, etc. MCP servers can access these resources in a controlled manner and provide content for AI models to use. For example, a local MCP server can read computer files or query a local SQLite database and then send the results to the model as a reference.
**Remote Services**: External systems or online services provided over the network (usually accessed via HTTP API). MCP servers can also connect to these remote services to obtain data. For instance, an MCP server can connect to Slack's Web API to perform operations such as sending messages or reading channel records on behalf of the AI assistant.
## 4. MCP & JAVA Support
MCP provides support for multiple programming languages, such as Python, Java, Kotlin, TypeScript, etc. Here, we take the Java SDK as an example, and the official documentation is also available: https://modelcontextprotocol.io/sdk/java/mcp-overview. Spring AI has also supported MCP.
### 4.1. Multiple Transmission Methods
MCP provides two different transmission implementations.
- Default transmission method: based on Stdio, HTTP SSE
- Spring-based transmission: WebFlux SSE, WebMVC SSE
### 4.2. Basic Architecture of JAVA Applications
The JAVA SDK also follows a layered structure:

Client/Server Layer (McpClient/McpServer): Both use McpSession for synchronous/asynchronous operations, where McpClient handles client protocol operations, and McpServer manages server-side protocol operations.
Session Layer (McpSession): Uses DefaultMcpSession to manage communication modes and states.
Transport Layer (McpTransport): Handles JSON-RPC message serialization/deserialization through:
- StdioTransport (stdin/stdout) in the core module
- HTTP SSE transmission in dedicated transport modules (Java HttpClient, Spring WebFlux, Spring WebMVC)
**The MCP client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client side of the protocol.**

**The MCP server is a fundamental component in the Model Context Protocol (MCP) architecture, providing tools, resources, and functionalities to clients. It implements the server side of the protocol.**

### 4.3. MCP Client Invocation
#### 4.3.1. Cherry Studio MCP Service Invocation
https://cherry-ai.com/download



In the dialog box, input: call the mcp weather service's getWeatherForecastByLocation tool, with the latitude and longitude parameters as follows, and please output the result in Chinese: "latitude", "47.6062", "longitude", "-122.3321".
Successful invocation result:

We can use some desktop tools like Claude Desktop, Cursor, etc., to introduce our MCP Server. I tried Claude, but it requires a foreign phone number for registration, which I don't have. I also tried Cursor, but it only supports HTTP SSE. I was just doing this for demonstration, so I decided to skip it and not wrap it. Therefore, I directly wrote an MCP Client for testing.
We create an MCP Client project: mcp-client-spring-ai, and introduce the Maven dependencies:
You Might Also Like
Ollama
Ollama enables easy access to large language models on various platforms.

n8n
n8n is a secure workflow automation platform for technical teams with 400+...
OpenWebUI
Open WebUI is an extensible web interface for customizable applications.

Dify
Dify is a platform for AI workflows, enabling file uploads and self-hosting.

Zed
Zed is a high-performance multiplayer code editor from the creators of Atom.
MarkItDown MCP
markitdown-mcp is a lightweight MCP server for converting various URIs to Markdown.