项目简介

这个GitHub仓库包含了一系列使用Go语言编写的Model Context Protocol (MCP) 服务器实现。这些服务器旨在通过标准化的JSON-RPC协议,为大型语言模型(LLM)客户端提供特定的上下文信息和外部功能。

目前主要提供了两种类型的服务器:

  1. MCP文件系统服务器 (MCP-FileSystem-Golang): 允许LLM安全地执行文件系统的读写、目录列表、文件移动、信息查询和文件搜索等操作。
  2. MCP Brave搜索服务器 (MCP-Brave-Search-Golang): 使LLM能够利用Brave搜索引擎进行网络搜索和本地信息查询。

主要功能点

  • 标准MCP通信: 所有服务器都遵循Model Context Protocol (MCP) 规范,通过JSON-RPC协议与LLM客户端进行通信。
  • 工具调用 (Tools): 服务器注册并托管一系列可供LLM调用的工具。LLM可以请求工具列表('tools/list')并调用具体工具('tools/call')来执行外部操作。
  • 会话管理: 服务器处理'initialize'请求和'initialized'通知,管理与客户端的会话状态,确保客户端在使用工具前已完成初始化握手。
  • 多种传输协议: 核心MCP框架支持多种传输协议,当前示例服务器均配置使用标准输入输出(Stdio)。
  • 文件系统操作: 文件系统服务器提供读取、写入、创建目录、列出目录、移动文件、搜索文件和获取文件信息等功能,并具备安全路径验证,限制访问在预设目录内。
  • 网络搜索功能: Brave搜索服务器提供网络搜索和本地搜索工具,允许LLM获取来自Brave搜索引擎的实时信息,包括网页结果、本地商业信息等,并内置API限流功能。

安装步骤

  1. 克隆仓库: 首先,将项目从GitHub克隆到您的本地机器。

    git clone https://github.com/LaurieRhodes/PUBLIC-Golang-MCP-Servers.git
    cd PUBLIC-Golang-MCP-Servers
  2. 构建服务器: 进入相应的服务器子目录并使用Go命令进行编译。

    • MCP文件系统服务器:

      cd MCP-FileSystem-Golang
      go build -o mcp-filesystem-server ./cmd/server

      这将在当前目录下生成名为 'mcp-filesystem-server' 的可执行文件。

    • MCP Brave搜索服务器:

      cd MCP-Brave-Search-Golang
      go build -o mcp-brave-search-server ./cmd/server

      这将在当前目录下生成名为 'mcp-brave-search-server' 的可执行文件。

  3. 配置服务器: 每个服务器都需要一个 'config.json' 文件来指定其运行参数。请在相应服务器的可执行文件所在的目录下创建此文件。

    • MCP文件系统服务器配置: 在 'MCP-FileSystem-Golang' 目录下创建 'config.json' 文件。

      {
        "allowedDirectories": [
          "/path/to/your/safe/directory1",
          "C:\\another\\safe\\directory2"
        ]
      }

      重要提示: 'allowedDirectories' 字段是必填项,且至少需要包含一个您希望LLM能够安全访问的本地目录的绝对路径。

    • MCP Brave搜索服务器配置: 在 'MCP-Brave-Search-Golang' 目录下创建 'config.json' 文件。

      {
        "braveApiKey": "YOUR_BRAVE_API_KEY",
        "rateLimit": {
          "perSecond": 1,
          "perMonth": 15000
        }
      }

      重要提示: 'braveApiKey' 字段是必填项,您需要替换为您的Brave Search API Key。'rateLimit' 字段是可选的,用于设置API请求的速率限制,未指定时会有默认值。

服务器配置示例 (供MCP客户端参考)

MCP客户端需要配置MCP服务器的启动命令 ('command') 和参数 ('args') 才能与MCP服务器建立连接。以下是两种服务器的配置信息示例,可用于集成到MCP客户端中:

  • MCP文件系统服务器配置示例: 客户端需要知道服务器的名称、启动方式以及它提供的工具及其输入规范。

    {
      "name": "secure-filesystem-server",
      "command": "./mcp-filesystem-server",
      "args": [],
      "description": "一个提供文件系统操作(读、写、列表、搜索等)的MCP服务器,限制在预配置的安全目录内操作。",
      "tools": [
        {
          "name": "read_file",
          "description": "读取文件内容",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" }
            },
            "required": ["path"]
          }
        },
        {
          "name": "read_multiple_files",
          "description": "同时读取多个文件内容",
          "inputSchema": {
            "type": "object",
            "properties": {
              "paths": { "type": "array", "items": { "type": "string" } }
            },
            "required": ["paths"]
          }
        },
        {
          "name": "write_file",
          "description": "创建新文件或覆盖现有文件内容",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" },
              "content": { "type": "string" }
            },
            "required": ["path", "content"]
          }
        },
        {
          "name": "create_directory",
          "description": "创建新目录",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" }
            },
            "required": ["path"]
          }
        },
        {
          "name": "list_directory",
          "description": "获取指定路径下所有文件和目录的详细列表",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" }
            },
            "required": ["path"]
          }
        },
        {
          "name": "move_file",
          "description": "移动或重命名文件和目录",
          "inputSchema": {
            "type": "object",
            "properties": {
              "source": { "type": "string" },
              "destination": { "type": "string" }
            },
            "required": ["source", "destination"]
          }
        },
        {
          "name": "search_files",
          "description": "在指定目录树中递归搜索匹配模式的文件和目录",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" },
              "pattern": { "type": "string" }
            },
            "required": ["path", "pattern"]
          }
        },
        {
          "name": "get_file_info",
          "description": "检索文件或目录的详细元数据",
          "inputSchema": {
            "type": "object",
            "properties": {
              "path": { "type": "string" }
            },
            "required": ["path"]
          }
        },
        {
          "name": "list_allowed_directories",
          "description": "返回服务器允许访问的目录列表",
          "inputSchema": { "type": "object", "properties": {}, "required": [] }
        }
      ]
    }
  • MCP Brave搜索服务器配置示例: 客户端需要知道服务器的名称、启动方式以及它提供的工具及其输入规范。

    {
      "name": "brave-search-mcp",
      "command": "./mcp-brave-search-server",
      "args": [],
      "description": "一个提供Brave网络搜索和本地搜索功能的MCP服务器,支持API限流。",
      "tools": [
        {
          "name": "brave_web_search",
          "description": "使用Brave Search API执行网络搜索,适用于一般性查询、新闻、文章和在线内容。支持分页。",
          "inputSchema": {
            "type": "object",
            "properties": {
              "query": { "type": "string", "description": "搜索查询 (最多400字符,50个词)" },
              "count": { "type": "number", "description": "结果数量 (1-20, 默认10)", "default": 10 },
              "offset": { "type": "number", "description": "分页偏移量 (最大9, 默认0)", "default": 0 }
            },
            "required": ["query"]
          }
        },
        {
          "name": "brave_local_search",
          "description": "使用Brave Search API搜索本地商家和地点,最适合与物理位置相关的查询。会自动回退到网页搜索如果没有本地结果。",
          "inputSchema": {
            "type": "object",
            "properties": {
              "query": { "type": "string", "description": "本地搜索查询 (例如 '中央公园附近的披萨')" },
              "count": { "type": "number", "description": "结果数量 (1-20, 默认5)", "default": 5 }
            },
            "required": ["query"]
          }
        }
      ]
    }

基本使用方法

  1. 启动服务器:

    • 文件系统服务器: 在 'MCP-FileSystem-Golang' 目录下执行 './mcp-filesystem-server'
    • Brave搜索服务器: 在 'MCP-Brave-Search-Golang' 目录下执行 './mcp-brave-search-server' 服务器启动后,它将通过标准输入/输出(Stdio)等待JSON-RPC请求。
  2. 与LLM客户端集成: 您的MCP客户端应配置为执行上述服务器命令。客户端将负责:

    • 与服务器进行 'initialize' 握手,交换客户端和服务器的能力信息。
    • 发送 'tools/list' 请求以发现服务器提供的所有可用工具及其详细的输入/输出规范。
    • 根据LLM的需求,构造并发送 'tools/call' 请求,调用具体的工具来执行文件操作或网络搜索,并处理服务器返回的JSON-RPC响应。

信息

分类

AI与计算