Class: Tools::GetShowcaseTool

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

Overview

MCP tool that opens a single project Showcase by numeric ID, slug, or its
public URL, and returns its full content for grounding (captions, summaries,
internal links).

semantic_search surfaces showcases by fuzzy relevance and never returns the
full project narrative. A showcase's URL slug (custom_slug) is also frozen at
creation and often diverges from the project name — e.g. slug
"rock-the-block-master-bathroom-in" vs name
'HGTV's "Rock the Block" featuring WarmlyYours Floor Heating' — so a pasted
showcase link can't be found by searching the name/body. This tool resolves
the link directly via FriendlyId, mirroring get_blog_post for blog posts.

Examples:

Open by public URL

{ id_or_url: "https://www.warmlyyours.com/en-US/showcases/rock-the-block-master-bathroom-in" }

Open by slug or ID

{ id_or_url: "rock-the-block-master-bathroom-in" }
{ id_or_url: "154" }

Class Method Summary collapse

Class Method Details

.call(id_or_url:, _server_context: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/mcp/tools/get_showcase_tool.rb', line 44

def call(id_or_url:, _server_context: nil)
  # A showcase URL's identifier is its last path segment (sans query/anchor).
  token = id_or_url.to_s.split(/[?#]/, 2).first.to_s.split('/').compact_blank.last.to_s.strip
  return error_response('Provide a showcase ID, slug, or URL.') if token.blank?

  # FriendlyId resolves by slug first, then falls back to the primary key,
  # so one call handles a slug, a numeric ID, and the edge case of a
  # purely-numeric custom_slug (which a numeric-only ID lookup would miss).
  showcase = Showcase.friendly.find(token)

  json_response(
    id: showcase.id,
    state: showcase.state,
    name: showcase.name,
    slug: showcase.custom_slug,
    url: "#{WEB_URL}/showcases/#{showcase.custom_slug}",
    project_type: showcase.project_type_label,
    content: showcase.content_for_embedding(:primary),
    # Editable structure — the IDs the update_showcase / set_showcase_*
    # tools operate on. Lets Sunny see current state before editing.
    editable: editable_state(showcase)
  )
rescue ActiveRecord::RecordNotFound
  error_response("Showcase #{id_or_url.inspect} not found")
end