-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (56 loc) · 1.72 KB
/
Copy pathmain.go
File metadata and controls
69 lines (56 loc) · 1.72 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
67
68
69
package main
import (
"flag"
"fmt"
"github.com/fabiante/gridscale-mcp/resources"
"github.com/fabiante/gridscale-mcp/tools"
"github.com/gridscale/gsclient-go/v3"
"github.com/mark3labs/mcp-go/server"
)
func main() {
userKey := flag.String("user-key", "", "Gridscale API user key")
userToken := flag.String("user-token", "", "Gridscale API user token")
flag.Parse()
if *userKey == "" {
fmt.Println("Error: --user-key flag is required")
flag.Usage()
return
}
if *userToken == "" {
fmt.Println("Error: --user-token flag is required")
flag.Usage()
return
}
// Create a new MCP server
s := server.NewMCPServer(
"Gridscale API",
"0.1.0",
server.WithResourceCapabilities(true, true),
server.WithLogging(),
)
gs := newGSClient(*userKey, *userToken)
addTool(s, tools.CreateIP(gs))
addTool(s, tools.CreateStorage(gs))
addTool(s, tools.DeleteIP(gs))
addResource(s, resources.GetStorageTemplate(gs)) // FIXME: Somehow the LLM does not respond with a list of templates if asked. Check why. Is that an issue of this code or the LLM?
// Start the server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
}
}
func addTool(s *server.MCPServer, factory tools.HandlerFactory) {
tool, handler := factory()
s.AddTool(tool, handler)
}
func addResourceTemplate(s *server.MCPServer, factory resources.TemplateHandlerFactory) {
tool, handler := factory()
s.AddResourceTemplate(tool, handler)
}
func addResource(s *server.MCPServer, factory resources.HandlerFactory) {
tool, handler := factory()
s.AddResource(tool, handler)
}
func newGSClient(userKey, userToken string) *gsclient.Client {
config := gsclient.DefaultConfiguration(userKey, userToken)
return gsclient.NewClient(config)
}