Commit 4b3e6b3c authored by Tobias Koppers's avatar Tobias Koppers

Improve trace server MCP: full path IDs, graph-based drill-down, search via SpanRef

- Aggregated span IDs now include the full parent path (e.g. "a2119-a2120")
  so callers can pass the id directly as `parent` to drill deeper. Raw span
  IDs remain plain numeric store indices.
- Aggregated parent resolution walks the SpanGraphRef tree segment by segment
  via `resolve_graph_by_path`, so drilling like `parent=a2119-a2120` correctly
  navigates the aggregation hierarchy instead of falling back to the raw span.
- Search in aggregated mode uses `SpanRef::search` to find matching spans
  anywhere in the subtree, returning individual raw results rather than a
  shallow name filter on direct graph children.
- Extracted `sort_items`, `span_ref_to_info`, `resolve_parent_span` helpers
  to avoid duplication between aggregated and raw query paths.
- Include the MCP port in the `query-trace --help` pointer so users can
  copy-paste the command directly.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 7873aeaa
...@@ -255,7 +255,7 @@ export async function startTurboTraceServerCli( ...@@ -255,7 +255,7 @@ export async function startTurboTraceServerCli(
server.listen(httpPort, '127.0.0.1', () => { server.listen(httpPort, '127.0.0.1', () => {
console.log( console.log(
`Query this trace from the command line: next internal query-trace --help` `Query this trace from the command line: next internal query-trace --port ${httpPort} --help`
) )
console.log( console.log(
`Alternatively, connect an MCP client to http://127.0.0.1:${httpPort}/mcp` `Alternatively, connect an MCP client to http://127.0.0.1:${httpPort}/mcp`
......
...@@ -266,6 +266,30 @@ describe('turbopack-trace-server', () => { ...@@ -266,6 +266,30 @@ describe('turbopack-trace-server', () => {
expect(childMd).toMatch(/Page \d+ of \d+/) expect(childMd).toMatch(/Page \d+ of \d+/)
}) })
it('should drill two levels deep using full path IDs', async () => {
// Get a root-level aggregated span.
const root = await querySpansJson(mcpPort, { sort: 'value' })
const rootId = root.spans[0].id
expect(rootId).toMatch(/^a\d+$/)
// Drill into its children.
const children = await querySpansJson(mcpPort, { parent: rootId })
expect(children.spans.length).toBeGreaterThan(0)
const childId = children.spans[0].id
// Child ID should include the parent path prefix.
expect(childId).toMatch(new RegExp(`^${rootId}-a\\d+$`))
// Drill one more level — pass the child's full path ID directly.
const grandchildren = await querySpansJson(mcpPort, { parent: childId })
expect(grandchildren.page).toBe(1)
if (grandchildren.spans.length > 0) {
// Grandchild ID should include the full parent chain.
expect(grandchildren.spans[0].id).toMatch(
new RegExp(`^${childId}-a\\d+$`)
)
}
})
it('should return no results for an impossible search term', async () => { it('should return no results for an impossible search term', async () => {
const md = await callMcpTool(mcpPort, 'query_spans', { const md = await callMcpTool(mcpPort, 'query_spans', {
search: 'zzz_unlikely_span_name_zzz', search: 'zzz_unlikely_span_name_zzz',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment