Store request in MCP tools BaseService
What does this MR do and why?
This MR updates Mcp::Tools::Base::BaseService#execute to store the incoming MCP request in @request, making the request accessible to all subclasses through an inherited private request reader.
Previously, AggregatedService and GraphqlService independently assigned @request, while other subclasses, including CustomService, did not automatically receive access to the request.
This change:
- Moves request assignment into the shared
BaseService#executeimplementation. - Adds a private
requestreader toBaseService. - Removes redundant request assignments and duplicate readers from
AggregatedServiceandGraphqlService. - Removes the
Lint/UnusedMethodArgumentsuppression. - Adds regression coverage for request propagation through
BaseServiceandCustomService. - Retains existing request-forwarding coverage for
GraphqlServiceandAggregatedService. - Verifies that a subsequent execution without a request does not retain the previous request.
This ensures consistent request propagation across MCP tools without changing existing rate-limiting policies or CommandTool request delegation.
References
Screenshots or screen recordings
Not applicable. This MR contains backend service and RSpec changes with no UI modifications.
Before
Request assignment was handled separately by individual service implementations. Other subclasses did not automatically have access to the request.
After
BaseService#execute stores the request centrally, making it available to subclasses through the inherited private reader.
How to set up and validate locally
Run the targeted RSpec tests:
RAILS_ENV=test bin/rspec \ spec/services/mcp/tools/base/base_service_spec.rb \ spec/services/mcp/tools/base/custom_service_spec.rb \ spec/services/mcp/tools/base/graphql_service_spec.rb \ spec/services/mcp/tools/base/aggregated_service_spec.rb
RSpec result: 105 examples, 0 failures.
Run RuboCop against all seven modified files:
bundle exec rubocop \ app/services/mcp/tools/base/base_service.rb \ app/services/mcp/tools/base/aggregated_service.rb \ app/services/mcp/tools/base/graphql_service.rb \ spec/services/mcp/tools/base/base_service_spec.rb \ spec/services/mcp/tools/base/custom_service_spec.rb \ spec/services/mcp/tools/base/graphql_service_spec.rb \ spec/services/mcp/tools/base/aggregated_service_spec.rb
RuboCop result: 7 files inspected, no offenses detected.
Also verified:
git diff --check
Result: Passed.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps assess changes for quality, performance, reliability, security, and maintainability.
- Request assignment is centralized in
BaseService#execute. - Request access is provided through a private reader.
- Redundant assignments and duplicate readers in subclasses are removed.
- Regression tests cover
BaseService,CustomService,GraphqlService, andAggregatedService. - Tests verify request reset behavior when a subsequent execution receives
nil. - Existing
CommandToolrequest delegation is preserved. - No rate-limiting policy changes are introduced.
- Targeted RSpec tests pass.
- RuboCop reports no offenses.
git diff --checkpasses.