ZAI MCP Server
Provides web search, content extraction, and AI summarization capabilities using the GLM-4.7-Flash model. It enables users to perform web searches, fetch website data, and generate concise content summaries through integrated tools.
README
ZAI MCP Server
A Model Context Protocol (MCP) server that provides web search, content fetching, and AI-powered summarization capabilities using ZAI's GLM-4.7-Flash model.
Features
- Web Search: Search the web using DuckDuckGo
- Content Fetching: Clean and extract text from any website
- AI Summarization: Summarize web content using GLM-4.7-Flash
- Combined Workflows: Search, fetch, and summarize in one operation
- Fast & Efficient: Uses flash model for quick responses
Tools
search_web
Search the web for information.
Parameters:
query(string, required): Search querynum_results(number, optional): Number of results (1-10, default: 5)
Returns:
{
"query": "search term",
"count": 5,
"results": [
{
"title": "Result Title",
"url": "https://example.com",
"snippet": "Brief snippet of the content..."
}
]
}
fetch_and_summarize
Fetch a website URL and summarize its content.
Parameters:
url(string, required): Website URL to fetchmax_content_length(number, optional): Max content length to process (default: 10000)
Returns:
{
"url": "https://example.com/article",
"title": "Article Title",
"summary": "AI-generated summary of the content...",
"content_length": 5000
}
search_and_summarize
Search the web, fetch the top result, and summarize it.
Parameters:
query(string, required): Search queryresult_index(number, optional): Which search result to fetch (1-10, default: 1)
Returns:
{
"query": "search term",
"result_index": 1,
"url": "https://example.com/article",
"title": "Article Title",
"summary": "AI-generated summary...",
"total_results": 10
}
Installation
Prerequisites
- Python 3.8 or higher
- ZAI API key (get one at https://z.ai/model-api)
- pip package manager
Install from source
# Clone the repository
git clone https://github.com/yourusername/zai-mcp-server.git
cd zai-mcp-server
# Install dependencies
pip install -r requirements.txt
# Make server executable
chmod +x src/server.py
Quick Start
# Set your API key
export ZAI_API_KEY="your-zai-api-key"
# Run the server
python src/server.py
Configuration
Environment Variables
| Variable | Description | Required | Default |
|---|---|---|---|
ZAI_API_KEY |
Your ZAI API key | Yes | - |
API Configuration
The server uses the following ZAI API configuration:
- Base URL:
https://api.z.ai/api/paas/v4 - Model:
glm-4.7-flash - Max Tokens: 1000
- Temperature: 0.7
Usage
Standalone Testing
# Test initialization
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}' | python src/server.py
# List available tools
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}' | python src/server.py
# Search the web
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "search_web", "arguments": {"query": "AI news", "num_results": 3}}}' | python src/server.py
Integration with Claude Desktop
Add to Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"zai": {
"command": "python3",
"args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
"env": {
"ZAI_API_KEY": "your-zai-api-key"
}
}
}
}
Integration with Cursor
Add to Cursor settings file (~/.cursor/mcp_config.json):
{
"mcpServers": {
"zai": {
"command": "python3",
"args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
"env": {
"ZAI_API_KEY": "your-zai-api-key"
}
}
}
}
Integration with Cline (VS Code)
Add to your MCP settings in VS Code:
{
"mcpServers": [
{
"name": "zai",
"command": "python3",
"args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
"env": {
"ZAI_API_KEY": "${env:ZAI_API_KEY}"
}
}
]
}
Integration with Continue
Add to ~/.continue/config.json:
{
"mcpServers": {
"zai": {
"command": "python3",
"args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
"env": {
"ZAI_API_KEY": "your-zai-api-key"
}
}
}
}
Integration with Roo Code
Add to Roo Code's MCP configuration:
{
"mcpServers": {
"zai": {
"command": "python3",
"args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
"env": {
"ZAI_API_KEY": "your-zai-api-key"
}
}
}
}
OpenCode Native Integration
Setup
OpenCode supports MCP servers natively. To configure:
-
Create/Update the MCP configuration file:
# Default location: ~/.config/opencode/mcp_servers.json mkdir -p ~/.config/opencode nano ~/.config/opencode/mcp_servers.json -
Add ZAI MCP Server configuration:
{ "mcpServers": { "zai": { "name": "ZAI Web Search & Summarization", "description": "Search web and summarize content using GLM-4.7-Flash", "command": "python3", "args": ["/home/op/zai-mcp-server/src/server.py"], "env": { "ZAI_API_KEY": "your-zai-api-key" }, "enabled": true } } } -
Restart OpenCode to load the new MCP server
Usage in OpenCode
Once configured, you can use the MCP server in OpenCode conversations:
User: Search for recent developments in AI and summarize the top result
Assistant: I'll use the ZAI MCP server to search and summarize for you.
[Calls search_and_summarize tool]
The ZAI MCP server found an article about recent AI developments. Here's a summary:
- Main point 1
- Main point 2
- Main point 3
Full article available at: https://example.com/ai-developments
Examples
Example 1: Web Search
# Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search_web",
"arguments": {
"query": "machine learning trends 2024",
"num_results": 5
}
}
}
# Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": JSON.stringify({
"query": "machine learning trends 2024",
"count": 5,
"results": [...]
})
}
]
}
}
Example 2: Fetch and Summarize
# Request
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "fetch_and_summarize",
"arguments": {
"url": "https://www.example.com/article"
}
}
}
# Response
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": JSON.stringify({
"url": "https://www.example.com/article",
"title": "Article Title",
"summary": "Key points:\n• Point 1\n• Point 2\n• Point 3",
"content_length": 5000
})
}
]
}
}
Example 3: Search and Summarize (Combined)
# Request
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "search_and_summarize",
"arguments": {
"query": "quantum computing breakthrough",
"result_index": 1
}
}
}
# Response
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": JSON.stringify({
"query": "quantum computing breakthrough",
"result_index": 1,
"url": "https://example.com/quantum-news",
"title": "Major Quantum Computing Breakthrough",
"summary": "Researchers have achieved a significant milestone...",
"total_results": 10
})
}
]
}
}
Testing
Run the test suite to verify the server is working correctly:
python examples/test_server.py
Expected output:
============================================================
ZAI MCP Server Test Suite
============================================================
Testing initialization...
✓ Initialize: mcp-zai-server v1.0.0
Testing tools list...
✓ Available tools (3):
- search_web: Search the web for information using DuckDuckGo
- fetch_and_summarize: Fetch a website URL and summarize its content using GLM-4.7-Flash
- search_and_summarize: Search the web, fetch top result, and summarize using GLM-4.7-Flash
Testing resources list...
✓ Available resources (1):
- zai://status: Current status of ZAI MCP server
Testing resource read...
✓ Server status:
Status: online
Model: glm-4.7-flash
API Endpoint: https://api.z.ai/api/paas/v4
Tools: search_web, fetch_and_summarize, search_and_summarize
============================================================
✓ All tests passed!
============================================================
Development
Project Structure
zai-mcp-server/
├── src/
│ └── server.py # Main MCP server implementation
├── docs/
│ ├── ARCHITECTURE.md # Architecture documentation
│ └── API_REFERENCE.md # Detailed API reference
├── examples/
│ └── test_server.py # Test suite and examples
├── requirements.txt # Python dependencies
├── README.md # This file
└── .env.example # Environment variables template
Dependencies
aiohttp- Async HTTP clientbeautifulsoup4- HTML parsingopenai- OpenAI-compatible client for ZAI API
Troubleshooting
Common Issues
Server won't start
- Ensure Python 3.8+ is installed:
python --version - Check dependencies are installed:
pip install -r requirements.txt - Verify API key is set:
echo $ZAI_API_KEY
Search returns no results
- DuckDuckGo API may have rate limits
- Try with a different query
- Check internet connectivity
Summarization fails
- Verify API key is valid at https://z.ai/model-api
- Check API credits/balance
- Ensure URL is accessible
MCP client can't connect
- Verify server path in configuration is correct
- Ensure Python3 is in system PATH
- Check file permissions:
chmod +x src/server.py
Debug Mode
Enable debug logging by setting environment variable:
export ZAI_DEBUG=1
python src/server.py
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
- Issues: Report bugs and feature requests on GitHub Issues
- ZAI API Documentation: https://docs.z.ai
- MCP Specification: https://modelcontextprotocol.io
Acknowledgments
- ZAI for providing the GLM-4.7-Flash API
- DuckDuckGo for the search API
- Model Context Protocol team for the specification
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。