-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmcp.go
More file actions
181 lines (162 loc) · 5.5 KB
/
mcp.go
File metadata and controls
181 lines (162 loc) · 5.5 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package cmd
import (
"context"
"encoding/json"
"fmt"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/opslevel/cli/common"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
type NullArguments struct{}
type LightweightComponent struct {
Id string `json:"id"`
Name string `json:"name"`
Owner string `json:"owner"`
URL string `json:"url"`
}
var mcpCmd = &cobra.Command{
Use: "mcp",
Short: "MCP Server",
Long: "MCP Server",
RunE: func(cmd *cobra.Command, args []string) error {
done := make(chan struct{})
s := server.NewMCPServer(
"OpsLevel",
"1.0.0",
)
client := common.NewGraphClient(fmt.Sprintf("mcp-%s", version))
// Register Teams
s.AddTool(
mcp.NewTool("teams",
mcp.WithDescription("Get all the team names, identifiers and metadata for the opslevel account. Teams are owners of other objects in opslevel. Only use this if you need to search all teams.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListTeams(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Users
s.AddTool(
mcp.NewTool("users", mcp.WithDescription("Get all the user names, e-mail addresses and metadata for the opslevel account. Users are the people in opslevel. Only use this if you need to search all users.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListUsers(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Actions
s.AddTool(
mcp.NewTool("actions", mcp.WithDescription("Get all the information about actions the user can run in the opslevel account")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListTriggerDefinitions(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Filters
s.AddTool(
mcp.NewTool("filters", mcp.WithDescription("Get all the rubric filter names and which predicates they have for the opslevel account")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListFilters(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Components
s.AddTool(
mcp.NewTool("components", mcp.WithDescription("Get all the components in the opslevel account. Components are objects in opslevel that represent things like apis, libraries, services, frontends, backends, etc.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListServices(nil)
if err != nil {
return nil, err
}
var components []LightweightComponent
for _, node := range resp.Nodes {
components = append(components, LightweightComponent{
Id: string(node.Id),
Name: node.Name,
Owner: node.Owner.Alias,
URL: node.HtmlURL,
})
}
data, err := json.Marshal(components)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Infra
s.AddTool(
mcp.NewTool("infrastructure", mcp.WithDescription("Get all the infrastructure in the opslevel account. Infrastructure are objects in opslevel that represent cloud provider resources like vpc, databases, caches, networks, vms, etc.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListInfrastructure(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Domains
s.AddTool(
mcp.NewTool("domains", mcp.WithDescription("Get all the domains in the opslevel account. Domains are objects in opslevel that represent a top-level abstraction used to organize and categorize software systems.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListDomains(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
// Register Systems
s.AddTool(
mcp.NewTool("systems", mcp.WithDescription("Get all the systems in the opslevel account. Systems are objects in opslevel that represent a grouping of services or components that act together to serve a business function or process.")),
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
resp, err := client.ListSystems(nil)
if err != nil {
return nil, err
}
data, err := json.Marshal(resp.Nodes)
if err != nil {
return nil, err
}
return mcp.NewToolResultText(string(data)), nil
})
log.Info().Msg("Starting MCP server...")
if err := server.ServeStdio(s); err != nil {
panic(err)
}
<-done
return nil
},
}
func init() {
betaCmd.AddCommand(mcpCmd)
}