@posthog/mcp 0.0.8 → 0.1.16

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 (138) hide show
  1. package/LICENSE +307 -2
  2. package/README.md +186 -93
  3. package/dist/extensions/capture.d.ts +13 -0
  4. package/dist/extensions/capture.d.ts.map +1 -0
  5. package/dist/extensions/capture.js +80 -0
  6. package/dist/extensions/capture.mjs +46 -0
  7. package/dist/extensions/compatibility.d.ts +23 -0
  8. package/dist/extensions/compatibility.d.ts.map +1 -0
  9. package/dist/extensions/compatibility.js +113 -0
  10. package/dist/extensions/compatibility.mjs +67 -0
  11. package/dist/extensions/constants.d.ts +39 -0
  12. package/dist/extensions/constants.d.ts.map +1 -0
  13. package/dist/extensions/constants.js +86 -0
  14. package/dist/extensions/constants.mjs +37 -0
  15. package/dist/extensions/context-parameters.d.ts +31 -0
  16. package/dist/extensions/context-parameters.d.ts.map +1 -0
  17. package/dist/extensions/context-parameters.js +93 -0
  18. package/dist/extensions/context-parameters.mjs +50 -0
  19. package/dist/extensions/conversation-id.d.ts +52 -0
  20. package/dist/extensions/conversation-id.d.ts.map +1 -0
  21. package/dist/extensions/conversation-id.js +164 -0
  22. package/dist/extensions/conversation-id.mjs +103 -0
  23. package/dist/extensions/event-types.d.ts +21 -0
  24. package/dist/extensions/event-types.d.ts.map +1 -0
  25. package/dist/extensions/event-types.js +47 -0
  26. package/dist/extensions/event-types.mjs +13 -0
  27. package/dist/extensions/exceptions.d.ts +13 -0
  28. package/dist/extensions/exceptions.d.ts.map +1 -0
  29. package/dist/extensions/exceptions.js +58 -0
  30. package/dist/extensions/exceptions.mjs +24 -0
  31. package/dist/extensions/ids.d.ts +13 -0
  32. package/dist/extensions/ids.d.ts.map +1 -0
  33. package/dist/extensions/ids.js +55 -0
  34. package/dist/extensions/ids.mjs +18 -0
  35. package/dist/extensions/instrument-highlevel.d.ts +3 -0
  36. package/dist/extensions/instrument-highlevel.d.ts.map +1 -0
  37. package/dist/extensions/instrument-highlevel.js +229 -0
  38. package/dist/extensions/instrument-highlevel.mjs +195 -0
  39. package/dist/extensions/instrument-lowlevel.d.ts +8 -0
  40. package/dist/extensions/instrument-lowlevel.d.ts.map +1 -0
  41. package/dist/extensions/instrument-lowlevel.js +85 -0
  42. package/dist/extensions/instrument-lowlevel.mjs +51 -0
  43. package/dist/extensions/instrumentation.d.ts +59 -0
  44. package/dist/extensions/instrumentation.d.ts.map +1 -0
  45. package/dist/extensions/instrumentation.js +237 -0
  46. package/dist/extensions/instrumentation.mjs +194 -0
  47. package/dist/extensions/intent.d.ts +10 -0
  48. package/dist/extensions/intent.d.ts.map +1 -0
  49. package/dist/extensions/intent.js +84 -0
  50. package/dist/extensions/intent.mjs +44 -0
  51. package/dist/extensions/internal.d.ts +32 -0
  52. package/dist/extensions/internal.d.ts.map +1 -0
  53. package/dist/extensions/internal.js +158 -0
  54. package/dist/extensions/internal.mjs +106 -0
  55. package/dist/extensions/logger.d.ts +14 -0
  56. package/dist/extensions/logger.d.ts.map +1 -0
  57. package/dist/extensions/logger.js +47 -0
  58. package/dist/extensions/logger.mjs +10 -0
  59. package/dist/extensions/mcp-payloads.d.ts +5 -0
  60. package/dist/extensions/mcp-payloads.d.ts.map +1 -0
  61. package/dist/extensions/mcp-payloads.js +91 -0
  62. package/dist/extensions/mcp-payloads.mjs +54 -0
  63. package/dist/extensions/mcp-sdk-compat.d.ts +33 -0
  64. package/dist/extensions/mcp-sdk-compat.d.ts.map +1 -0
  65. package/dist/extensions/mcp-sdk-compat.js +112 -0
  66. package/dist/extensions/mcp-sdk-compat.mjs +60 -0
  67. package/dist/extensions/posthog-events.d.ts +14 -0
  68. package/dist/extensions/posthog-events.d.ts.map +1 -0
  69. package/dist/extensions/posthog-events.js +143 -0
  70. package/dist/extensions/posthog-events.mjs +109 -0
  71. package/dist/extensions/sanitization.d.ts +10 -0
  72. package/dist/extensions/sanitization.d.ts.map +1 -0
  73. package/dist/extensions/sanitization.js +96 -0
  74. package/dist/extensions/sanitization.mjs +62 -0
  75. package/dist/extensions/session.d.ts +20 -0
  76. package/dist/extensions/session.d.ts.map +1 -0
  77. package/dist/extensions/session.js +113 -0
  78. package/dist/extensions/session.mjs +67 -0
  79. package/dist/extensions/sink.d.ts +44 -0
  80. package/dist/extensions/sink.d.ts.map +1 -0
  81. package/dist/extensions/sink.js +102 -0
  82. package/dist/extensions/sink.mjs +65 -0
  83. package/dist/extensions/tools.d.ts +9 -0
  84. package/dist/extensions/tools.d.ts.map +1 -0
  85. package/dist/extensions/tools.js +79 -0
  86. package/dist/extensions/tools.mjs +39 -0
  87. package/dist/extensions/tracing-helpers.d.ts +29 -0
  88. package/dist/extensions/tracing-helpers.d.ts.map +1 -0
  89. package/dist/extensions/tracing-helpers.js +59 -0
  90. package/dist/extensions/tracing-helpers.mjs +16 -0
  91. package/dist/extensions/truncation.d.ts +25 -0
  92. package/dist/extensions/truncation.d.ts.map +1 -0
  93. package/dist/extensions/truncation.js +277 -0
  94. package/dist/extensions/truncation.mjs +228 -0
  95. package/dist/index.d.ts +36 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +132 -0
  98. package/dist/index.mjs +83 -2928
  99. package/dist/types.d.ts +220 -0
  100. package/dist/types.d.ts.map +1 -0
  101. package/dist/types.js +18 -0
  102. package/dist/types.mjs +0 -0
  103. package/dist/version.d.ts +2 -0
  104. package/dist/version.d.ts.map +1 -0
  105. package/dist/version.js +36 -0
  106. package/dist/version.mjs +2 -0
  107. package/package.json +55 -87
  108. package/src/extensions/capture.ts +68 -0
  109. package/src/extensions/compatibility.ts +138 -0
  110. package/src/extensions/constants.ts +48 -0
  111. package/src/extensions/context-parameters.ts +119 -0
  112. package/src/extensions/conversation-id.ts +177 -0
  113. package/src/extensions/event-types.ts +21 -0
  114. package/src/extensions/exceptions.ts +83 -0
  115. package/src/extensions/ids.ts +32 -0
  116. package/src/extensions/instrument-highlevel.ts +297 -0
  117. package/src/extensions/instrument-lowlevel.ts +83 -0
  118. package/src/extensions/instrumentation.ts +415 -0
  119. package/src/extensions/intent.ts +78 -0
  120. package/src/extensions/internal.ts +193 -0
  121. package/src/extensions/logger.ts +27 -0
  122. package/src/extensions/mcp-payloads.ts +98 -0
  123. package/src/extensions/mcp-sdk-compat.ts +160 -0
  124. package/src/extensions/posthog-events.ts +212 -0
  125. package/src/extensions/sanitization.ts +121 -0
  126. package/src/extensions/session.ts +117 -0
  127. package/src/extensions/sink.ts +130 -0
  128. package/src/extensions/tools.ts +50 -0
  129. package/src/extensions/tracing-helpers.ts +51 -0
  130. package/src/extensions/truncation.ts +453 -0
  131. package/src/index.ts +174 -0
  132. package/src/types.ts +244 -0
  133. package/src/version.ts +1 -0
  134. package/dist/index.cjs +0 -2936
  135. package/dist/index.cjs.map +0 -1
  136. package/dist/index.d.cts +0 -264
  137. package/dist/index.d.mts +0 -263
  138. package/dist/index.mjs.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,311 @@
