Class: Tools::FindSupportCasesTool
- Inherits:
-
ApplicationTool
- Object
- MCP::Tool
- ApplicationTool
- Tools::FindSupportCasesTool
- Defined in:
- app/mcp/tools/find_support_cases_tool.rb
Overview
MCP Tool for searching and filtering support cases.
Supports structured queries by customer, case number, state, type, date range,
and assigned employee — returning case summaries with participant and activity counts.
Class Method Summary collapse
-
.call(query: nil, customer: nil, state: nil, case_type: nil, assigned_to: nil, date_from: nil, date_to: nil, updated_before: nil, service_date: nil, limit: 15, _server_context: nil) ⇒ Object
Mirrors input_schema one-for-one, which is what makes the parameter list long — see find_images_tool for the same shape.
Class Method Details
.call(query: nil, customer: nil, state: nil, case_type: nil, assigned_to: nil, date_from: nil, date_to: nil, updated_before: nil, service_date: nil, limit: 15, _server_context: nil) ⇒ Object
Mirrors input_schema one-for-one, which is what makes the parameter list
long — see find_images_tool for the same shape.
rubocop:disable Metrics/ParameterLists
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/mcp/tools/find_support_cases_tool.rb', line 77 def call(query: nil, customer: nil, state: nil, case_type: nil, assigned_to: nil, date_from: nil, date_to: nil, updated_before: nil, service_date: nil, limit: 15, _server_context: nil) limit = limit.to_i.clamp(1, 50) scope = SupportCase.includes(:assigned_to, support_case_participants: :party).order(created_at: :desc) scope = apply_query_filter(scope, query) scope = apply_customer_filter(scope, customer) scope = apply_state_filter(scope, state) scope = scope.where(case_type: case_type) if case_type.present? scope = apply_assigned_filter(scope, assigned_to) date_err = validate_date_params(date_from, date_to, updated_before, service_date) return json_response(error: date_err) if date_err scope = apply_date_range(scope, date_from, date_to) scope = scope.where(support_cases: { updated_at: ...Date.parse(updated_before) }) if updated_before.present? scope = scope.where(support_cases: { service_date: Date.parse(service_date) }) if service_date.present? cases = scope.limit(limit).to_a activity_counts, communication_counts = batch_counts_for(cases) json_response( filters: { query: query, customer: customer, state: state, case_type: case_type, assigned_to: assigned_to, date_from: date_from, date_to: date_to, updated_before: updated_before, service_date: service_date }.compact, total_results: cases.size, support_cases: cases.map { |sc| format_case_summary(sc, activity_counts, communication_counts) } ) end |