Skip to content

[jaegermcp] Enforce config-driven limits in MCP handlers#8194

Merged
yurishkuro merged 4 commits into
jaegertracing:mainfrom
rite7sh:fix/mcp-config-limits
Mar 18, 2026
Merged

[jaegermcp] Enforce config-driven limits in MCP handlers#8194
yurishkuro merged 4 commits into
jaegertracing:mainfrom
rite7sh:fix/mcp-config-limits

Conversation

@rite7sh
Copy link
Copy Markdown
Contributor

@rite7sh rite7sh commented Mar 18, 2026

Which problem is this PR solving?

Fixes #8193

This PR addresses an issue where configuration-defined limits in the Jaeger MCP extension were not being enforced.

Specifically:

  • MaxSearchResults was defined but not used in search_traces handler (hardcoded limits were used instead)
  • MaxSpanDetailsPerRequest was defined but not enforced in get_span_details handler

This resulted in potential unbounded payload sizes and inconsistency between configuration and runtime behavior.


Description of the changes

  • Pass MaxSearchResults and MaxSpanDetailsPerRequest from server.go into MCP handlers
  • Replace hardcoded limits in search_traces with config-driven limits
  • Add validation in get_span_details to enforce MaxSpanDetailsPerRequest
  • Update handler constructors to accept limit parameters
  • Update all call sites and tests to match new constructor signatures
  • Add a unit test to verify span limit enforcement behavior

How was this change tested?

  • Ran full test suite using make test
  • Updated existing unit tests to reflect constructor changes
  • Added a new test (TestGetSpanDetailsHandler_ExceedsLimit) to verify:
    • Error is returned when span request exceeds configured limit
    • Error message contains correct limit information
  • Verified no regressions in existing MCP handler tests

Checklist


AI Usage in this PR (choose one)

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@rite7sh rite7sh requested a review from a team as a code owner March 18, 2026 10:58
Copilot AI review requested due to automatic review settings March 18, 2026 10:58
@dosubot dosubot Bot added the enhancement label Mar 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Signed-off-by: Ritesh Tripathi <ritesh6263tripathi@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enforces Jaeger MCP extension configuration limits at runtime by threading configured maximums into the MCP tool handlers and applying them during request handling, preventing unbounded payload sizes and keeping behavior consistent with jaeger_mcp config.

Changes:

  • Pass MaxSearchResults and MaxSpanDetailsPerRequest from server.go into the search_traces and get_span_details handlers.
  • Replace hardcoded search_traces depth/result caps with config-driven limits.
  • Add span count validation in get_span_details and update/add unit tests for the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/jaeger/internal/extension/jaegermcp/server.go Wires config limits into handler constructors when registering MCP tools.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces.go Removes hardcoded caps; clamps search_depth using injected configured maximum.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details.go Enforces max spans per request via injected configured maximum.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces_test.go Updates tests to include the new handler limit field/constructor signature.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details_test.go Updates tests for new signature and adds coverage for exceeding the span limit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details.go Outdated
rite7sh added 2 commits March 18, 2026 13:11
- Remove hardcoded 'max: 100' reference from SearchDepth field documentation
- Clarify that maximum is controlled by server configuration (MaxSearchResults)
- Align documentation with config-driven limit enforcement implementation

Signed-off-by: Ritesh Tripathi <ritesh6263tripathi@gmail.com>
Signed-off-by: Ritesh Tripathi <ritesh6263tripathi@gmail.com>
Copilot AI review requested due to automatic review settings March 18, 2026 13:30
@rite7sh rite7sh force-pushed the fix/mcp-config-limits branch from a6babd7 to 3ecb2b7 Compare March 18, 2026 13:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Jaeger MCP limit enforcement by wiring configuration-defined limits into MCP tool handlers and applying those limits at runtime to prevent unexpectedly large responses.

