Class: Tools::PublishFaqsTool
- Inherits:
-
ApplicationTool
- Object
- MCP::Tool
- ApplicationTool
- Tools::PublishFaqsTool
- Defined in:
- app/mcp/tools/publish_faqs_tool.rb
Overview
MCP Tool for publishing existing FAQ articles.
Sunny can create FAQs (create_faq) and embed them into a blog post
(insert_faqs), but embedding alone does NOT make them appear on the live
site: the blog re-renders each FAQ widget through Oembed::FaqProvider with
published_only: true, so a draft FAQ renders as nothing on the public page
even though the editor's widget count includes it. This tool closes that
gap — it flips existing draft FAQs to published, then refreshes the posts
that embed them so the stored body re-renders with the now-visible FAQs.
Class Method Summary collapse
-
.call(ids:, _server_context: nil) ⇒ MCP::Tool::Response
Publish requested FAQs and refresh the posts that embed them.
Class Method Details
.call(ids:, _server_context: nil) ⇒ MCP::Tool::Response
Publish requested FAQs and refresh the posts that embed them.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/mcp/tools/publish_faqs_tool.rb', line 51 def call(ids:, _server_context: nil) # Keep 0 / non-numeric ids: they simply won't match an ArticleFaq and # get reported as not_found rather than vanishing from the response. lookup_ids = Array(ids).map(&:to_i).uniq return error_response('No FAQ IDs provided') if lookup_ids.empty? faqs = ArticleFaq.where(id: lookup_ids).index_by(&:id) results = lookup_ids.map { |faq_id| publish_one(faqs[faq_id], faq_id) } published_ids = results.select { |r| r[:published] }.pluck(:id) refreshed_posts = (published_ids) json_response( results: results, published_count: published_ids.size, refreshed_posts: refreshed_posts, message: (results, refreshed_posts) ) rescue StandardError => e ErrorReporting.error(e, tool: 'publish_faqs') error_response("Unexpected error publishing FAQs: #{e.}") end |