zh_mcp_server
知乎自动发文章MCP服务,一种用于知乎发文章的模型上下文协议(MCP)服务器,使用者可以通过该服务与大模型自动生成文章并在知乎发文章。基于selenium和ChromeDriver实现自动发文章。
claude mcp add --transport stdio victorzwx-zh_mcp_server python -m MCP_Server_ZhiHu \ --env PYTHONIOENCODING="utf-8"
How to use
This MCP server provides an automated way to generate content for Zhihu and post articles through a model-context protocol (MCP) server. It is implemented in Python and relies on a login flow to capture a user’s cookie data, which is then used by the MCP service to authenticate requests to Zhihu. After setup, you can start the MCP server and interact with it through the MCP interface to generate article drafts and publish them to Zhihu via the model-driven workflow. The server exposes a module-based entry point that can be invoked with Python, and supports encoding configuration to ensure non-ASCII text (for Chinese content) is preserved correctly when integrated into Java or other codebases.
To use it, first install the required Python environment and dependencies, then run the MCP entry point using the provided module path. The login flow will automatically open a Chromium browser window to capture your mobile-based verification code, which you must enter back in the terminal to complete the cookie setup. Once initialized, you can invoke the MCP server from your application or scripts to generate articles and post them through Zhihu using the model's capabilities.
How to install
Prerequisites:
- Python 3.10+ installed on your system
- Git installed
- Chrome/Chromium installed (for the login flow)
- Access to the repository and network to install dependencies
Step-by-step:
-
Clone the repository: git clone https://github.com/Victorzwx/MCP_Server_ZhiHu.git cd MCP_Server_ZhiHu
-
Create and activate a Python virtual environment (optional but recommended): python -m venv venv source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows
-
Install dependencies listed in requirements.txt: pip install -r requirements.txt
This should install: selenium>=4.0.0, requests>=2.25.1, mcp>=0.1.0, webdriver-manager>=3.8.0
-
Install a compatible ChromeDriver version that matches your Chrome browser (example shown): npx @puppeteer/browsers install chromedriver@134.0.6998.166
-
Initialize the environment (if you prefer an alternative setup): python setup_environment.py
-
Start the MCP server from Python (as per config example):
Ensure the following is defined in your MCP config:
"xhs_mcp_server": {"command": "python", "args": ["-m", "MCP_Server_ZhiHu"]}
-
Run the login flow to save cookies (required): python -m MCP_Server_ZhiHu.login
A browser window will open. Enter your Zhihu mobile account and complete the verification code in the terminal when prompted.
-
Optional alternative invocation with encoding (for integration into Java or other environments):
If integrating from code, ensure encoding is set:
{ "command": "D:\aconda\python.exe", "args": ["-m", "xhs_mcp_server", "--encoding=utf-8"], "env": {"PYTHONIOENCODING": "utf-8"} }
-
Run the MCP server using the configuration shown in the README (as a reminder):
For Python-based startup
python -m MCP_Server_ZhiHu
Notes:
- The login step is essential to obtain the necessary cookies for Zhihu interactions. Do not skip.
- If you encounter issues with headless environments or rendering during login, you may need to run in a non-headless mode as described in the debugging notes of the project.
Additional notes
Tips and common issues:
- Ensure Python 3.10+ is used to avoid compatibility issues with the MCP library.
- The login flow requires an active internet connection and a mobile verification step; keep your phone handy during the process.
- When integrating with other codebases (e.g., Java), specify encoding to utf-8 to prevent garbled characters in Chinese content. Use the PYTHONIOENCODING environment variable accordingly.
- If you hit ChromeDriver version mismatches, align the installed Chrome/Chromium version with the driver version mentioned in the README (example uses chromedriver 134.0.6998.166).
- The MCP server relies on selenium for browser automation; ensure browser drivers are accessible in the system PATH if you don’t use the provided install commands.
- For debugging, you can disable headless mode by configuring the poster initialization (as shown in the README) to visually inspect the flow.
Related MCP Servers
mcp-vegalite
MCP server from isaacwasserman/mcp-vegalite-server
github-chat
A Model Context Protocol (MCP) for analyzing and querying GitHub repositories using the GitHub Chat API.
nautex
MCP server for guiding Coding Agents via end-to-end requirements to implementation plan pipeline
pagerduty
PagerDuty's official local MCP (Model Context Protocol) server which provides tools to interact with your PagerDuty account directly from your MCP-enabled client.
futu-stock
mcp server for futuniuniu stock
mcp -boilerplate
Boilerplate using one of the 'better' ways to build MCP Servers. Written using FastMCP