-
Notifications
You must be signed in to change notification settings - Fork 8
Add campaigns tool #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| kind: Added | ||
| body: Add campaigns tool for listing campaigns | ||
| time: 2025-06-13T10:06:09.286358-03:00 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,22 @@ type serializedCheckResults struct { | |
| NextLevel *serializedLevel | ||
| } | ||
|
|
||
| type serializedCampaign struct { | ||
| Id string | ||
| Name string | ||
| ProjectBrief string | ||
| Status string | ||
| CheckStats opslevel.Stats | ||
| HtmlURL string | ||
| ServiceStats opslevel.Stats | ||
| Filter *opslevel.FilterId | ||
| Owner *opslevel.TeamId | ||
| StartDate *iso8601.Time | ||
| EndedDate *iso8601.Time | ||
| TargetDate *iso8601.Time | ||
| Reminder *opslevel.CampaignReminder | ||
| } | ||
|
|
||
| // newToolResult creates a CallToolResult for the passed object handling any json marshaling errors | ||
| func newToolResult(obj any, err error) (*mcp.CallToolResult, error) { | ||
| if err != nil { | ||
|
|
@@ -513,6 +529,71 @@ var rootCmd = &cobra.Command{ | |
| return newToolResult(result, nil) | ||
| }) | ||
|
|
||
| // Register campaigns tool | ||
| s.AddTool( | ||
| mcp.NewTool( | ||
| "campaigns", | ||
| mcp.WithDescription("Get all the campaigns in the OpsLevel account. Campaigns are used to track and manage initiatives or projects within OpsLevel."), | ||
| mcp.WithString("status", mcp.Description("Filter campaigns by status, default is 'in_progress'"), mcp.Enum(opslevel.AllCampaignStatusEnum...)), | ||
| mcp.WithToolAnnotation(mcp.ToolAnnotation{ | ||
| Title: "Campaigns in OpsLevel", | ||
| ReadOnlyHint: &trueValue, | ||
| DestructiveHint: &falseValue, | ||
| IdempotentHint: &trueValue, | ||
| OpenWorldHint: &trueValue, | ||
| }), | ||
| ), | ||
| func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| args := &opslevel.ListCampaignsVariables{} | ||
| status := req.GetString("status", "") | ||
| if status != "" { | ||
| status_enum := opslevel.CampaignStatusEnum(status) | ||
| args.Status = &status_enum | ||
| } | ||
|
|
||
| resp, err := client.ListCampaigns(args) | ||
| if err != nil { | ||
| return mcp.NewToolResultErrorFromErr("failed to list campaigns", err), nil | ||
| } | ||
| var campaigns []serializedCampaign | ||
| for _, node := range resp.Nodes { | ||
| c := serializedCampaign{ | ||
| Id: string(node.Id), | ||
| Name: node.Name, | ||
| ProjectBrief: node.ProjectBrief, | ||
| Status: string(node.Status), | ||
| HtmlURL: node.HtmlUrl, | ||
| CheckStats: node.CheckStats, | ||
| ServiceStats: node.ServiceStats, | ||
| } | ||
| if node.Owner != (opslevel.TeamId{}) { | ||
| c.Owner = &node.Owner | ||
| } | ||
| if node.StartDate != (iso8601.Time{}) { | ||
| c.StartDate = &node.StartDate | ||
| } | ||
| if node.EndedDate != (iso8601.Time{}) { | ||
| c.EndedDate = &node.EndedDate | ||
| } | ||
| if node.TargetDate != (iso8601.Time{}) { | ||
| c.TargetDate = &node.TargetDate | ||
| } | ||
| if len(node.Reminder.Channels) > 0 { | ||
| c.Reminder = &node.Reminder | ||
| } | ||
| if node.Filter != (opslevel.FilterId{}) { | ||
| c.Filter = &node.Filter | ||
| } | ||
| if node.CheckStats != (opslevel.Stats{}) { | ||
| c.CheckStats = node.CheckStats | ||
| } | ||
|
Comment on lines
+569
to
+589
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never seen syntax like this before - TIL
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not very golike but I don't know how else to see if the value is the same as the default constructor
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wesleyjellis no it makes sense in this usecase i've just never seen it before. Its verbose for sure but understandable. 👍 |
||
|
|
||
| campaigns = append(campaigns, c) | ||
| } | ||
|
|
||
| return newToolResult(campaigns, err) | ||
| }) | ||
|
|
||
| log.Info().Msg("Starting MCP server...") | ||
| if err := server.ServeStdio(s); err != nil { | ||
| if err == context.Canceled { | ||
|
|
||
| +3 −0 | .changes/unreleased/Feature-20250612-203712.yaml | |
| +77 −0 | campaign.go | |
| +104 −0 | campaign_test.go | |
| +3 −0 | connection.go | |
| +43 −0 | object.go | |
| +90 −0 | testdata/templates/campaigns.tpl |
Uh oh!
There was an error while loading. Please reload this page.