1
+ Copyright 2020 Posthog / Hiberly, Inc.
2
+
3
+ Copyright 2015 Mixpanel, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this work except in compliance with the License.
7
+ You may obtain a copy of the License below, or at:
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ Apache License
18
+ Version 2.0, January 2004
19
+ http://www.apache.org/licenses/
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
193
+
194
+ APPENDIX: How to apply the Apache License to your work.
195
+
196
+ To apply the Apache License to your work, attach the following
197
+ boilerplate notice, with the fields enclosed by brackets "[]"
198
+ replaced with your own identifying information. (Don't include
199
+ the brackets!) The text should be enclosed in the appropriate
200
+ comment syntax for the file format. We also recommend that a
201
+ file or class name and description of purpose be included on the
202
+ same "printed page" as the copyright notice for easier
203
+ identification within third-party archives.
204
+
205
+ Copyright [yyyy] [name of copyright owner]
206
+
207
+ Licensed under the Apache License, Version 2.0 (the "License");
208
+ you may not use this file except in compliance with the License.
209
+ You may obtain a copy of the License at
210
+
211
+ http://www.apache.org/licenses/LICENSE-2.0
212
+
213
+ Unless required by applicable law or agreed to in writing, software
214
+ distributed under the License is distributed on an "AS IS" BASIS,
215
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
216
+ See the License for the specific language governing permissions and
217
+ limitations under the License.
218
+
219
+
220
+ ---
221
+
222
+ Some files in this codebase contain code from getsentry/sentry-javascript.
223
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
224
+
1
225
  MIT License
