mcp-gateway-go

mcp-gateway-go

site icon
2025.04.22 2
Go网关工具实时通信开发效率
`mcp-gateway-go` 是一个基于 Go 的轻量级网关,用于将标准输入/输出 (stdio) 的 Model Context Protocol (MCP) 服务器转换为 Server-Sent Events (SSE) 端点,从而实现与 Web 浏览器或 AI 代理等客户端的实时通信。
View on GitHub

Overview

基本能力

产品定位

mcp-gateway-go 是一个用于将 MCP 服务器转换为 SSE 端点的网关工具,适用于需要将本地 MCP 服务器暴露给 Web 客户端或支持 SSE 的服务的场景。

核心功能

  • 标准输入/输出支持:通过 mcp-go 库与 MCP 服务器进行 stdio 交互。
  • SSE 支持:将 MCP 服务器的输出转换为 SSE 格式,实现实时通信。
  • 命令行工具集成:支持通过命令行工具(如 Node.js)运行 MCP 服务器,便于使用现有服务器实现。
  • 可自定义基础 URL:允许设置 SSE 端点的基础 URL,支持灵活的部署配置。

适用场景

  • 将现有的 MCP 服务器暴露给 Web 客户端或支持 SSE 的服务。
  • 在现代 Web 应用程序中集成 MCP 服务器,无需修改原始服务器实现。

工具列表

  • mcp-go:用于与 MCP 服务器交互的 Go 库。
  • mcp-gateway-go:将 MCP 服务器转换为 SSE 端点的网关工具。

常见问题解答

无明确常见问题解答内容。

使用教程

使用依赖

确保已安装 Go,并获取必要的包:

go get github.com/mark3labs/mcp-go
go get github.com/zhengkunwang223/mcp-gateway-go

安装教程

  1. 创建一个 Go 文件(如 main.go),内容如下:
package main

import (
    "github.com/mark3labs/mcp-go/server"
    "github.com/zhengkunwang223/mcp-gateway-go/gateway"
)

func main() {
    // Initialize the MCP server
    s := server.NewMCPServer("SSE Demo", "1.0.0")

    // Create the SSE server with a custom base URL
    sseServer := gateway.NewSSEServer(s, gateway.WithBaseURL("http://127.0.0.1:7979"))

    // Define the MCP command to run
    mcpCommand := gateway.McpCommand{
        Command: "npx",
        Args:    []string{"-y", "@modelcontextprotocol/server-filesystem", "/tmp"},
    }

    // Set up the gateway server
    gatewayServer := gateway.NewGatewaySSEServer(mcpCommand, sseServer)

    // Start the server on port 7979
    if err := gatewayServer.Start(":7979"); err != nil {
        panic(err)
    }
}
  1. 运行 Go 文件:
go run main.go

调试方式

服务器启动后,将监听 http://127.0.0.1:7979 上的传入连接。

许可证

该项目遵循 None 开源许可条款。