流式HTTP服务器

一个基于Go语言和Docker Compose的MCP服务器,通过流式HTTP传输连接LM Studio,支持自定义工具扩展。

  • by Arkaikus
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 Arkaikus/mcp-streamable-go

使用说明

MCP流式HTTP服务器(Go)

使用Streamable HTTP传输的MCP服务器,与Docker Compose一起运行并连接到LM Studio。建于 走 和官方 modelcontextprotocol/go-sdk.

使用Docker Compose运行

docker compose up --build

验证

  • 健康检查: http://localhost:8000/health
  • MCP端点: http://localhost:8000/mcp(流式HTTP)

LM工作室配置

打开LM工作室→ 程序标签 → 安装 → 编辑mcp.json 并添加:

{
  "mcpServers": {
    "my-local-mcp": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

保存后,您的模型将可以访问 add, greet,以及 reverse_text 工具。

本地开发

go mod tidy
go run .

或者使用自定义端口:

PORT=9000 go run .

添加工具

  1. 在中创建新文件 tools/ (例如。 tools/my_tool.go)
  2. 定义params结构体 jsonschema 标签
  3. 实现处理函数
  4. 添加 RegisterMyTool(server) 到 tools/index.go

例子:

// tools/my_tool.go
package tools

import (
    "context"
    "github.com/modelcontextprotocol/go-sdk/mcp"
)

type MyToolParams struct {
    Input string `json:"input" jsonschema:"required,description=Input value"`
}

func MyTool(ctx context.Context, req *mcp.CallToolRequest, params *MyToolParams) (*mcp.CallToolResult, any, error) {
    return &mcp.CallToolResult{
        Content: []mcp.Content{&mcp.TextContent{Text: "result"}},
    }, nil, nil
}

func RegisterMyTool(server *mcp.Server) {
    mcp.AddTool(server, &mcp.Tool{
        Name:        "my_tool",
        Description: "My custom tool",
    }, MyTool)
}

然后在 tools/index.go:

func Register(server *mcp.Server) {
    RegisterAdd(server)
    RegisterGreet(server)
    RegisterReverseText(server)
    RegisterMyTool(server)
}