2
226
 
3
- Copyright (c) 2025 MCPcat
227
+ Copyright (c) 2012 Functional Software, Inc. dba Sentry
228
+
229
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
230
+ this software and associated documentation files (the "Software"), to deal in
231
+ the Software without restriction, including without limitation the rights to
232
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
233
+ of the Software, and to permit persons to whom the Software is furnished to do
234
+ so, subject to the following conditions:
235
+
236
+ The above copyright notice and this permission notice shall be included in all
237
+ copies or substantial portions of the Software.
238
+
239
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245
+ SOFTWARE.
246
+
247
+ ---
248
+
249
+ Some files in this codebase contain code from getsentry/sentry-react-native.
250
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
251
+
252
+ The MIT License (MIT)
253
+
254
+ Copyright (c) 2017 Sentry
255
+
256
+ Permission is hereby granted, free of charge, to any person obtaining a copy
257
+ of this software and associated documentation files (the "Software"), to deal
258
+ in the Software without restriction, including without limitation the rights
259
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
260
+ copies of the Software, and to permit persons to whom the Software is
261
+ furnished to do so, subject to the following conditions:
262
+
263
+ The above copyright notice and this permission notice shall be included in all
264
+ copies or substantial portions of the Software.
265
+
266
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
267
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
268
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
269
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
270
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
271
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
272
+ SOFTWARE.
273
+
274
+ ---
275
+
276
+ Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
277
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
278
+
279
+ MIT License
280
+
281
+ Copyright (c) Meta Platforms, Inc. and affiliates.
282
+
283
+ Permission is hereby granted, free of charge, to any person obtaining a copy
284
+ of this software and associated documentation files (the "Software"), to deal
285
+ in the Software without restriction, including without limitation the rights
286
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
287
+ copies of the Software, and to permit persons to whom the Software is
288
+ furnished to do so, subject to the following conditions:
289
+
290
+ The above copyright notice and this permission notice shall be included in all
291
+ copies or substantial portions of the Software.
292
+
293
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
294
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
295
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
296
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
297
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
298
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
299
+ SOFTWARE.
300
+
301
+ ---
302
+
303
+ Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
304
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
305
+
306
+ The MIT License (MIT)
307
+
308
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
4
309
 
