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/0e9f36386539e530f9e2a0f0c1c92681a884d0f4 below:

add -debug flag to allow debugging of Grafana requests (#97) · grafana/mcp-grafana@0e9f363 · GitHub

@@ -41,6 +41,26 @@ func urlAndAPIKeyFromHeaders(req *http.Request) (string, string) {

41 41

type grafanaURLKey struct{}

42 42

type grafanaAPIKeyKey struct{}

43 43 44 +

// grafanaDebugKey is the context key for the Grafana transport's debug flag.

45 +

type grafanaDebugKey struct{}

46 + 47 +

// WithGrafanaDebug adds the Grafana debug flag to the context.

48 +

func WithGrafanaDebug(ctx context.Context, debug bool) context.Context {

49 +

if debug {

50 +

slog.Info("Grafana transport debug mode enabled")

51 +

}

52 +

return context.WithValue(ctx, grafanaDebugKey{}, debug)

53 +

}

54 + 55 +

// GrafanaDebugFromContext extracts the Grafana debug flag from the context.

56 +

// If the flag is not set, it returns false.

57 +

func GrafanaDebugFromContext(ctx context.Context) bool {

58 +

if debug, ok := ctx.Value(grafanaDebugKey{}).(bool); ok {

59 +

return debug

60 +

}

61 +

return false

62 +

}

63 + 44 64

// ExtractGrafanaInfoFromEnv is a StdioContextFunc that extracts Grafana configuration

45 65

// from environment variables and injects a configured client into the context.

46 66

var ExtractGrafanaInfoFromEnv server.StdioContextFunc = func(ctx context.Context) context.Context {

@@ -135,6 +155,8 @@ var ExtractGrafanaClientFromEnv server.StdioContextFunc = func(ctx context.Conte

135 155

cfg.APIKey = apiKey

136 156

}

137 157 158 +

cfg.Debug = GrafanaDebugFromContext(ctx)

159 + 138 160

slog.Debug("Creating Grafana client", "url", parsedURL.Redacted(), "api_key_set", apiKey != "")

139 161

client := client.NewHTTPClientWithConfig(strfmt.Default, cfg)

140 162

return context.WithValue(ctx, grafanaClientKey{}, client)

@@ -165,6 +187,9 @@ var ExtractGrafanaClientFromHeaders server.SSEContextFunc = func(ctx context.Con

165 187

if apiKey != "" {

166 188

cfg.APIKey = apiKey

167 189

}

190 + 191 +

cfg.Debug = GrafanaDebugFromContext(ctx)

192 + 168 193

client := client.NewHTTPClientWithConfig(strfmt.Default, cfg)

169 194

return WithGrafanaClient(ctx, client)

170 195

}

@@ -251,16 +276,27 @@ func ComposeSSEContextFuncs(funcs ...server.SSEContextFunc) server.SSEContextFun

251 276

}

252 277

}

253 278 254 -

// ComposedStdioContextFunc is a StdioContextFunc that comprises all predefined StdioContextFuncs.

255 -

var ComposedStdioContextFunc = ComposeStdioContextFuncs(

256 -

ExtractGrafanaInfoFromEnv,

257 -

ExtractGrafanaClientFromEnv,

258 -

ExtractIncidentClientFromEnv,

259 -

)

279 +

// ComposedStdioContextFunc returns a StdioContextFunc that comprises all predefined StdioContextFuncs,

280 +

// as well as the Grafana debug flag.

281 +

func ComposedStdioContextFunc(debug bool) server.StdioContextFunc {

282 +

return ComposeStdioContextFuncs(

283 +

func(ctx context.Context) context.Context {

284 +

return WithGrafanaDebug(ctx, debug)

285 +

},

286 +

ExtractGrafanaInfoFromEnv,

287 +

ExtractGrafanaClientFromEnv,

288 +

ExtractIncidentClientFromEnv,

289 +

)

290 +

}

260 291 261 292

// ComposedSSEContextFunc is a SSEContextFunc that comprises all predefined SSEContextFuncs.

262 -

var ComposedSSEContextFunc = ComposeSSEContextFuncs(

263 -

ExtractGrafanaInfoFromHeaders,

264 -

ExtractGrafanaClientFromHeaders,

265 -

ExtractIncidentClientFromHeaders,

266 -

)

293 +

func ComposedSSEContextFunc(debug bool) server.SSEContextFunc {

294 +

return ComposeSSEContextFuncs(

295 +

func(ctx context.Context, req *http.Request) context.Context {

296 +

return WithGrafanaDebug(ctx, debug)

297 +

},

298 +

ExtractGrafanaInfoFromHeaders,

299 +

ExtractGrafanaClientFromHeaders,

300 +

ExtractIncidentClientFromHeaders,

301 +

)

302 +

}


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