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:



40
41
42
# File 'app/services/seo/mcp_clients.rb', line 40

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

.reset!Object

Clear cached clients



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

def reset!
  reset_ahrefs!
  @gsc = nil
end

.reset_ahrefs!Object

Reset and rebuild the Ahrefs client



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

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