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 .添加工具
- 在中创建新文件
tools/(例如。tools/my_tool.go) - 定义params结构体
jsonschema标签 - 实现处理函数
- 添加
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)
}