Class: PostHog::MCP::TrackingData Private

Inherits:
Object
  • Object
show all
Defined in:
lib/posthog/mcp/tracking_data.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

All per-server analytics state. Lives on the instrumented MCP::Server instance (never in module-level storage), guarded by its own mutex.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:, sink:, server_name: nil, server_version: nil) ⇒ TrackingData

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TrackingData.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/posthog/mcp/tracking_data.rb', line 15

def initialize(options:, sink:, server_name: nil, server_version: nil)
  @options = options
  @sink = sink
  @server_name = server_name
  @server_version = server_version
  @mutex = Mutex.new
  @session_id = nil
  @session_source = 'generated'
  @last_mcp_session_id = nil
  @last_activity = Time.now
  @warned_no_stateless_session = false
  # Set once a request arrives over HTTP: from then on the server-wide session
  # is never a safe fallback for a capture that lost its request scope.
  @http_transport_seen = false
  @warned_unscoped_capture = false
  # The `get_more_tools` class {Tools.register} added to the server, if any.
  @virtual_tool = nil
  @identified_sessions = IdentityCache.new
  @tool_descriptions = {}
  @tool_categories = {}
  # Which tools got `_mcp_instructions` declared at tools/list. Only those
  # may be mirrored into; absent fails closed.
  @tool_output_instructions = {}
  # Which injected argument names the analytics layer owns per tool (i.e.
  # the tool does not declare them itself).
  @tool_owned_params = {}
end

Instance Attribute Details

#http_transport_seen ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def http_transport_seen
  @http_transport_seen
end

#identified_sessions ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def identified_sessions
  @identified_sessions
end

#last_activity ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def last_activity
  @last_activity
end

#last_mcp_session_id ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def last_mcp_session_id
  @last_mcp_session_id
end

#options ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def options
  @options
end

#server_name ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def server_name
  @server_name
end

#server_version ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def server_version
  @server_version
end

#session_id ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def session_id
  @session_id
end

#session_source ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def session_source
  @session_source
end

#sink ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def sink
  @sink
end

#tool_categories ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def tool_categories
  @tool_categories
end

#tool_descriptions ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def tool_descriptions
  @tool_descriptions
end

#tool_output_instructions ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def tool_output_instructions
  @tool_output_instructions
end

#tool_owned_params ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/posthog/mcp/tracking_data.rb', line 10

def tool_owned_params
  @tool_owned_params
end

#virtual_tool ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def virtual_tool
  @virtual_tool
end

#warned_no_stateless_session ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def warned_no_stateless_session
  @warned_no_stateless_session
end

#warned_unscoped_capture ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/posthog/mcp/tracking_data.rb', line 12

def warned_unscoped_capture
  @warned_unscoped_capture
end

Instance Method Details

#remember_tool(name, description: nil, category: nil, owned_params: nil, output_instructions: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
54
55
56
57
58
# File 'lib/posthog/mcp/tracking_data.rb', line 51

def remember_tool(name, description: nil, category: nil, owned_params: nil, output_instructions: nil)
  synchronize do
    @tool_descriptions[name] = description if description.is_a?(String) && !description.empty?
    @tool_categories[name] = category if category.is_a?(String) && !category.empty?
    @tool_owned_params[name] = owned_params unless owned_params.nil?
    @tool_output_instructions[name] = output_instructions unless output_instructions.nil?
  end
end

#synchronize ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
48
49
# File 'lib/posthog/mcp/tracking_data.rb', line 43

def synchronize(&)
  if @mutex.owned?
    yield
  else
    @mutex.synchronize(&)
  end
end