Class: Tools::UpdateFaqTool

Inherits:
ApplicationTool show all
Defined in:
app/mcp/tools/update_faq_tool.rb

Overview

MCP tool for patching existing FAQ content, associations, and landing-page
placements without replacing fields the caller omitted.

Constant Summary collapse

UNSET =

Sentinel distinguishing omitted patch fields from explicit nil values.

Object.new.freeze

Class Method Summary collapse

Class Method Details

.call(id:, question: UNSET, answer: UNSET, description: UNSET, show_on_sales_pages: UNSET, show_on_support_pages: UNSET, product_line_names: UNSET, add_tags: nil, remove_tags: nil, add_page_paths: nil, remove_page_paths: nil, _server_context: nil) ⇒ MCP::Tool::Response

MCP keyword arguments intentionally mirror the public JSON schema.

rubocop:disable Metrics/ParameterLists

Parameters:

  • id (Integer)

    existing FAQ article ID

  • question (String, Object) (defaults to: UNSET)

    replacement question or UNSET

  • answer (String, Object) (defaults to: UNSET)

    replacement answer HTML or UNSET

  • description (String, Object) (defaults to: UNSET)

    replacement description or UNSET

  • show_on_sales_pages (Boolean, Object) (defaults to: UNSET)

    replacement sales visibility or UNSET

  • show_on_support_pages (Boolean, Object) (defaults to: UNSET)

    replacement support visibility or UNSET

  • product_line_names (Array<String>, Object) (defaults to: UNSET)

    replacement product lines or UNSET

  • add_tags (Array<String>, nil) (defaults to: nil)

    ordinary tags to add

  • remove_tags (Array<String>, nil) (defaults to: nil)

    ordinary tags to remove

  • add_page_paths (Array<String>, nil) (defaults to: nil)

    landing-page placements to add

  • remove_page_paths (Array<String>, nil) (defaults to: nil)

    landing-page placements to remove

  • _server_context (Object, nil) (defaults to: nil)

    MCP server context (unused)

Returns:

  • (MCP::Tool::Response)

    JSON response with the FAQ update outcome



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/mcp/tools/update_faq_tool.rb', line 101

def call(
  id:,
  question: UNSET,
  answer: UNSET,
  description: UNSET,
  show_on_sales_pages: UNSET,
  show_on_support_pages: UNSET,
  product_line_names: UNSET,
  add_tags: nil,
  remove_tags: nil,
  add_page_paths: nil,
  remove_page_paths: nil,
  _server_context: nil
)
  faq = ArticleFaq.find_by(id: id)
  return error_response("No FAQ found with id=#{id}") unless faq

  result = Faq::Update.call(
    faq: faq,
    faq_changes: build_changes(
      question: question,
      answer: answer,
      description: description,
      show_on_sales_pages: show_on_sales_pages,
      show_on_support_pages: show_on_support_pages
    ),
    product_line_names: product_line_names.equal?(UNSET) ? nil : product_line_names,
    add_tags: add_tags,
    remove_tags: remove_tags,
    add_page_paths: add_page_paths,
    remove_page_paths: remove_page_paths
  )
  return error_response(result.error) unless result.success?

  json_response(
    success: true,
    faq: format_faq(result.faq),
    changed_fields: result.changed_fields,
    added_tags: result.added_tags,
    removed_tags: result.removed_tags,
    added_page_paths: result.added_page_paths,
    removed_page_paths: result.removed_page_paths,
    refreshed_posts: result.refreshed_posts,
    cache_purged: result.cache_purged,
    warnings: result.warnings.presence,
    message: result.changed_fields.any? ? 'FAQ updated successfully.' : 'FAQ already matched the requested state.'
  )
rescue StandardError => e
  ErrorReporting.error(e, tool: 'update_faq')
  error_response("Unexpected error updating FAQ: #{e.message}")
end