@posthog/mcp 0.15.0 → 0.16.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.
Files changed (59) hide show
  1. package/README.md +64 -0
  2. package/dist/extensions/constants.d.ts +9 -0
  3. package/dist/extensions/constants.d.ts.map +1 -1
  4. package/dist/extensions/constants.js +9 -0
  5. package/dist/extensions/constants.mjs +9 -0
  6. package/dist/extensions/event-types.d.ts +1 -0
  7. package/dist/extensions/event-types.d.ts.map +1 -1
  8. package/dist/extensions/event-types.js +1 -0
  9. package/dist/extensions/event-types.mjs +1 -0
  10. package/dist/extensions/feedback.d.ts +41 -0
  11. package/dist/extensions/feedback.d.ts.map +1 -0
  12. package/dist/extensions/feedback.js +259 -0
  13. package/dist/extensions/feedback.mjs +200 -0
  14. package/dist/extensions/instrument-highlevel.d.ts.map +1 -1
  15. package/dist/extensions/instrument-highlevel.js +19 -1
  16. package/dist/extensions/instrument-highlevel.mjs +20 -2
  17. package/dist/extensions/instrument-lowlevel.d.ts.map +1 -1
  18. package/dist/extensions/instrument-lowlevel.js +19 -1
  19. package/dist/extensions/instrument-lowlevel.mjs +20 -2
  20. package/dist/extensions/instrumentation.d.ts +30 -13
  21. package/dist/extensions/instrumentation.d.ts.map +1 -1
  22. package/dist/extensions/instrumentation.js +27 -7
  23. package/dist/extensions/instrumentation.mjs +27 -7
  24. package/dist/extensions/mcp-payloads.d.ts +9 -3
  25. package/dist/extensions/mcp-payloads.d.ts.map +1 -1
  26. package/dist/extensions/mcp-payloads.js +16 -7
  27. package/dist/extensions/mcp-payloads.mjs +11 -5
  28. package/dist/extensions/posthog-events.d.ts.map +1 -1
  29. package/dist/extensions/posthog-events.js +1 -0
  30. package/dist/extensions/posthog-events.mjs +1 -0
  31. package/dist/extensions/posthog-mcp.d.ts +23 -3
  32. package/dist/extensions/posthog-mcp.d.ts.map +1 -1
  33. package/dist/extensions/posthog-mcp.js +27 -1
  34. package/dist/extensions/posthog-mcp.mjs +27 -1
  35. package/dist/extensions/sanitization.js +1 -1
  36. package/dist/extensions/sanitization.mjs +2 -2
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +10 -0
  40. package/dist/index.mjs +5 -1
  41. package/dist/types.d.ts +113 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +1 -1
  45. package/dist/version.mjs +1 -1
  46. package/package.json +4 -4
  47. package/src/extensions/constants.ts +9 -0
  48. package/src/extensions/event-types.ts +1 -0
  49. package/src/extensions/feedback.ts +349 -0
  50. package/src/extensions/instrument-highlevel.ts +39 -2
  51. package/src/extensions/instrument-lowlevel.ts +39 -2
  52. package/src/extensions/instrumentation.ts +65 -17
  53. package/src/extensions/mcp-payloads.ts +19 -6
  54. package/src/extensions/posthog-events.ts +1 -0
  55. package/src/extensions/posthog-mcp.ts +74 -3
  56. package/src/extensions/sanitization.ts +3 -3
  57. package/src/index.ts +21 -0
  58. package/src/types.ts +119 -0
  59. package/src/version.ts +1 -1
