ReActMCP Web Search

by mshojaei77

Integrations

  • Loads environment variables from a .env file for configuration, specifically used to store and access the EXA_API_KEY required for web searches

  • Integrates with the exa_py GitHub client to perform web searches via the Exa API

  • Formats web search results in Markdown to easily incorporate titles, URLs, and summaries into AI assistant responses

ReActMCP 网页搜索

ReActMCP Web Search 是一个 MCP(模型上下文协议)服务器,它将 Web 搜索功能集成到您的 AI 助手框架中。它利用 Exa API 执行基本和高级 Web 搜索,并返回实时的 Markdown 格式结果,包括标题、URL、发布日期和内容摘要。

该存储库是更广泛的 ReActMCP 项目的一部分,该项目连接各种 MCP 工具和服务器,为您的 AI 助手提供广泛的功能。


目录


特征

  • 基本网络搜索:使用 Exa API 执行简单搜索。
  • 高级网络搜索:使用其他过滤选项,例如域限制、文本包含要求和日期过滤器。
  • Markdown 输出:以 Markdown 格式格式化搜索结果,以便轻松合并标题、URL 和摘要。
  • MCP 集成:轻松将此工具添加到您的 MCP 服务器生态系统中,以获得多工具 AI 协助。

要求

  • Python 3.8+
  • python-dotenv
  • exa_py (Exa API 客户端)
  • 您的 MCP 框架可能需要的其他依赖项

安装

  1. 克隆存储库
    git clone https://github.com/mshojaei77/ReActMCP.git cd ReActMCP
  2. 创建虚拟环境(可选但推荐)
    python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
  3. 安装依赖项
    pip install -r requirements.txt

配置

环境变量

在项目根目录中创建一个.env文件,至少包含以下变量:

EXA_API_KEY=your_exa_api_key_here OPENAI_API_KEY=...

Exa API 需要此密钥来执行网络搜索。

MCP 配置

MCP 配置文件mcp_config.json定义了 MCP 服务器可用的设置和工具。以下是一个示例配置:

{ "websearch": { "script": "web_search.py", "encoding_error_handler": "ignore", "description": "Web search capability using Exa API that provides real-time internet search results. Supports both basic and advanced search with filtering options including domain restrictions, text inclusion requirements, and date filtering. Returns formatted results with titles, URLs, publication dates, and content summaries.", "required_env_vars": ["EXA_API_KEY"], "active": true }, "settings": { "model": "gpt-4o", "system_prompt_path": "system_prompt.txt" } }

您可以通过修改参数(例如默认结果数)或添加新的 MCP 工具来个性化或扩展此配置。

系统提示

system_prompt.txt文件用于配置 AI 助手的行为和语气。它引导用户做出友好、引人入胜且信息丰富的回复,并包含表情符号。以下提供了一个示例提示:

You are a helpful, knowledgeable AI assistant with web search capabilities. Your goal is to provide accurate, comprehensive, and up-to-date information to users. Use lots of emojis and make your responses fun and engaging. ## Available Search Tools - `search_web`: Basic web search that returns results based on a query - `advanced_search_web`: Advanced search with filtering options for domains, required text, and date ranges ## Guidelines for Responding to Questions 1. For current information or facts that might have changed since your training data, use the appropriate search tool to find the most recent and relevant information. 2. Use `search_web` for general queries and `advanced_search_web` with appropriate filters for more specific needs. 3. Formulate precise search queries to maximize result relevance. 4. For recent information, use the `max_age_days` parameter in advanced search to limit results to recent publications. 5. When targeting specific sources, use the `include_domains` parameter to focus your search. 6. Cite sources by including URLs from search results. 7. For insufficient or contradictory results, acknowledge limitations and explain findings. 8. Break down complex topics into organized sections. 9. Provide balanced perspectives on controversial topics. 10. Be transparent about uncertainty rather than making up information. 11. Maintain a helpful, informative, and conversational tone. ## Response Quality Standards Your responses should be well-structured, factually accurate, and tailored to the user's level of understanding on the topic. Use the web search capabilities as your primary tools for accessing current information before responding to time-sensitive or factual queries.

请随意调整系统提示以符合您所需的助手行为。


用法

运行 Web 搜索服务器

MCP 服务器在servers目录中实现。要运行服务器,只需执行以下命令:

python servers/web_search.py

此命令将启动 MCP 服务器,该服务器监听请求并公开以下工具:

  • search_web :执行基本的网络搜索。
  • advanced_search_web :使用过滤选项执行高级网络搜索。

测试工具

web_search.py 中,提供了一个测试函数test_search() (目前已被注释掉),用于演示搜索功能的基本用法。您可以取消注释测试执行块并使用 Python 的 asyncio 运行器来运行此测试:

if __name__ == "__main__": import asyncio # Uncomment the following line to perform a test search # asyncio.run(test_search()) mcp.run()

这将打印示例查询的搜索结果并帮助您验证该工具是否按预期运行。


Claude桌面配置:

通过将以下内容添加到您的配置中来配置 Claude Desktop 以使用此服务器:

{ "mcpServers": { "websearch": { "command": "python", "args": ["path/to/servers/exa_web_search.py"] } } }

故障排除

  • **缺少 EXA_API_KEY:**确保.env文件已使用有效的 Exa API 密钥正确设置。
  • **依赖项问题:**请检查所有必需的 Python 包是否已安装(检查requirements.txt文件)。如有需要,请重新安装包。
  • **API 错误:**如果您在网络搜索期间遇到错误,请检查您的网络连接并验证 Exa API 状态。

执照

本项目遵循 MIT 许可证。详情请参阅LICENSE文件。


贡献

欢迎贡献代码!如果您有任何建议、错误修复或改进,请创建问题或提交拉取请求。

祝您编程愉快,并享受使用 ReActMCP Web Search 构建个性化多功能 AI 助手的乐趣!🚀😊

星史

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

MCP 服务器使用 Exa API 将实时网络搜索功能集成到 AI 助手中,提供带有格式化 markdown 结果的基本和高级搜索功能。

  1. Table of Contents
    1. Features
      1. Requirements
        1. Installation
          1. Configuration
            1. Environment Variables
            2. MCP Configuration
            3. System Prompt
          2. Usage
            1. Running the Web Search Server
            2. Testing the Tools
          3. Claude Desktop Configuration:
            1. Troubleshooting
              1. License
                1. Contributing
                  1. Star History
                    ID: 83o9on4ihz