5
310
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
311
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +323,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
323
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
324
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
325
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
326
+ SOFTWARE.
package/README.md CHANGED
@@ -1,146 +1,239 @@
1
- # PostHog MCP
1
+ # @posthog/mcp
2
2
 
3
- TypeScript SDK for instrumenting Model Context Protocol servers with PostHog analytics.
3
+ PostHog SDK for instrumenting [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) servers.
4
4
 
5
- > Warning:
6
- > This package is in very early access and is not suitable for production use yet.
7
- > The API, event names, PostHog property schema, tracing behavior, and release process may change without notice while we dogfood the SDK.
8
- > We publish in public because PostHog builds in public, but you should treat `0.0.x` releases as experimental.
9
-
10
- The initial goal is to help MCP server owners understand tool usage, agent intent, client/session metadata, errors, and feedback without hand-rolling MCP-specific analytics.
5
+ One call wraps your MCP server and PostHog starts receiving structured events for every tool call, tool listing, initialize handshake, identify, and exception, with all the usual PostHog primitives (`$session_id`, `distinct_id`, `$set`, `$groups`, `$exception`) wired up automatically.
11
6
 
12
7
  ## Install
13
8
 
14
9
  ```bash
15
- pnpm add @posthog/mcp
10
+ npm install @posthog/mcp posthog-node
16
11
  ```
17
12
 
18
- ## Usage
13
+ `@modelcontextprotocol/sdk` ≥ 1.26 and `posthog-node` ≥ 5 are peer dependencies.
19
14
 