package/src/types.ts CHANGED
@@ -101,6 +101,20 @@ export interface MCPAnalyticsOptions {
101
101
  logger?: LoggerFn
102
102
  /** Enable the `get_more_tools` virtual tool so agents can report missing functionality. */
103
103
  reportMissing?: boolean
104
+ /**
105
+ * Inject the `send_feedback` virtual tool so agents can send feedback about
106
+ * this server to its developers — a missing capability (the priority
107
+ * category), a tool that failed or confused them, or praise. Calls to it emit
108
+ * `$mcp_feedback` (never a `$mcp_tool_call`). Off by default.
109
+ *
110
+ * `true` uses the defaults; the object form renames the tool, replaces its
111
+ * description, declares host-specific `extraProperties`, or wires an
112
+ * `onFeedback` handler that routes reports to a real backend.
113
+ *
114
+ * Covers what `reportMissing` covers (as `feedback_type: "missing_capability"`),
115
+ * so new integrations should enable only one of the two.
116
+ */
117
+ collectFeedback?: CollectFeedbackConfig
104
118
  /**
105
119
  * Rename the `get_more_tools` virtual tool (the `reportMissing` feature).
106
120
  * Defaults to `get_more_tools`. Set once here so the tool is advertised and
@@ -186,6 +200,78 @@ export interface MCPAnalyticsContextOptions {
186
200
  description?: string
187
201
  }
188
202
 
203
+ export type FeedbackType = 'missing_capability' | 'issue' | 'praise' | 'other'
204
+ export type FeedbackSentiment = 'positive' | 'neutral' | 'negative' | 'mixed'
205
+
206
+ /** The `collectFeedback` option: `true` for the defaults, or the object form. */
207
+ export type CollectFeedbackConfig = boolean | CollectFeedbackOptions
208
+
209
+ /**
210
+ * A host-declared input-schema fragment for one `send_feedback` extra property —
211
+ * plain JSON Schema, the same shape the MCP `tools/list` wire format uses.
212
+ */
213
+ export interface FeedbackExtraPropertySchema {
214
+ type: string
215
+ description?: string
216
+ enum?: string[]
217
+ [key: string]: unknown
218
+ }
219
+
220
+ /** Object form of {@link CollectFeedbackConfig}. */
221
+ export interface CollectFeedbackOptions {
222
+ /**
223
+ * Rename the `send_feedback` virtual tool. Set once so the tool is advertised
224
+ * and detected under the same name. Defaults to `send_feedback`.
225
+ */
226
+ toolName?: string
227
+ /** Replace the default tool description. */
228
+ description?: string
229
+ /**
230
+ * Host-specific fields merged into the tool's advertised input schema. Each
231
+ * declared key is captured as a `$mcp_feedback_<key>` event property (through
232
+ * the standard sanitize/truncate pipeline); arguments the agent invents beyond
233
+ * the schema are never captured. A key that collides with a core field or an
234
+ * SDK-injected argument throws at configuration time.
235
+ */
236
+ extraProperties?: Record<string, FeedbackExtraPropertySchema>
237
+ /** Keys of `extraProperties` to advertise as required. */
238
+ extraRequired?: string[]
239
+ /**
240
+ * Route each report to a real backend (`instrument()` path only — a custom
241
+ * dispatcher routes reports itself, see {@link PreparedToolCall.isFeedback}).
242
+ * Return a string to replace the default acknowledgement text. A throw is
243
+ * logged and falls back to the default reply; the `$mcp_feedback` event is
244
+ * captured either way. The returned string is captured as `$mcp_response`
245
+ * through the generic sanitize pipeline only — unlike `$mcp_feedback_summary`
246
+ * / `details`, it does not get structured-PII redaction, so avoid echoing
247
+ * the agent's raw report text back in it.
248
+ */
249
+ onFeedback?: (report: FeedbackReport) => MaybePromise<string | void>
250
+ }
251
+
252
+ /** One parsed `send_feedback` call, as handed to `onFeedback` and the dispatcher. */
253
+ export interface FeedbackReport {
254
+ /** Invalid or missing values fall back to `other`. */
255
+ feedbackType: FeedbackType
256
+ /** One-sentence summary; empty string when the agent omitted it. */
257
+ summary: string
258
+ sentiment?: FeedbackSentiment
259
+ frictionPoints?: string
260
+ suggestedImprovement?: string
261
+ details?: string
262
+ /** The existing tool the feedback is about (`tool_name` argument). */
263
+ toolName?: string
264
+ taskCompleted?: boolean
265
+ /**
266
+ * Values of the declared `extraProperties` fields that match their declared
267
+ * `type`/`enum`. A value the agent sent with the wrong shape is left out
268
+ * (find it in `raw` if you need it), so these are safe to trust as declared.
269
+ */
270
+ extras: JsonRecord
271
+ /** The full raw arguments, for the handler only — never captured. */
272
+ raw: JsonRecord
273
+ }
274
+
189
275
  export interface MCPAnalyticsModelOptions {
190
276
  description?: string
191
277
  }
@@ -590,6 +676,14 @@ export interface PrepareToolListOptions {
590
676
  * {@link PostHogMCP.captureMissingCapability} and reply with `getMoreToolsResult()`.
591
677
  */
592
678
  reportMissing?: boolean
679
+ /**
680
+ * Append the `send_feedback` virtual tool so agents can send feedback.
681
+ * Defaults to `false`, and requires the `PostHogMCP` constructor's
682
+ * `collectFeedback` option (the enable switch that also gates detection).
683
+ * When the agent calls it, route the call to
684
+ * {@link PostHogMCP.captureFeedback} and reply with `sendFeedbackResult()`.
685
+ */
686
+ collectFeedback?: boolean
593
687
  }
594
688
 
595
689
  /** Options for {@link PostHogMCP.prepareToolCall}. */
@@ -621,6 +715,18 @@ export interface PreparedToolCall {
621
715
  args?: Record<string, unknown>
622
716
  /** True when `name` is the `get_more_tools` virtual tool. */
623
717
  isMissingCapability: boolean
718
+ /**
719
+ * True when `name` is the `send_feedback` virtual tool AND the constructor's
720
+ * `collectFeedback` option is set. Always false without that opt-in, so a real
721
+ * tool that happens to use the name is never shadowed.
722
+ */
723
+ isFeedback: boolean
724
+ /**
725
+ * The parsed feedback report, set only when {@link PreparedToolCall.isFeedback}
726
+ * is true. Pass it to {@link PostHogMCP.captureFeedback} and to your own
727
+ * feedback backend, then reply with `sendFeedbackResult()` or a custom text.
728
+ */
729
+ feedbackReport?: FeedbackReport
624
730
  }
625
731
 
626
732
  /** Payload for {@link PostHogMCP.captureMissingCapability}. Emits `$mcp_missing_capability`. */
@@ -637,3 +743,16 @@ export interface MissingCapabilityCaptureData extends McpCaptureCommon {
637
743
  /** Captured call arguments → `$mcp_parameters` (sanitized + truncated). */
638
744
  parameters?: unknown
639
745
  }
746
+
747
+ /** Payload for {@link PostHogMCP.captureFeedback}. Emits `$mcp_feedback`. */
748
+ export interface FeedbackCaptureData extends McpCaptureCommon {
749
+ /**
750
+ * The parsed report (from {@link PreparedToolCall.feedbackReport}) →
751
+ * `$mcp_feedback_*` properties, with the summary and details as `$mcp_intent`.
752
+ */
753
+ report: FeedbackReport
754
+ /** The calling model id -> `$mcp_llm_model`. */
755
+ llmModel?: string
756
+ /** How the model id was obtained -> `$mcp_llm_model_source`. */
757
+ llmModelSource?: MCPAnalyticsModelSource
758
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '0.15.0'
1
+ export const version = '0.16.0'