研究型MCP服务器

一个为AI代理或开发工具提供结构化研究能力(主要是网络搜索)的模型上下文协议服务器,具有可扩展架构和标准化通信功能。

  • by ali-nr
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 ali-nr/developer-research-server

使用说明

开发人员研究MCP服务器

该存储库包含一个模型上下文协议(MCP)服务器,旨在为AI代理或其他开发工具提供结构化的研究功能,主要是网络搜索。MCP实现了客户端(如AI代理)和提供专用工具的服务器之间的标准化通信。

该服务器最初使用OpenRouter进行网络搜索功能,但采用可扩展的架构构建,以便将来轻松集成其他研究提供商(例如,其他搜索引擎、数据库)。

目录

特性

  • 通过OpenRouter等提供商提供网络搜索功能。
  • 针对检索技术和软件开发内容进行了优化。
  • 专为可扩展性而设计,以支持多个研究提供商。
  • 实现可靠的错误处理和重试机制。
  • 以适合编程使用的结构良好、一致的JSON格式交付结果。

体系结构和可扩展性

该服务器采用模块化架构。每个研究提供者(如OpenRouter)都被实现为一个遵循通用接口的独立模块。这一设计原则使以下操作变得简单:

  1. 添加对新搜索引擎或数据源的支持。
  2. 根据配置或请求参数在提供者之间切换(未来增强)。
  3. 独立维护和更新特定于提供者的逻辑。

先决条件

  • Node.js v18或更高版本
  • npm (附带Node.js)
  • 所需研究提供商的API密钥(例如,OpenRouter)

安装

  1. 克隆存储库:

    git clone https://github.com/yourusername/developer-research-server.git # Replace with the actual URL
    cd developer-research-server
    
  2. 安装依赖项: 使用npm安装项目依赖项。

    npm install
    
  3. 构建项目: 将TypeScript代码编译为JavaScript。

    npm run build
    

    编译后的输出将在 build/ 目录。

配置

服务器是使用环境变量配置的。

  1. 创建一个 .env 文件: 复制 mcp-config-sample.json (如果可用,或手动创建一个) .env 项目根目录中的文件。

    # Example .env file content:
    OPENROUTER_API_KEY=your_openrouter_api_key_here
    OPENROUTER_API_URL=https://openrouter.ai/api/v1
    

    注意:确保 .env 文件已添加到您的 .gitignore 为了避免泄露秘密。

  2. 所需的环境变量:

    • OPENROUTER_API_KEY (OpenRouter提供商需要):您唯一的OpenRouter API密钥。
    • OPENROUTER_API_URL (可选):OpenRouter API的基本URL。默认为 https://openrouter.ai/api/v1.

    未来的提供者可能需要不同的环境变量。

消费

此MCP服务器在直接运行时通过标准输入/输出(stdio)监听请求。它旨在集成到Roo Code等工具中。

使用Roo代码

要将此服务器与Roo代码一起使用,请将以下配置添加到您的 .roo/mcp.json 文件。调整 args 指向已编译文件的路径 index.js 克隆存储库位置中的文件。

{
  "mcpServers": {
    "developer-research": {
      // Changed name to be more generic
      "command": "node",
      "args": ["/full/path/to/your/developer-research-server/build/index.js"], // <-- IMPORTANT: Update this path
      "env": {
        // Environment variables are typically loaded from the .env file
        // Or can be explicitly set here if needed, but .env is recommended for secrets
        // "OPENROUTER_API_KEY": "your-openrouter-api-key", // <-- Replace or load from .env
        // "OPENROUTER_API_URL": "https://openrouter.ai/api/v1"
      },
      "alwaysAllow": ["search_web"], // List tools the agent can always use
      "timeout": 60 // Timeout in seconds
    }
  }
}

重要提示:

  • 替换 /full/path/to/your/developer-research-server/build/index.js 在您的系统上使用正确的绝对路径。
  • 确保 OPENROUTER_API_KEY 优选地通过 .env 文件由服务器进程本身加载,而不是硬编码 mcp.json.

可用工具

目前,服务器提供以下工具:

搜索web

使用配置的提供程序(当前为OpenRouter)执行web搜索,并返回相关结果。

参数

  • query (字符串,必填):搜索查询。
  • num_results (整数,可选):所需的搜索结果数量。必须介于1和10之间。默认为5。
  • focus (字符串,可选):指定搜索的焦点区域。支持的值: "technical", "development", "general".默认为 "technical".

示例(概念性Roo代码使用)

// Within a Roo Code agent or script
const searchResults = await useMcpTool("developer-research", "search_web", {
  query: "advanced typescript patterns",
  num_results: 3,
  focus: "technical",
});

console.log(searchResults);

响应格式

该工具返回一个具有以下结构的JSON对象:

{
  "success": true, // Boolean indicating if the search was successful
  "results": [
    // Array of result objects
    {
      "title": "Title of the search result",
      "url": "https://example.com/page",
      "content": "A snippet or summary of the page content...",
      "domain": "example.com"
    }
    // ... more results
  ],
  "total_results": 3 // The actual number of results returned
}

如果出现错误,响应可能如下:

{
  "success": false,
  "error": "Description of the error that occurred."
}

许可证

麻省理工学院