20
- ```ts
21
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
- import { track } from "@posthog/mcp";
15
+ ## Quick start
23
16
 
24
- const server = new Server({ name: "my-mcp-server", version: "1.0.0" });
17
+ You bring your own [`posthog-node`](https://posthog.com/docs/libraries/node) client and pass it in (same pattern as [`@posthog/ai`](https://posthog.com/docs/libraries/ai)). You own its configuration and lifecycle — call `posthog.shutdown()` on exit so queued events flush.
25
18
 
26
- track(server, {
27
- apiKey: process.env.POSTHOG_API_KEY,
28
- context: true,
29
- enableAITracing: true,
30
- host: "https://us.i.posthog.com",
31
- });
19
+ ```ts
20
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
21
+ import { PostHog } from 'posthog-node'
22
+ import { z } from 'zod'
23
+ import { instrument } from '@posthog/mcp'
24
+
25
+ const posthog = new PostHog('phc_your_project_token', { host: 'https://us.i.posthog.com' })
26
+
27
+ const server = new McpServer({ name: 'my-mcp-server', version: '1.0.0' })
28
+
29
+ server.tool(
30
+ 'search_docs',
31
+ 'Search PostHog documentation',
32
+ { query: z.string() },
33
+ async ({ query }) => ({
34
+ content: [{ type: 'text', text: `Searching for "${query}"...` }],
35
+ })
36
+ )
37
+
38
+ // One line. From here on every tool call, tool listing, and initialize
39
+ // handshake on this server is captured to PostHog.
40
+ const analytics = instrument(server, posthog)
41
+
42
+ // You own the client lifecycle — flush before the process exits.
43
+ process.on('SIGTERM', async () => {
44
+ await posthog.shutdown()
45
+ process.exit(0)
46
+ })
32
47
  ```
33
48
 
34
- With `context: true`, the SDK adds a required `context` argument to every tool call, strips it before invoking your handler, and captures it as `$mcp_intent` on PostHog events.
35
- Captured tool parameters omit the duplicated `context` value and MCP transport internals.
49
+ What you get in PostHog out of the box:
50
+
51
+ | Event | When | A few of the auto-captured properties |
52
+ |---|---|---|
53
+ | `$mcp_tool_call` | every tool invocation | `$mcp_tool_name`, `$mcp_parameters`, `$mcp_response`, `$mcp_duration_ms`, `$mcp_is_error` |
54
+ | `$mcp_tools_list` | client lists tools | `$mcp_listed_tool_names` |
55
+ | `$mcp_initialize` | client/server handshake | `$mcp_client_name`, `$mcp_client_version`, `$mcp_server_name` |
56
+ | `$exception` | a tool throws or returns `isError` | `$exception_list`, `$exception_level` (standard PostHog error-tracking shape) |
57
+ | `$identify` | first time `identify()` returns a non-null identity | `$set` populated from the identity's `properties` |
58
+ | `$mcp_missing_capability` | agent calls `get_more_tools` (when `reportMissing` is on) | `$mcp_intent` — what the agent was looking for |
59
+
60
+ Events for sessions with no resolved identity are sent with `$process_person_profile: false`, so anonymous MCP traffic doesn't mint a person profile per session.
61
+
62
+ The full event + property catalog (including `$mcp_resources_*` / `$mcp_prompts_*`) lives in [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md).
63
+
64
+ ## Coming from another PostHog SDK?
65
+
66
+ The surface maps onto concepts you already know — the main twist is that, because an MCP server handles many requests/sessions, the identity- and property-resolving hooks are **per-request callbacks** rather than imperative calls.
67
+
68
+ | You know | Here it's | Note |
69
+ |---|---|---|
70
+ | BYO client in `@posthog/ai` | `instrument(server, posthog, options?)` → returns an `McpAnalytics` handle | Same pattern: you construct and own the `posthog-node` client and pass it positionally. |
71
+ | `posthog.capture({ event, properties })` | `analytics.capture({ event, properties })` | A method on the handle returned by `instrument()`. `distinct_id` is derived from the session/identity for you. |
72
+ | `posthog.identify({ distinctId, properties })` | `identify: (req) => ({ distinctId, properties, groups })` | A per-request callback. `properties` → `$set`, `groups` → `$groups`. |
73
+ | `posthog.register(props)` (super properties) | `eventProperties: (req) => ({ … })` | Per-request instead of set-once; return constants for the "stamp on everything" case. |
74
+ | `beforeSend` | `beforeSend(event)` | Identical contract to posthog-node. |
75
+
76
+ ## Common patterns
77
+
78
+ ### Identify the calling user
36
79
 
37
- Use `intentFallback` when you want a fallback for clients that call tools without the `context` argument.
38
- This is a consumer-supplied callback — the SDK does no inference of its own; whatever string you return becomes `$mcp_intent`.
39
- The explicit `context` argument always wins; fallback values are marked with `$mcp_intent_source = "inferred"`.
80
+ `identify` runs on every tool call but only emits an `$identify` event when the returned identity actually changes for a session. From there on, events for that session are attributed to the user.
40
81
 
41
82
  ```ts
