@posthog/mcp 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MCPcat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # PostHog MCP
2
+
3
+ TypeScript SDK for instrumenting Model Context Protocol servers with PostHog analytics.
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.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add @posthog/mcp
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
+ import { track } from "@posthog/mcp";
23
+
24
+ const server = new Server({ name: "my-mcp-server", version: "1.0.0" });
25
+
26
+ track(server, {
27
+ apiKey: process.env.POSTHOG_API_KEY,
28
+ context: true,
29
+ enableAITracing: true,
30
+ host: "https://us.i.posthog.com",
31
+ });
32
+ ```
33
+
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.
36
+
37
+ With `enableAITracing: true`, tool calls also emit `$ai_span` events with `$ai_trace_id` and `$ai_span_id`.
38
+ The regular `mcp_tool_call` event includes the same trace/span IDs so it can be joined back to the LLM analytics span.
39
+
40
+ 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.
41
+
42
+ If your application already owns a PostHog client, pass it in instead:
43
+
44
+ ```ts
45
+ import { PostHog } from "posthog-node";
46
+ import { track } from "@posthog/mcp";
47
+
48
+ const posthog = new PostHog(process.env.POSTHOG_API_KEY ?? "");
49
+
50
+ track(server, {
51
+ posthogClient: posthog,
52
+ });
53
+ ```
54
+
55
+ ## Development
56
+
57
+ ```bash
58
+ pnpm install
59
+ pnpm verify
60
+ ```
61
+
62
+ Useful commands:
63
+
64
+ ```bash
65
+ pnpm build
66
+ pnpm test
67
+ pnpm typecheck
68
+ pnpm typecheck:tsc6
69
+ pnpm fix
70
+ ```
71
+
72
+ `pnpm typecheck` uses the TypeScript 7 native preview via `tsgo`.
73
+
74
+ ## Attribution
75
+
76
+ 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.