Class: Seo::McpClients

Inherits:
Object
  • Object
show all
Defined in:
app/services/seo/mcp_clients.rb

Overview

Factory for API clients used by SEO services.
Provides lazy-loaded, cached clients for Ahrefs and Google Search Console.

Examples:

Using Ahrefs MCP client

client = Seo::McpClients.ahrefs
result = client.top_pages(target: 'warmlyyours.com', limit: 100)

Using GSC client

client = Seo::McpClients.gsc
data = client.search_analytics(start_date: 28.days.ago.to_date, end_date: Date.yesterday)

Class Method Summary collapse

Class Method Details

.ahrefsSeo::AhrefsMcpClient

Get the Ahrefs MCP client
Uses direct HTTP client for reliability



21
22
23
24
25
26
# File 'app/services/seo/mcp_clients.rb', line 21

def ahrefs
  @ahrefs_mutex ||= Mutex.new
  @ahrefs_mutex.synchronize do
    @ahrefs ||= Seo::AhrefsMcpClient.new
  end
end

.gscSeo::GscApiClient

Get the Google Search Console API client

Returns:



44
45
46
# File 'app/services/seo/mcp_clients.rb', line 44

def gsc
  @gsc ||= Seo::GscApiClient.new
end

.reset!Object

Clear cached clients



49
50
51
52
# File 'app/services/seo/mcp_clients.rb', line 49

def reset!
  reset_ahrefs!
  @gsc = nil
end

.reset_ahrefs!Object

Reset and rebuild the Ahrefs client



29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/seo/mcp_clients.rb', line 29

def reset_ahrefs!
  @ahrefs_mutex ||= Mutex.new
  @ahrefs_mutex.synchronize do
    begin
      @ahrefs&.close
    rescue StandardError
      nil
    end
    @ahrefs = nil
  end
end