42
- track(server, {
43
- apiKey: process.env.POSTHOG_API_KEY,
44
- context: true,
45
- intentFallback: (request) => {
46
- const toolName = request.params?.name;
47
- return toolName ? `Calling ${toolName}` : undefined;
83
+ import jwt from 'jsonwebtoken'
84
+
85
+ instrument(server, posthog, {
86
+ identify: async (request, extra) => {
87
+ const auth = extra?.headers?.authorization
88
+ if (!auth) return null
89
+
90
+ const { sub, email, plan } = jwt.verify(stripBearer(auth), SECRET) as {
91
+ sub: string
92
+ email: string
93
+ plan: 'free' | 'pro'
94
+ }
95
+
96
+ return {
97
+ distinctId: sub, // → distinct_id for the session
98
+ properties: { name: email, plan }, // → $set on the person
99
+ groups: { organization: 'org_123' }, // optional → $groups on every event
100
+ }
48
101
  },
49
- });
102
+ })
50
103
  ```
51
104
 
52
- With `enableAITracing: true`, tool calls also emit `$ai_span` events with `$ai_trace_id` and `$ai_span_id`.
53
- The regular `mcp_tool_call` event includes the same trace/span IDs so it can be joined back to the LLM analytics span.
105
+ This is the same shape as posthog-node's `identify({ distinctId, properties })`, just evaluated per request: `distinctId` becomes the `distinct_id`, `properties` are written to `$set` (so put `name`/`email`/etc there), and `groups` is stamped onto every event as `$groups` so you never hand-write the dollar-keyed properties yourself.
106
+
107
+ ### Capture user intent
54
108
 
55
- ### Conversation ID (opt-in)
109
+ PostHog injects an optional `context` parameter into every tool's input schema. When the LLM passes a value, the SDK stores it as `$mcp_intent` (with `$mcp_intent_source = "context_parameter"`) so dashboards can group tool calls by *why* the agent invoked them.
56
110
 
57
- When `enableConversationId: true` is passed to `track()`, the SDK injects an optional `conversation_id` argument into every tool's input schema and tells the agent to reuse the value the server returns. When the agent omits it on a call, the SDK mints a UUID and appends a short text block to the tool's response asking the agent to echo the same `conversation_id` on subsequent calls. The value the agent supplies (or the SDK mints) is captured on PostHog events as `$mcp_conversation_id` — separate from `$session_id`, which is unchanged. Off by default.
111
+ If a client ignores the schema (raw cURL, in-house agents, JSON-blind crawlers), supply `intentFallback` and the SDK will derive an intent from the request:
58
112
 
59
113
  ```ts
60
- track(server, {
61
- apiKey: process.env.POSTHOG_API_KEY,
62
- enableConversationId: true,
63
- });
114
+ instrument(server, posthog, {
115
+ intentFallback: (request) => {
116
+ const tool = request.params?.name
117
+ const args = request.params?.arguments ?? {}
118
+ if (tool === 'search_docs') return `Searching docs for "${args.query}"`
119
+ return tool ? `Invoking ${tool}` : null
120
+ },
121
+ })
64
122
  ```
65
123
 
66
- **Caveats:**
124
+ ### Capture a custom event
125
+
126
+ For domain-specific events that aren't auto-captured (e.g. user feedback, workflow milestones). Call `.capture()` on the handle returned by `instrument()`. You name the event; it's sent verbatim (it's your event, so it isn't `$`-prefixed):
127
+
128
+ ```ts
129
+ const analytics = instrument(server, posthog)
130
+
131
+ await analytics.capture({
132
+ event: 'feedback_submitted',
133
+ properties: { rating: 5, comment: 'love it' },
134
+ })
135
+ ```
67
136
 
68
- - The prompt-back is appended as a regular `text` content block (the only channel MCP currently offers for server→agent communication). Consumers that surface raw tool-call content to end users will see `[SERVER]: Reuse conversation_id=…` in their UI. If/when the MCP spec grows a server-directives channel (e.g. on `_meta`), the SDK will move there.
69
- - The captured `$mcp_conversation_id` value is agent-controlled when the agent supplies one — the SDK accepts any non-empty string. Customers wanting to bind it to their own session scheme (chat ID, JWT `jti`, request ID) can do so freely; the trade-off is that nothing prevents a misbehaving agent from sending arbitrary values.
137
+ The event is enriched with `$session_id`, `distinct_id`, and server/client metadata before being sent. `analytics.capture()` resolves once the event has been processed, so you can `await` it.
70
138
 
71
- The SDK sends events through `posthog-node`, so it uses the same PostHog ingestion client, batching, retry, flush, and shutdown behavior as the existing Node SDK.
139
+ ### Inspect, modify, or drop events before send (`beforeSend`)
72
140
 
73
- If your application already owns a PostHog client, pass it in instead:
141
+ `beforeSend` runs on each fully-built payload right before it reaches `posthog.capture()` (same contract as posthog-node). Return the event to send it, mutate its `properties`, or return `null` to drop it. It runs once per emitted event, including the `$exception` sibling of a failed call.
74
142
 
75
143
  ```ts
76
- import { PostHog } from "posthog-node";
77
- import { track } from "@posthog/mcp";
144
+ instrument(server, posthog, {
145
+ beforeSend: (event) => {
146
+ // Redact a property
147
+ if (typeof event.properties.$mcp_parameters === 'string') {
148
+ event.properties.$mcp_parameters = event.properties.$mcp_parameters.replace(/api_key_\w+/g, '[REDACTED]')
149
+ }
150
+ // Drop a whole class of events
151
+ if (event.event === '$exception') return null
152
+ return event
153
+ },
154
+ })
155
+ ```
78
156
 
79
- const posthog = new PostHog(process.env.POSTHOG_API_KEY ?? "");
157
+ ### Attach extra properties to every event
80
158
 
81
- track(server, {
82
- posthogClient: posthog,
83
- });
159
+ ```ts
160
+ instrument(server, posthog, {
161
+ eventProperties: (request, extra) => ({
162
+ deployment: process.env.NODE_ENV,
163
+ region: 'us-east-1',
164
+ feature_flags: ['dark_mode', 'beta_ui'],
165
+ }),
166
+ })
84
167
  ```
85
168
 
86
- ## Event schema
169
+ Returned keys are spread flat onto event properties, sitting alongside `$mcp_*` keys, and can intentionally override them.
87
170
 
88
- The SDK emits PostHog events using a stable MCP-specific schema.
89
- The package exports `PostHogMCPAnalyticsEvent`, `PostHogMCPAnalyticsProperty`, and `POSTHOG_MCP_ANALYTICS_SOURCE` constants so product code can query the same contract without hard-coded strings.
171
+ ### Get more tools (`reportMissing`)
90
172
 
91
- Canonical event names:
173
+ Register an extra `get_more_tools` virtual tool that lets the agent report functionality it couldn't find. Each report lands as its own `$mcp_missing_capability` event (a capability gap, not a tool invocation) with the agent's reasoning in `$mcp_intent`.
92
174
 
93
- - `mcp_tool_call` for each MCP tool call
94
- - `mcp_tools_list` when clients list available tools
95
- - `mcp_initialize` when clients initialize a session
96
- - `$ai_span` for tool-call spans when `enableAITracing: true`
97
- - `$exception` for captured tool errors
175
+ ```ts
176
+ instrument(server, posthog, {
177
+ reportMissing: true,
178
+ })
179
+ ```
98
180
 
99
- Important properties:
181
+ ### Tie tool calls into a single conversation
100
182
 
101
- - `$mcp_source = "posthog_mcp_analytics"`
102
- - `$mcp_intent` from the `context` argument, or from `intentFallback` when no context was provided
103
- - `$mcp_intent_source` as `context_parameter` or `inferred`
104
- - `$mcp_tool_name` and `$mcp_resource_name`
105
- - `$mcp_tool_description`, the tool's current `description` at the moment of the call — populated on `mcp_tool_call` and on the paired `$exception` event so the description is visible inline while triaging
106
- - `$mcp_listed_tool_names`, the array of tool names advertised in a `tools/list` response — populated on `mcp_tools_list` events so you can correlate "tools the agent was offered" with "tools the agent actually called" (e.g. find advertised tools that never get picked)
107
- - `$mcp_parameters` and `$mcp_response`, after redaction and truncation
108
- - `$mcp_duration_ms`
109
- - `$mcp_is_error`
110
- - `$session_id`
111
- - `$ai_trace_id`, `$ai_span_id`, and `$ai_session_id` when AI tracing is enabled
183
+ Opt into `enableConversationId: true` and the SDK injects a `conversation_id` parameter into every tool, mints one when the agent omits it, and appends a prompt-back text block telling the agent to echo it on every subsequent call. Events get `$mcp_conversation_id` so you can group all calls in an agent conversation.
112
184
 
113
- The SDK does not emit `$mcp_context`.
114
- Use `$mcp_intent` for agent/user intent.
185
+ ```ts
186
+ instrument(server, posthog, {
187
+ enableConversationId: true,
188
+ })
189
+ ```
115
190
 
116
- See [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) for the full architecture, property catalog, sample queries, and migration notes vs the upstream mcpcat schema.
191
+ ### Turn off exception autocapture
117
192
 
118
- ## Development
193
+ A failed tool call emits an `$exception` sibling alongside the `$mcp_tool_call` by default. Set `enableExceptionAutocapture: false` if you track errors elsewhere and don't want MCP failures fanning into PostHog error tracking:
119
194
 
120
- ```bash
121
- pnpm install
122
- pnpm verify
195
+ ```ts
196
+ instrument(server, posthog, {
197
+ enableExceptionAutocapture: false,
198
+ })
123
199
  ```
124
200
 
125
- Useful commands:
201
+ ## API
126
202
 
127
- ```bash
128
- pnpm build
129
- pnpm test
130
- pnpm typecheck
131
- pnpm typecheck:tsc6
132
- pnpm fix
203
+ - **`instrument(server, posthog, options?)`**: wraps a low-level `Server` or high-level `McpServer`. The `posthog-node` client is a required positional 2nd argument; `options` is optional. Idempotent per server instance (subsequent calls on the same server are skipped via a `WeakMap` lookup). Returns an `McpAnalytics` handle.
204
+ - **`analytics.capture({ event, properties })`**: a method on the handle returned by `instrument()` that emits one custom event. `event` is required and sent verbatim (not `$`-prefixed). Returns a promise you can `await`.
205
+
206
+ The full options reference lives in [`src/types.ts`](./src/types.ts) (`MCPAnalyticsOptions`) and the design narrative + HogQL recipes live in [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md).
207
+
208
+ ## Graceful shutdown
209
+
210
+ The SDK doesn't own the client, so flushing is just `posthog.shutdown()` on your `posthog-node` instance — see the Quick start above. Nothing MCP-specific to tear down.
211
+
212
+ ### Serverless / short-lived processes
213
+
214
+ In a serverless function (Lambda, Cloudflare Workers, Vercel) the process can freeze or exit before `posthog-node` flushes its queue. Flush explicitly at the end of the invocation rather than relying on a `SIGTERM` handler:
215
+
216
+ ```ts
217
+ // at the end of the request/invocation
218
+ await posthog.flush()
219
+ // or keep the runtime alive until the flush completes
220
+ ctx.waitUntil(posthog.flush())
133
221
  ```
134
222
 
135
- `pnpm typecheck` uses the TypeScript 7 native preview via `tsgo`.
223
+ ## Logging in STDIO MCP servers
136
224
 
137
- ## Releases
225
+ MCP over STDIO uses stdout/stderr for protocol messages, so the SDK never logs to them. Pass a `logger` callback if you want to capture SDK-internal warnings:
138
226
 
139
- Releases are semi-automatic through Changesets and GitHub Actions.
140
- See [RELEASE.md](./RELEASE.md) for the release process.
227
+ ```ts
228
+ import fs from 'node:fs'
229
+ const logStream = fs.createWriteStream('mcp.log', { flags: 'a' })
141
230
 
142
- Release approval requests are posted in Slack to `#approvals-client-libraries`.
231
+ instrument(server, posthog, {
232
+ logger: (msg) => logStream.write(`${new Date().toISOString()} ${msg}\n`),
233
+ })
234
+ ```
143
235
 
144
- ## Attribution
236
+ ## Docs
145
237
 
146
- This SDK started from a duplicated copy of the MIT-licensed [MCPcat TypeScript SDK](https://github.com/MCPCat/mcpcat-typescript-sdk). We are grateful for their work on MCP server instrumentation patterns, especially tool-call tracing, context capture, and MCP SDK compatibility handling.
238
+ - [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md): wire-up, request lifecycle, event pipeline, full event + property catalog, intent resolution, file map, HogQL query recipes.
239
+ - [PostHog docs](https://posthog.com/docs): the rest.