Changes:

  • Pass MaxSearchResults and MaxSpanDetailsPerRequest from server.go into the search_traces and get_span_details handlers.
  • Replace search_traces hardcoded caps with a handler-configured maximum.
  • Enforce MaxSpanDetailsPerRequest in get_span_details, including a new unit test for the over-limit case.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/jaeger/internal/extension/jaegermcp/server.go Passes configured limits into handler constructors during tool registration.
cmd/jaeger/internal/extension/jaegermcp/server_test.go Updates server tests’ config setup to include required limit fields.
cmd/jaeger/internal/extension/jaegermcp/internal/types/search_traces.go Updates schema/docs to reflect config-controlled maximum for search_depth.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces.go Adds maxResults to handler and clamps SearchDepth using the configured limit.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces_test.go Updates tests for the new handler struct/constructor signature.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details.go Adds per-request span ID count enforcement based on configured limit.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details_test.go Updates tests for new constructor signature and adds an exceeds-limit test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details.go Outdated
Comment thread cmd/jaeger/internal/extension/jaegermcp/internal/handlers/get_span_details.go Outdated
Signed-off-by: Ritesh Tripathi <ritesh6263tripathi@gmail.com>
@yurishkuro yurishkuro added changelog:experimental Change to an experimental part of the code and removed changelog:bugfix-or-minor-feature labels Mar 18, 2026
@yurishkuro yurishkuro changed the title jaegermcp: enforce config-driven limits in MCP handlers [jaegermcp] Enforce config-driven limits in MCP handlers Mar 18, 2026
@yurishkuro yurishkuro enabled auto-merge March 18, 2026 18:15
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.63%. Comparing base (af51e32) to head (b00175a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8194   +/-   ##
=======================================
  Coverage   95.62%   95.63%           
=======================================
  Files         318      318           
  Lines       16771    16780    +9     
=======================================
+ Hits        16038    16047    +9     
  Misses        578      578           
  Partials      155      155           
Flag Coverage Δ
badger_v1 9.05% <ø> (ø)
badger_v2 1.04% <ø> (ø)
cassandra-4.x-v1-manual 13.25% <ø> (ø)
cassandra-4.x-v2-auto 1.03% <ø> (ø)
cassandra-4.x-v2-manual 1.03% <ø> (ø)
cassandra-5.x-v1-manual 13.25% <ø> (ø)
cassandra-5.x-v2-auto 1.03% <ø> (ø)
cassandra-5.x-v2-manual 1.03% <ø> (ø)
clickhouse 1.16% <ø> (ø)
elasticsearch-6.x-v1 16.83% <ø> (ø)
elasticsearch-7.x-v1 16.86% <ø> (ø)
elasticsearch-8.x-v1 17.01% <ø> (ø)
elasticsearch-8.x-v2 1.04% <ø> (ø)
elasticsearch-9.x-v2 1.04% <ø> (-0.05%) ⬇️
grpc_v1 7.79% <ø> (ø)
grpc_v2 1.04% <ø> (ø)
kafka-3.x-v2 1.04% <ø> (ø)
memory_v2 1.04% <ø> (ø)
opensearch-1.x-v1 16.91% <ø> (ø)
opensearch-2.x-v1 16.91% <ø> (ø)
opensearch-2.x-v2 1.04% <ø> (ø)
opensearch-3.x-v2 1.04% <ø> (ø)
query 1.04% <ø> (ø)
tailsampling-processor 0.52% <ø> (ø)
unittests 94.32% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yurishkuro yurishkuro added this pull request to the merge queue Mar 18, 2026
Merged via the queue into jaegertracing:main with commit bb7318d Mar 18, 2026
71 checks passed
@yurishkuro
Copy link
Copy Markdown
Member

Thanks!

@github-actions github-actions Bot added the waiting-for-author PR is waiting for author to respond to maintainer's comments label Mar 18, 2026
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 <roshansingh7890@gmail.com>
Signed-off-by: Roshan <rosh.s568@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:experimental Change to an experimental part of the code enhancement waiting-for-author PR is waiting for author to respond to maintainer's comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP handlers do not enforce config-defined limits

4 participants