-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (35 loc) · 920 Bytes
/
main.go
File metadata and controls
44 lines (35 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"fmt"
"log"
"net/http"
"github.com/riza-io/mcp-go"
"github.com/riza-io/mcp-go/sse"
)
type WeatherServer struct {
mcp.UnimplementedServer
}
func (s *WeatherServer) Initialize(ctx context.Context, req *mcp.Request[mcp.InitializeRequest]) (*mcp.Response[mcp.InitializeResponse], error) {
fmt.Println("Initialize", req.Params.ProtocolVersion)
return mcp.NewResponse(&mcp.InitializeResponse{
ProtocolVersion: req.Params.ProtocolVersion,
Capabilities: mcp.ServerCapabilities{
Resources: &mcp.Resources{},
Tools: &mcp.Tools{},
},
}), nil
}
func main() {
ctx := context.Background()
mux := http.NewServeMux()
server := mcp.NewServer(sse.NewStream(mux, "/sse", "/messages"), &WeatherServer{})
go func() {
if err := http.ListenAndServe(":3009", mux); err != nil {
log.Fatal(err)
}
}()
if err := server.Listen(ctx); err != nil {
log.Fatal(err)
}
}