Skip to content

Commit 1d45940

Browse files
committed
Add componentChecks tool, listing checks in rubric
componentChecks lists the rubric of checks for a given component
1 parent a7952a8 commit 1d45940

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: Add componentChecks tool, listing checks in the rubric
3+
time: 2025-06-09T16:17:00.521062-03:00

src/cmd/root.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/spf13/cobra"
1717

18+
"github.com/relvacode/iso8601"
1819
"github.com/rs/zerolog"
1920
"github.com/rs/zerolog/log"
2021
"github.com/spf13/viper"
@@ -71,6 +72,25 @@ type serializedCheck struct {
7172
Category string
7273
}
7374

75+
type serializedCheckResult struct {
76+
CheckId string
77+
CheckName string
78+
Message string
79+
Status string
80+
LastUpdated iso8601.Time
81+
}
82+
83+
type serializedCheckResultsByLevel struct {
84+
Level serializedLevel
85+
CheckResults []serializedCheckResult
86+
}
87+
88+
type serializedCheckResults struct {
89+
ByLevel []serializedCheckResultsByLevel
90+
CurrentLevel serializedLevel
91+
NextLevel serializedLevel
92+
}
93+
7494
// newToolResult creates a CallToolResult for the passed object handling any json marshaling errors
7595
func newToolResult(obj any, err error) (*mcp.CallToolResult, error) {
7696
if err != nil {
@@ -417,6 +437,63 @@ var rootCmd = &cobra.Command{
417437
return newToolResult(checks, nil)
418438
})
419439

440+
s.AddTool(
441+
mcp.NewTool(
442+
"componentChecks",
443+
mcp.WithDescription("Get all the checks for a specific component in the OpsLevel account. Checks are organized by level in a rubric, with each level containing a set of checks that must be passed to achieve that level."),
444+
mcp.WithString("serviceId", mcp.Required(), mcp.Description("The id of the service to fetch.")),
445+
mcp.WithToolAnnotation(mcp.ToolAnnotation{
446+
Title: "Rubric of Checks for Component",
447+
ReadOnlyHint: true,
448+
DestructiveHint: false,
449+
IdempotentHint: true,
450+
OpenWorldHint: true,
451+
}),
452+
),
453+
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
454+
service, err := client.GetService(req.Params.Arguments["serviceId"].(string))
455+
if err != nil {
456+
return nil, err
457+
}
458+
459+
stats, err := service.GetServiceStats(client)
460+
if err != nil {
461+
return nil, err
462+
}
463+
464+
result := serializedCheckResults{
465+
CurrentLevel: serializedLevel{
466+
Alias: stats.Rubric.Level.Alias,
467+
Index: stats.Rubric.Level.Index,
468+
},
469+
NextLevel: serializedLevel{
470+
Alias: stats.Rubric.CheckResults.NextLevel.Level.Alias,
471+
Index: stats.Rubric.CheckResults.NextLevel.Level.Index,
472+
},
473+
}
474+
475+
for _, checkResultsByLevel := range stats.Rubric.CheckResults.ByLevel.Nodes {
476+
byLevel := serializedCheckResultsByLevel{
477+
Level: serializedLevel{
478+
Alias: checkResultsByLevel.Level.Alias,
479+
Index: checkResultsByLevel.Level.Index,
480+
},
481+
}
482+
for _, checkResult := range checkResultsByLevel.Items.Nodes {
483+
byLevel.CheckResults = append(byLevel.CheckResults, serializedCheckResult{
484+
CheckId: string(checkResult.Check.Id),
485+
CheckName: checkResult.Check.Name,
486+
Message: checkResult.Message,
487+
Status: string(checkResult.Status),
488+
LastUpdated: checkResult.LastUpdated,
489+
})
490+
}
491+
result.ByLevel = append(result.ByLevel, byLevel)
492+
}
493+
494+
return newToolResult(result, nil)
495+
})
496+
420497
log.Info().Msg("Starting MCP server...")
421498
if err := server.ServeStdio(s); err != nil {
422499
if err == context.Canceled {

src/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.24.2
77
require (
88
github.com/mark3labs/mcp-go v0.23.1
99
github.com/opslevel/opslevel-go/v2025 v2025.5.28
10+
github.com/relvacode/iso8601 v1.6.0
1011
github.com/rs/zerolog v1.34.0
1112
github.com/spf13/cobra v1.9.1
1213
github.com/spf13/viper v1.20.1
@@ -37,7 +38,6 @@ require (
3738
github.com/opslevel/moredefaults v0.0.0-20240529152742-17d1318a3c12 // indirect
3839
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
3940
github.com/pkg/errors v0.9.1 // indirect
40-
github.com/relvacode/iso8601 v1.6.0 // indirect
4141
github.com/rogpeppe/go-internal v1.14.1 // indirect
4242
github.com/sagikazarmark/locafero v0.7.0 // indirect
4343
github.com/sourcegraph/conc v0.3.0 // indirect

src/submodules/opslevel-go

Submodule opslevel-go updated 47 files

0 commit comments

Comments
 (0)