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

Function TestMCP

integration/api/mcp_test.go:23–80  ·  integration/api/mcp_test.go::TestMCP

TestMCP is a smoke test that starts up a tempo instance, writes a trace and queries it back via MCP. It also verifies that all expected tools are available.

(t *testing.T)

Source from the content-addressed store, hash-verified

21// TestMCP is a smoke test that starts up a tempo instance, writes a trace and queries it back via MCP.
22// It also verifies that all expected tools are available.
23func TestMCP(t *testing.T) {
24 util.RunIntegrationTests(t, util.TestHarnessConfig{
25 ConfigOverlay: "config-mcp.yaml",
26 }, func(h *util.TempoHarness) {
27 h.WaitTracesWritable(t)
28
29 // Write a trace
30 info := tempoUtil.NewTraceInfo(time.Now(), "")
31 require.NoError(t, h.WriteTraceInfo(info, ""))
32
33 _, err := info.ConstructTraceFromEpoch()
34 require.NoError(t, err)
35
36 // Wait for the trace to be written to the WAL
37 h.WaitTracesQueryable(t, 1)
38
39 // now query it back with mcp
40 queryFrontend := h.Services[util.ServiceQueryFrontend]
41 mcpClient := createMCPClient(t, queryFrontend)
42
43 tools := listTools(t, mcpClient)
44
45 // confirm all tools are listed as read only and no open world
46 for _, tool := range tools {
47 require.NotNil(t, tool.Annotations.DestructiveHint, "tool %s doesn't specify destructive", tool.Name)
48 require.False(t, *tool.Annotations.DestructiveHint, "tool %s is marked destructive", tool.Name)
49
50 require.NotNil(t, tool.Annotations.OpenWorldHint, "tool %s doesn't specify open world", tool.Name)
51 require.False(t, *tool.Annotations.OpenWorldHint, "tool %s is marked open world", tool.Name)
52
53 require.NotNil(t, tool.Annotations.ReadOnlyHint, "tool %s doesn't specify read only", tool.Name)
54 require.True(t, *tool.Annotations.ReadOnlyHint, "tool %s is marked write", tool.Name)
55 }
56
57 // Verify all expected tools are available
58 expectedTools := []string{
59 "traceql-search",
60 "traceql-metrics-instant",
61 "traceql-metrics-range",
62 "get-trace",
63 "get-attribute-names",
64 "get-attribute-values",
65 "docs-traceql",
66 }
67
68 actualTools := make([]string, len(tools))
69 for i, tool := range tools {
70 actualTools[i] = tool.Name
71 }
72
73 // sort both lists
74 sort.Strings(actualTools)
75 sort.Strings(expectedTools)
76 require.Equal(t, expectedTools, actualTools)
77
78 assertTraceOverMCP(t, mcpClient, info.HexID())
79 })
80}

Callers

nothing calls this directly

Calls 11

HexIDMethod · 0.95
createMCPClientFunction · 0.85
listToolsFunction · 0.85
assertTraceOverMCPFunction · 0.85
WaitTracesWritableMethod · 0.80
WriteTraceInfoMethod · 0.80
WaitTracesQueryableMethod · 0.80
NowMethod · 0.65
StringsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected