A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/grafana/mcp-grafana/commit/a18a21c41e2eef35131998f73413d209bf22729b below:

Oncall tools improvements (#88) · grafana/mcp-grafana@a18a21c · GitHub

@@ -75,6 +75,46 @@ func oncallClientFromContext(ctx context.Context) (*aapi.Client, error) {

75 75

return client, nil

76 76

}

77 77 78 +

// getUserServiceFromContext creates a new UserService using the OnCall client from the context

79 +

func getUserServiceFromContext(ctx context.Context) (*aapi.UserService, error) {

80 +

client, err := oncallClientFromContext(ctx)

81 +

if err != nil {

82 +

return nil, fmt.Errorf("getting OnCall client: %w", err)

83 +

}

84 + 85 +

return aapi.NewUserService(client), nil

86 +

}

87 + 88 +

// getScheduleServiceFromContext creates a new ScheduleService using the OnCall client from the context

89 +

func getScheduleServiceFromContext(ctx context.Context) (*aapi.ScheduleService, error) {

90 +

client, err := oncallClientFromContext(ctx)

91 +

if err != nil {

92 +

return nil, fmt.Errorf("getting OnCall client: %w", err)

93 +

}

94 + 95 +

return aapi.NewScheduleService(client), nil

96 +

}

97 + 98 +

// getTeamServiceFromContext creates a new TeamService using the OnCall client from the context

99 +

func getTeamServiceFromContext(ctx context.Context) (*aapi.TeamService, error) {

100 +

client, err := oncallClientFromContext(ctx)

101 +

if err != nil {

102 +

return nil, fmt.Errorf("getting OnCall client: %w", err)

103 +

}

104 + 105 +

return aapi.NewTeamService(client), nil

106 +

}

107 + 108 +

// getOnCallShiftServiceFromContext creates a new OnCallShiftService using the OnCall client from the context

109 +

func getOnCallShiftServiceFromContext(ctx context.Context) (*aapi.OnCallShiftService, error) {

110 +

client, err := oncallClientFromContext(ctx)

111 +

if err != nil {

112 +

return nil, fmt.Errorf("getting OnCall client: %w", err)

113 +

}

114 + 115 +

return aapi.NewOnCallShiftService(client), nil

116 +

}

117 + 78 118

type ListOnCallSchedulesParams struct {

79 119

TeamID string `json:"teamId,omitempty" jsonschema:"description=The ID of the team to list schedules for"`

80 120

ScheduleID string `json:"scheduleId,omitempty" jsonschema:"description=The ID of the schedule to get details for. If provided, returns only that schedule's details"`

@@ -91,13 +131,11 @@ type ScheduleSummary struct {

91 131

}

92 132 93 133

func listOnCallSchedules(ctx context.Context, args ListOnCallSchedulesParams) ([]*ScheduleSummary, error) {

94 -

client, err := oncallClientFromContext(ctx)

134 +

scheduleService, err := getScheduleServiceFromContext(ctx)

95 135

if err != nil {

96 -

return nil, fmt.Errorf("getting OnCall client: %w", err)

136 +

return nil, fmt.Errorf("getting OnCall schedule service: %w", err)

97 137

}

98 138 99 -

scheduleService := aapi.NewScheduleService(client)

100 - 101 139

if args.ScheduleID != "" {

102 140

schedule, _, err := scheduleService.GetSchedule(args.ScheduleID, &aapi.GetScheduleOptions{})

103 141

if err != nil {

@@ -119,6 +157,9 @@ func listOnCallSchedules(ctx context.Context, args ListOnCallSchedulesParams) ([

119 157

if args.Page > 0 {

120 158

listOptions.Page = args.Page

121 159

}

160 +

if args.TeamID != "" {

161 +

listOptions.TeamID = args.TeamID

162 +

}

122 163 123 164

response, _, err := scheduleService.ListSchedules(listOptions)

124 165

if err != nil {

@@ -128,11 +169,6 @@ func listOnCallSchedules(ctx context.Context, args ListOnCallSchedulesParams) ([

128 169

// Convert schedules to summaries

129 170

summaries := make([]*ScheduleSummary, 0, len(response.Schedules))

130 171

for _, schedule := range response.Schedules {

131 -

// Filter by team ID if provided. Note: We filter here because the API doesn't support

132 -

// filtering by team ID directly in the ListSchedules endpoint.

133 -

if args.TeamID != "" && schedule.TeamId != args.TeamID {

134 -

continue

135 -

}

136 172

summary := &ScheduleSummary{

137 173

ID: schedule.ID,

138 174

Name: schedule.Name,

@@ -159,12 +195,11 @@ type GetOnCallShiftParams struct {

159 195

}

160 196 161 197

func getOnCallShift(ctx context.Context, args GetOnCallShiftParams) (*aapi.OnCallShift, error) {

162 -

client, err := oncallClientFromContext(ctx)

198 +

shiftService, err := getOnCallShiftServiceFromContext(ctx)

163 199

if err != nil {

164 -

return nil, fmt.Errorf("getting OnCall client: %w", err)

200 +

return nil, fmt.Errorf("getting OnCall shift service: %w", err)

165 201

}

166 202 167 -

shiftService := aapi.NewOnCallShiftService(client)

168 203

shift, _, err := shiftService.GetOnCallShift(args.ShiftID, &aapi.GetOnCallShiftOptions{})

169 204

if err != nil {

170 205

return nil, fmt.Errorf("getting OnCall shift %s: %w", args.ShiftID, err)

@@ -181,37 +216,61 @@ var GetOnCallShift = mcpgrafana.MustTool(

181 216 182 217

// CurrentOnCallUsers represents the currently on-call users for a schedule

183 218

type CurrentOnCallUsers struct {

184 -

ScheduleID string `json:"scheduleId" jsonschema:"description=The ID of the schedule"`

185 -

ScheduleName string `json:"scheduleName" jsonschema:"description=The name of the schedule"`

186 -

Users []string `json:"users" jsonschema:"description=List of user IDs currently on call"`

219 +

ScheduleID string `json:"scheduleId" jsonschema:"description=The ID of the schedule"`

220 +

ScheduleName string `json:"scheduleName" jsonschema:"description=The name of the schedule"`

221 +

Users []*aapi.User `json:"users" jsonschema:"description=List of users currently on call"`

187 222

}

188 223 189 224

type GetCurrentOnCallUsersParams struct {

190 225

ScheduleID string `json:"scheduleId" jsonschema:"required,description=The ID of the schedule to get current on-call users for"`

191 226

}

192 227 193 228

func getCurrentOnCallUsers(ctx context.Context, args GetCurrentOnCallUsersParams) (*CurrentOnCallUsers, error) {

194 -

client, err := oncallClientFromContext(ctx)

229 +

scheduleService, err := getScheduleServiceFromContext(ctx)

195 230

if err != nil {

196 -

return nil, fmt.Errorf("getting OnCall client: %w", err)

231 +

return nil, fmt.Errorf("getting OnCall schedule service: %w", err)

197 232

}

198 233 199 -

scheduleService := aapi.NewScheduleService(client)

200 234

schedule, _, err := scheduleService.GetSchedule(args.ScheduleID, &aapi.GetScheduleOptions{})

201 235

if err != nil {

202 236

return nil, fmt.Errorf("getting schedule %s: %w", args.ScheduleID, err)

203 237

}

204 238 205 -

return &CurrentOnCallUsers{

239 +

// Create the result with the schedule info

240 +

result := &CurrentOnCallUsers{

206 241

ScheduleID: schedule.ID,

207 242

ScheduleName: schedule.Name,

208 -

Users: schedule.OnCallNow,

209 -

}, nil

243 +

Users: make([]*aapi.User, 0, len(schedule.OnCallNow)),

244 +

}

245 + 246 +

// If there are no users on call, return early

247 +

if len(schedule.OnCallNow) == 0 {

248 +

return result, nil

249 +

}

250 + 251 +

// Get the user service to fetch user details

252 +

userService, err := getUserServiceFromContext(ctx)

253 +

if err != nil {

254 +

return nil, fmt.Errorf("getting OnCall user service: %w", err)

255 +

}

256 + 257 +

// Fetch details for each user currently on call

258 +

for _, userID := range schedule.OnCallNow {

259 +

user, _, err := userService.GetUser(userID, &aapi.GetUserOptions{})

260 +

if err != nil {

261 +

// Log the error but continue with other users

262 +

fmt.Printf("Error fetching user %s: %v\n", userID, err)

263 +

continue

264 +

}

265 +

result.Users = append(result.Users, user)

266 +

}

267 + 268 +

return result, nil

210 269

}

211 270 212 271

var GetCurrentOnCallUsers = mcpgrafana.MustTool(

213 272

"get_current_oncall_users",

214 -

"Get users currently on-call for a specific schedule. A schedule is a calendar-based system defining when team members are on-call",

273 +

"Get users currently on-call for a specific schedule. A schedule is a calendar-based system defining when team members are on-call. This tool will return info about all users currently on-call for the schedule, regardless of team.",

215 274

getCurrentOnCallUsers,

216 275

)

217 276

@@ -220,17 +279,16 @@ type ListOnCallTeamsParams struct {

220 279

}

221 280 222 281

func listOnCallTeams(ctx context.Context, args ListOnCallTeamsParams) ([]*aapi.Team, error) {

223 -

client, err := oncallClientFromContext(ctx)

282 +

teamService, err := getTeamServiceFromContext(ctx)

224 283

if err != nil {

225 -

return nil, fmt.Errorf("getting OnCall client: %w", err)

284 +

return nil, fmt.Errorf("getting OnCall team service: %w", err)

226 285

}

227 286 228 287

listOptions := &aapi.ListTeamOptions{}

229 288

if args.Page > 0 {

230 289

listOptions.Page = args.Page

231 290

}

232 291 233 -

teamService := aapi.NewTeamService(client)

234 292

response, _, err := teamService.ListTeams(listOptions)

235 293

if err != nil {

236 294

return nil, fmt.Errorf("listing OnCall teams: %w", err)

@@ -252,13 +310,11 @@ type ListOnCallUsersParams struct {

252 310

}

253 311 254 312

func listOnCallUsers(ctx context.Context, args ListOnCallUsersParams) ([]*aapi.User, error) {

255 -

client, err := oncallClientFromContext(ctx)

313 +

userService, err := getUserServiceFromContext(ctx)

256 314

if err != nil {

257 -

return nil, fmt.Errorf("getting OnCall client: %w", err)

315 +

return nil, fmt.Errorf("getting OnCall user service: %w", err)

258 316

}

259 317 260 -

userService := aapi.NewUserService(client)

261 - 262 318

if args.UserID != "" {

263 319

user, _, err := userService.GetUser(args.UserID, &aapi.GetUserOptions{})

264 320

if err != nil {


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4