MCPcopy
hub / github.com/grafana/tempo / handleGetAttributeValues

Method handleGetAttributeValues

modules/frontend/mcp_tools.go:292–329  ·  view source on GitHub ↗

handleGetAttributeValues handles the get-attribute-values tool

(ctx context.Context, request mcp.CallToolRequest)

Source from the content-addressed store, hash-verified

290
291// handleGetAttributeValues handles the get-attribute-values tool
292func (s *MCPServer) handleGetAttributeValues(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
293 metricMCPToolCalls.WithLabelValues(toolGetAttributeValues).Inc()
294
295 name, err := request.RequireString("name")
296 if err != nil {
297 return mcp.NewToolResultError(err.Error()), nil
298 }
299
300 query := request.GetString("filter-query", "")
301 if !traceql.IsEmptyQuery(query) {
302 conditionGroups, _ := traceql.ExtractConditionGroups(query, traceql.DefaultMaxConditionGroupsPerTagQuery)
303 if len(conditionGroups) == 0 {
304 return mcp.NewToolResultError("filter-query invalid. It must have a single spanset filter with &&/|| conditions like { <cond> && <cond> } or { <cond> || <cond> }"), nil
305 }
306 }
307
308 level.Info(s.logger).Log("msg", "getting attribute values", "name", name, "filter query", query)
309
310 searchTagValuesReq := &tempopb.SearchTagValuesRequest{
311 TagName: name,
312 Query: query,
313 }
314
315 req, err := api.BuildSearchTagValuesRequest(nil, searchTagValuesReq)
316 if err != nil {
317 return mcp.NewToolResultError(fmt.Sprintf("failed to build search request: %v", err)), nil
318 }
319 req.URL.Path = s.buildPath("/api/v2/search/tag/" + url.PathEscape(name) + "/values")
320
321 req, ctx = injectMuxVars(ctx, req, map[string]string{api.MuxVarTagName: name})
322
323 body, err := handleHTTP(ctx, s.frontend.SearchTagsValuesV2Handler, req)
324 if err != nil {
325 return mcp.NewToolResultError(err.Error()), nil
326 }
327
328 return toolResult(body, MetaTypeAttributeValues, "json", "2"), nil
329}
330
331func handleHTTP(ctx context.Context, handler http.Handler, req *http.Request) (string, error) {
332 rw := newResponseBuffer()

Callers 1

TestAcceptHeaderIsSetFunction · 0.95

Calls 10

buildPathMethod · 0.95
IsEmptyQueryFunction · 0.92
ExtractConditionGroupsFunction · 0.92
injectMuxVarsFunction · 0.85
handleHTTPFunction · 0.85
toolResultFunction · 0.70
IncMethod · 0.65
ErrorMethod · 0.65
LogMethod · 0.65

Tested by 1

TestAcceptHeaderIsSetFunction · 0.76