网络搜索与摘要生成服务

ZAI MCP Server 是一个提供网络搜索、内容抓取和基于AI摘要生成功能的服务,利用GLM-4.7-Flash模型快速处理信息。

  • by groxaxo
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 groxaxo/zai-mcp-server

使用说明

ZAI MCP服务器

一种模型上下文协议(MCP)服务器,使用ZAI的GLM-4.7-Flash模型提供网络搜索、内容获取和人工智能支持的摘要功能。

特性

  • 网络搜索:使用DuckDuckGo搜索网络
  • 内容获取:从任何网站上清理和提取文本
  • AI总结:使用GLM-4.7-Flash总结网络内容
  • 组合工作流:在一个操作中搜索、获取和汇总
  • 快速高效:使用flash模型快速响应

工具

search_web

在网上搜索信息。

参数:

  • query (字符串,必填):搜索查询
  • num_results (数字,可选):结果数量(1-10,默认值:5)

退货:

{
  "query": "search term",
  "count": 5,
  "results": [
    {
      "title": "Result Title",
      "url": "https://example.com",
      "snippet": "Brief snippet of the content..."
    }
  ]
}

fetch_and_summarize

获取网站URL并总结其内容。

参数:

  • url (字符串,必填):要获取的网站URL
  • max_content_length (数字,可选):要处理的最大内容长度(默认值:10000)

退货:

{
  "url": "https://example.com/article",
  "title": "Article Title",
  "summary": "AI-generated summary of the content...",
  "content_length": 5000
}

search_and_summarize

搜索网络,获取顶部结果,并对其进行总结。

参数:

  • query (字符串,必填):搜索查询
  • result_index (数字,可选):获取哪个搜索结果(1-10,默认值:1)

退货:

{
  "query": "search term",
  "result_index": 1,
  "url": "https://example.com/article",
  "title": "Article Title",
  "summary": "AI-generated summary...",
  "total_results": 10
}

安装

先决条件

  • Python 3.8或更高版本
  • ZAI API密钥(在https://z.ai/model-api)
  • pip包管理器

从源代码安装

# 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

快速开始

# Set your API key
export ZAI_API_KEY="your-zai-api-key"

# Run the server
python src/server.py

配置

环境变量

变量 描述 必填 默认
ZAI_API_KEY 您的ZAI API密钥 是 -

API配置

服务器使用以下ZAI API配置:

  • 基础URL: https://api.z.ai/api/paas/v4
  • 模型: glm-4.7-flash
  • 最大令牌数: 1000
  • 温度: 0.7

用法

独立测试

# 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

与Claude Desktop集成

添加到Claude Desktop配置文件:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %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"
      }
    }
  }
}

与Cursor集成

添加到光标设置文件(~/.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"
      }
    }
  }
}

与Cline集成(VS代码)

在VS Code中添加到MCP设置中:

{
  "mcpServers": [
    {
      "name": "zai",
      "command": "python3",
      "args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
      "env": {
        "ZAI_API_KEY": "${env:ZAI_API_KEY}"
      }
    }
  ]
}

与Continue集成

添加 ~/.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"
      }
    }
  }
}

与Roo Code集成

添加到Roo Code的MCP配置中:

{
  "mcpServers": {
    "zai": {
      "command": "python3",
      "args": ["/absolute/path/to/zai-mcp-server/src/server.py"],
      "env": {
        "ZAI_API_KEY": "your-zai-api-key"
      }
    }
  }
}

OpenCode原生集成

设置

OpenCode原生支持MCP服务器。要配置:

  1. 创建/更新MCP配置文件:

    # Default location: ~/.config/opencode/mcp_servers.json
    mkdir -p ~/.config/opencode
    nano ~/.config/opencode/mcp_servers.json
    
  2. 添加ZAI MCP服务器配置:

    {
      "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
        }
      }
    }
    
  3. 重新启动OpenCode 加载新的MCP服务器

OpenCode中的用法

配置后,您可以在OpenCode对话中使用MCP服务器:

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

示例

示例1:网络搜索

# 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": [...]
        })
      }
    ]
  }
}

示例2:提取和汇总

# 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
        })
      }
    ]
  }
}

示例3:搜索和总结(组合)

# 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
        })
      }
    ]
  }
}

测试

运行测试套件以验证服务器是否正常工作:

python examples/test_server.py

预期产量:

============================================================
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!
============================================================

发展

项目结构

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

依赖项

  • aiohttp -异步HTTP客户端
  • beautifulsoup4 -HTML解析
  • openai -适用于ZAI API的OpenAI兼容客户端

故障排除

常见问题

服务器无法启动

  • 确保已安装Python 3.8+: python --version
  • 检查是否安装了依赖项: pip install -r requirements.txt
  • 验证是否设置了API密钥: echo $ZAI_API_KEY

搜索未返回任何结果

  • DuckDuckGo API可能有费率限制
  • 尝试使用其他查询
  • 检查互联网连接

摘要失败

  • 验证API密钥在https://z.ai/model-api
  • 检查API信用/余额
  • 确保URL可访问

MCP客户端无法连接

  • 验证配置中的服务器路径是否正确
  • 确保Python3在系统PATH中
  • 检查文件权限: chmod +x src/server.py

调试模式

通过设置环境变量启用调试日志记录:

export ZAI_DEBUG=1
python src/server.py

许可证

MIT许可证-有关详细信息,请参阅许可证文件

贡献

欢迎投稿!请随时提交拉取请求。

支持

  • 问题:在GitHub Issues上报告错误和功能请求
  • ZAI API文件: https://docs.z.ai
  • MCP规范: https://modelcontextprotocol.io

致谢

  • ZAI提供GLM-4.7-Flash API
  • DuckDuckGo搜索API
  • 规范的模型上下文协议团队