[mcp] search_traces tool (Phase 2 Step 4)#7858
Merged
Merged
Conversation
Part of #7827 - Added internal/types package with SearchTracesInput and SearchTracesOutput - Added internal/handlers package with SearchTracesHandler - Implemented search_traces tool with time parsing (RFC3339 and relative formats) - Registered search_traces tool in MCP server - Added comprehensive unit tests for handler and time parsing - All tests passing, fmt and lint checks pass Co-authored-by: yurishkuro <[email protected]>
Copilot
AI
changed the title
[WIP] Implement phase 2 step 4 from ADR 002
Implement search_traces MCP tool (Phase 2 Step 4 of ADR-002)
Jan 9, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7858 +/- ##
==========================================
- Coverage 95.46% 95.43% -0.03%
==========================================
Files 300 301 +1
Lines 15731 15855 +124
==========================================
+ Hits 15017 15132 +115
- Misses 560 566 +6
- Partials 154 157 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Yuri Shkuro <[email protected]>
yurishkuro
requested changes
Jan 10, 2026
Metrics Comparison SummaryTotal changes across all snapshots: 0 Detailed changes per snapshotsummary_metrics_snapshot_cassandra📊 Metrics Diff SummaryTotal Changes: 0
|
…, add comprehensive tests - Renamed Limit field to SearchDepth to match Query API terminology - Updated description from "metadata only" to "trace summary only" - Removed unnecessary comment line - Added comprehensive unit tests achieving 98% code coverage - Created queryServiceInterface for testability - Added tests for all code paths including error cases, attributes, durations, and search depth handling Co-authored-by: yurishkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
yurishkuro
approved these changes
Jan 10, 2026
jaegertracingbot
approved these changes
Jan 10, 2026
5 tasks
yurishkuro
pushed a commit
that referenced
this pull request
Apr 10, 2026
) ## Which problem is this PR solving? When an agent calls `search_traces`, the response includes `service_count` (an integer) but not the actual service names. The agent knows a trace spans 5 services but has no idea which ones. To find out, it must call `get_trace_topology` or `get_span_details` for every trace individually, which defeats the purpose of a lightweight summary endpoint. The data is already computed internally. `buildTraceSummary` builds a `services` map to derive `service_count`, then discards the map keys. This has been the case since the function was introduced in #7858, where the map was built but only `len(services)` was surfaced. Subsequent changes (#7859, #7863, #7916, #8194) restructured the types and renamed fields but never revisited the service data gap. ## Short description of the changes - Added `Services []string` to `TraceSummary`, populated from the existing `services` map - Sorted alphabetically via `slices.Sort` for deterministic output across calls - Added multi-service test with three services in non-alphabetical order, unique span IDs, and proper parent-child relationships to verify sort correctness - Updated existing summary tests to assert on the new field - `ServiceCount` preserved for backward compatibility ## Use case An agent investigating a latency spike searches for slow traces. The summary now returns: ```json { "service_count": 3, "services": ["api-gateway", "payment", "user-service"] } ``` The agent can immediately see that the payment service is involved and drill into that trace, instead of blindly fetching topology for every result. ## How was this change tested? - `go test ./cmd/jaeger/internal/extension/jaegermcp/...` - all passing - `make lint` - 0 issues - `make fmt` - clean - `make test` - 3053 tests passing ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/main/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully: `make lint test` ## AI Usage in this PR (choose one) - [x] **Light**: AI provided minor assistance (formatting, simple suggestions) Signed-off-by: Roshan Singh <[email protected]> Signed-off-by: Roshan <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #7827
Implements the
search_tracesMCP tool as specified in Phase 2 Step 4 of ADR-002. This tool enables LLM agents to query Jaeger traces efficiently using progressive disclosure—returning only lightweight trace summaries without attributes or events.Changes
Added internal types package
SearchTracesInput: Defines tool parameters with support for RFC3339 and relative time formats (-1h,now)search_depthparameter (instead oflimit) to match Query API terminology - behaves like an SQL LIMIT clause depending on backend implementationSearchTracesOutput/TraceSummary: Returns trace metadata (IDs, service/span counts, duration, error status)Added search_traces handler
QueryService.FindTraces()with MCP-optimized response formatqueryServiceInterfacefor testabilityRegistered tool in MCP server
Test coverage
Example Usage
{ "start_time_min": "-1h", "service_name": "frontend", "with_errors": true, "duration_min": "2s", "search_depth": 10 }Returns:
{ "traces": [{ "trace_id": "1a2b3c4d...", "root_service": "frontend", "root_operation": "/api/checkout", "duration_ms": 2450, "span_count": 47, "service_count": 8, "has_errors": true }] }Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.