Go MCP 库
一个用于构建模型上下文协议(MCP)服务器的轻量级Go语言库。
安装
go get github.com/nadavushka-dev/mcpaws用法
package main
import (
"encoding/json"
"github.com/nadavushka-dev/mcpaws/mcp"
)
func main() {
server := mcp.NewMcpServer(mcp.ServerConfig{
ProtocolVersion: "2025-06-18",
Capabilities: mcp.Capabilities{Tools: &mcp.ToolsCapabilities{}},
ServerInfo: mcp.ServerInfo{
Name: "my-server",
Version: "1.0.0",
},
})
server.AddTool(mcp.Tool{
Name: "echo",
Description: "Echo back a message",
InputSchema: mcp.InputSchema{
Type: "object",
Properties: map[string]mcp.Property{
"message": {Type: "string", Description: "Message to echo"},
},
Required: []string{"message"},
},
Method: func(params json.RawMessage) (any, error) {
var args struct{ Message string `json:"message"` }
json.Unmarshal(params, &args)
return mcp.ToolCallResult{
Content: []mcp.ToolContent{{Type: "text", Text: args.Message}},
}, nil
},
})
server.Run()
}示例
见 examples/main.go 以下是一个Git集成示例。
许可证
麻省理工学院许可证
