posthog-ruby 3.30.3 → 3.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 025cc00787e8fc35ab922fe03e64409937cb1a4fa1ae6c7bf9189e7464d278db
|
|
4
|
+
data.tar.gz: bb052d99ca78a5112cf01575fc93ccca51366ad007226ccccfc186007aa4e3b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ca10f382fe03e35018980520b20fffc322543ee125ff241cbda55f39d505780466983f0e3ff7b7064a0e45202d0b414a97a31d4fb211b383d6b63397f61539d
|
|
7
|
+
data.tar.gz: 0f81d05df9dfb75672227b7c1f841256fcc198eba2c7f35a9e26d89a654092fc48d697d4f9ceaea94c222320983bfc0c0da5d2402a47ba94de41143a95b482e5
|
|
@@ -16,13 +16,9 @@ module PostHog
|
|
|
16
16
|
|
|
17
17
|
# Description of the injected `context` argument.
|
|
18
18
|
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
'information from the user request or tool results, including names, emails, phone numbers, ' \
|
|
23
|
-
'IPs, IDs, or credentials. You MUST generalize specific entities into roles such as "a user", ' \
|
|
24
|
-
'"the customer", or "an account". Example: "Retrieving a customer\'s recent orders to ' \
|
|
25
|
-
'investigate a billing issue and help support determine the appropriate resolution."'
|
|
19
|
+
"A few words on why you are calling this tool, for the server developer's analytics. " \
|
|
20
|
+
'Describe people and things by role, such as "a customer". Do not quote the user or include ' \
|
|
21
|
+
'names, emails, or other personal details.'
|
|
26
22
|
|
|
27
23
|
# Description of the injected `llm_model` argument.
|
|
28
24
|
DEFAULT_MODEL_PARAMETER_DESCRIPTION =
|
|
@@ -93,6 +89,7 @@ module PostHog
|
|
|
93
89
|
MCP_RESOURCES_READ = 'mcp:resources/read'
|
|
94
90
|
MCP_TOOLS_CALL = 'mcp:tools/call'
|
|
95
91
|
MCP_TOOLS_LIST = 'mcp:tools/list'
|
|
92
|
+
MCP_UNKNOWN_TOOL = 'mcp:unknown_tool'
|
|
96
93
|
|
|
97
94
|
EVENT_NAME_BY_TYPE = {
|
|
98
95
|
CUSTOM => Event::CUSTOM,
|
|
@@ -104,7 +101,8 @@ module PostHog
|
|
|
104
101
|
MCP_RESOURCES_LIST => Event::RESOURCES_LIST,
|
|
105
102
|
MCP_RESOURCES_READ => Event::RESOURCE_READ,
|
|
106
103
|
MCP_TOOLS_CALL => Event::TOOL_CALL,
|
|
107
|
-
MCP_TOOLS_LIST => Event::TOOLS_LIST
|
|
104
|
+
MCP_TOOLS_LIST => Event::TOOLS_LIST,
|
|
105
|
+
MCP_UNKNOWN_TOOL => '$mcp_unknown_tool'
|
|
108
106
|
}.freeze
|
|
109
107
|
end
|
|
110
108
|
end
|
|
@@ -66,10 +66,14 @@ module PostHog
|
|
|
66
66
|
event['event_type'] == EventType::MCP_TOOLS_CALL
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
def unknown_tool?(event)
|
|
70
|
+
event['event_type'] == EventType::MCP_UNKNOWN_TOOL
|
|
71
|
+
end
|
|
72
|
+
|
|
69
73
|
def add_common_properties(event, properties)
|
|
70
74
|
if present(event['resource_name'])
|
|
71
75
|
properties[Property::RESOURCE_NAME] = event['resource_name']
|
|
72
|
-
properties[Property::TOOL_NAME] = event['resource_name'] if tool_call?(event)
|
|
76
|
+
properties[Property::TOOL_NAME] = event['resource_name'] if tool_call?(event) || unknown_tool?(event)
|
|
73
77
|
end
|
|
74
78
|
if present(event['tool_description']) && tool_call?(event)
|
|
75
79
|
properties[Property::TOOL_DESCRIPTION] =
|
|
@@ -163,6 +163,15 @@ module PostHog
|
|
|
163
163
|
return result
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
+
if unregistered_tool?(name)
|
|
167
|
+
begin
|
|
168
|
+
result = yield
|
|
169
|
+
ensure
|
|
170
|
+
safely { record_unknown_tool(name, request, minted ? nil : conversation_id) }
|
|
171
|
+
end
|
|
172
|
+
return result
|
|
173
|
+
end
|
|
174
|
+
|
|
166
175
|
safely { prime_session(request, minted ? nil : conversation_id) }
|
|
167
176
|
begin
|
|
168
177
|
result = yield
|
|
@@ -336,6 +345,15 @@ module PostHog
|
|
|
336
345
|
finish_event(event, request)
|
|
337
346
|
end
|
|
338
347
|
|
|
348
|
+
def record_unknown_tool(name, request, conversation_id)
|
|
349
|
+
session_id = prepare_request(request, conversation_id: conversation_id)
|
|
350
|
+
event = base_event(EventType::MCP_UNKNOWN_TOOL, session_id, request)
|
|
351
|
+
event['conversation_id'] = conversation_id
|
|
352
|
+
event.delete('duration')
|
|
353
|
+
event['resource_name'] = Sanitization.redact_pii(Sanitization.sanitize_captured_value(name))
|
|
354
|
+
finish_event(event, request)
|
|
355
|
+
end
|
|
356
|
+
|
|
339
357
|
# The virtual tool declares `llm_model` itself, so the argument is never
|
|
340
358
|
# stripped and is read straight off the call.
|
|
341
359
|
def self_reported_model(arguments)
|
|
@@ -605,6 +623,15 @@ module PostHog
|
|
|
605
623
|
tools.is_a?(Hash) && tools[name].equal?(@data.virtual_tool)
|
|
606
624
|
end
|
|
607
625
|
|
|
626
|
+
# True when the server's registry is readable and has no tool by this name.
|
|
627
|
+
# A server whose registry cannot be read stays a failed call.
|
|
628
|
+
def unregistered_tool?(name)
|
|
629
|
+
return false unless name.is_a?(String) && !name.empty?
|
|
630
|
+
|
|
631
|
+
tools = @server.respond_to?(:tools) ? @server.tools : nil
|
|
632
|
+
tools.is_a?(Hash) && !tools.key?(name)
|
|
633
|
+
end
|
|
634
|
+
|
|
608
635
|
# Injected argument names the analytics layer owns for this tool: the ones
|
|
609
636
|
# it injected at tools/list, or (never listed) the ones the tool's own
|
|
610
637
|
# schema does not declare. A composed or referenced schema is never
|
|
@@ -120,7 +120,7 @@ module PostHog
|
|
|
120
120
|
tool_name: tool_name, required: false, options: options, label: 'conversation_id')
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
def add_model_parameter(schema, tool_name:, description: nil, required:
|
|
123
|
+
def add_model_parameter(schema, tool_name:, description: nil, required: false, options: nil)
|
|
124
124
|
add_parameter(schema, ModelCapture::PARAM_NAME, description || DEFAULT_MODEL_PARAMETER_DESCRIPTION,
|
|
125
125
|
tool_name: tool_name, required: required, options: options, label: 'llm_model')
|
|
126
126
|
end
|
data/lib/posthog/mcp/tools.rb
CHANGED
|
@@ -43,11 +43,10 @@ module PostHog
|
|
|
43
43
|
required: ['context']
|
|
44
44
|
},
|
|
45
45
|
annotations: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
destructiveHint: false
|
|
46
|
+
readOnlyHint: false,
|
|
47
|
+
destructiveHint: false,
|
|
48
|
+
idempotentHint: false,
|
|
49
|
+
openWorldHint: false
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
return spec unless options.respond_to?(:capture_model_enabled?) && options.capture_model_enabled?
|
data/lib/posthog/version.rb
CHANGED