-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (54 loc) · 1.44 KB
/
Copy pathmain.go
File metadata and controls
66 lines (54 loc) · 1.44 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/MegaGrindStone/go-mcp"
"github.com/mikaelmorvan/mcp-task/task"
"github.com/redis/go-redis/v9"
)
func main() {
// Read the configuration file
config, err := LoadConfig("./config.json")
if err != nil {
panic(err)
}
// Create a Redis client
redisClient := redis.NewClient(&redis.Options{
Addr: config.RedisAddr,
DB: config.RedisDB, // use default DB
Password: config.RedisPassword, // no password set
})
// Create a task server
taskServer := task.NewTaskServer(redisClient)
// Choose a transport method
// Option 1: Server-Sent Events (SSE)
sseSrv := mcp.NewSSEServer("/message")
srv := mcp.NewServer(mcp.Info{
Name: config.ToolName,
Version: config.ToolVersion,
}, sseSrv,
mcp.WithToolServer(taskServer),
// mcp.WithToolServer(taskServer),
mcp.WithServerPingInterval(30*time.Second),
// Add other capabilities as needed
)
// Set up HTTP handlers for SSE
http.Handle("/sse", sseSrv.HandleSSE())
http.Handle("/message", sseSrv.HandleMessage())
go http.ListenAndServe(config.ServerBindAddr, nil)
// To shutdown gracefully
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
sig := make(chan os.Signal, 2)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sig
srv.Shutdown(ctx)
}()
// Start the server - this blocks until shutdown
srv.Serve()
}