@productbrain/mcp 0.0.1-beta.1 → 0.0.1-beta.10

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/.env.mcp.example CHANGED
@@ -1,28 +1,23 @@
1
- # ProductBrain MCP — Environment Variables
1
+ # Product Brain MCP — Environment Variables
2
2
  # Copy this file to .env.mcp and fill in your values.
3
3
  # In Claude Desktop / Cursor, these are typically set via the MCP config's "env" block.
4
4
 
5
- # ── Cloud Mode (recommended) ──────────────────────────────────────────
5
+ # ── Required ─────────────────────────────────────────────────────────
6
6
  #
7
- # PRODUCTBRAIN_API_KEY — Your API key from SynergyOS Settings → API Keys.
8
- # Starts with pb_sk_. This is the only required variable.
9
- #
10
- # PRODUCTBRAIN_URL — Override the backend URL.
11
- # Defaults to ProductBrain Cloud. Set to http://localhost:3210
12
- # for local development.
7
+ # PRODUCTBRAIN_API_KEY — Your API key from Settings → API Keys.
8
+ # Starts with pb_sk_. Workspace, user, and scope
9
+ # are all derived server-side from this key.
13
10
 
14
11
  # PRODUCTBRAIN_API_KEY=pb_sk_your_key_here
15
- # PRODUCTBRAIN_URL=https://earnest-sheep-635.convex.site
16
12
 
17
- # ── Self-Hosted Mode ──────────────────────────────────────────────────
13
+ # ── Deployment URL (optional) ────────────────────────────────────────
14
+ #
15
+ # CONVEX_SITE_URL — Your Convex deployment SITE URL (*.convex.site, NOT *.convex.cloud).
16
+ # Defaults to Product Brain Cloud if not set.
18
17
  #
19
- # CONVEX_SITE_URL Your Convex deployment SITE URL (*.convex.site, NOT *.convex.cloud).
20
- # MCP_API_KEY — Shared secret matching the Convex dashboard env var.
21
- # WORKSPACE_SLUG — The workspace slug to operate on.
18
+ # PRODUCTBRAIN_URL Alias for CONVEX_SITE_URL (for backward compat).
22
19
 
23
20
  # CONVEX_SITE_URL=https://your-deployment.convex.site
24
- # MCP_API_KEY=your-secret-api-key
25
- # WORKSPACE_SLUG=your-workspace-slug
26
21
 
27
22
  # ── Debug (optional) ──────────────────────────────────────────────────
28
23
  # MCP_DEBUG=1
@@ -0,0 +1,100 @@
1
+ // src/analytics.ts
2
+ import { userInfo } from "os";
3
+ import { PostHog } from "posthog-node";
4
+ var client = null;
5
+ var distinctId = "anonymous";
6
+ var POSTHOG_HOST = "https://eu.i.posthog.com";
7
+ function log(msg) {
8
+ if (process.env.MCP_DEBUG === "1") {
9
+ process.stderr.write(msg);
10
+ }
11
+ }
12
+ function initAnalytics() {
13
+ const apiKey = process.env.POSTHOG_MCP_KEY || "";
14
+ if (!apiKey) {
15
+ log("[MCP-ANALYTICS] No PostHog key \u2014 tracking disabled (set SYNERGYOS_POSTHOG_KEY at build time for publish)\n");
16
+ return;
17
+ }
18
+ client = new PostHog(apiKey, {
19
+ host: POSTHOG_HOST,
20
+ flushAt: 1,
21
+ flushInterval: 5e3
22
+ });
23
+ distinctId = process.env.MCP_USER_ID || fallbackDistinctId();
24
+ log(`[MCP-ANALYTICS] Initialized \u2014 host=${POSTHOG_HOST} distinctId=${distinctId}
25
+ `);
26
+ }
27
+ function fallbackDistinctId() {
28
+ try {
29
+ return userInfo().username;
30
+ } catch {
31
+ return `os-${process.pid}`;
32
+ }
33
+ }
34
+ function trackSessionStarted(workspaceId, serverVersion) {
35
+ if (!client) return;
36
+ client.capture({
37
+ distinctId,
38
+ event: "mcp_session_started",
39
+ properties: {
40
+ workspace_id: workspaceId,
41
+ server_version: serverVersion,
42
+ source: "mcp-server",
43
+ $groups: { workspace: workspaceId }
44
+ }
45
+ });
46
+ }
47
+ function trackToolCall(fn, status, durationMs, workspaceId, errorMsg) {
48
+ const properties = {
49
+ tool: fn,
50
+ status,
51
+ duration_ms: durationMs,
52
+ workspace_id: workspaceId,
53
+ source: "mcp-server",
54
+ $groups: { workspace: workspaceId }
55
+ };
56
+ if (errorMsg) properties.error = errorMsg;
57
+ if (!client) return;
58
+ client.capture({
59
+ distinctId,
60
+ event: "mcp_tool_called",
61
+ properties
62
+ });
63
+ }
64
+ function trackSetupStarted() {
65
+ if (!client) return;
66
+ client.capture({
67
+ distinctId,
68
+ event: "mcp_setup_started",
69
+ properties: {
70
+ source: "mcp-server",
71
+ platform: process.platform
72
+ }
73
+ });
74
+ }
75
+ function trackSetupCompleted(chosenClient, outcome) {
76
+ if (!client) return;
77
+ client.capture({
78
+ distinctId,
79
+ event: "mcp_setup_completed",
80
+ properties: {
81
+ client: chosenClient,
82
+ outcome,
83
+ source: "mcp-server",
84
+ platform: process.platform
85
+ }
86
+ });
87
+ }
88
+ async function shutdownAnalytics() {
89
+ await client?.shutdown();
90
+ }
91
+
92
+ export {
93
+ initAnalytics,
94
+ trackSessionStarted,
95
+ trackToolCall,
96
+ trackSetupStarted,
97
+ trackSetupCompleted,
98
+ shutdownAnalytics
99
+ };
100
+ //# sourceMappingURL=chunk-XBMI6QHR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/analytics.ts"],"sourcesContent":["/**\n * PostHog analytics for SynergyOS maintainers — tracks MCP usage (sessions, tool calls).\n * Not user-facing. Key is injected at build time via SYNERGYOS_POSTHOG_KEY.\n * Override with POSTHOG_MCP_KEY for self-hosted deployments.\n */\n\nimport { userInfo } from \"node:os\";\nimport { PostHog } from \"posthog-node\";\n\nlet client: PostHog | null = null;\nlet distinctId = \"anonymous\";\n\nconst POSTHOG_HOST = \"https://eu.i.posthog.com\";\n\n/** Injected at build time: SYNERGYOS_POSTHOG_KEY env when running `npm run build`/publish. */\ndeclare const __SYNERGYOS_POSTHOG_KEY__: string;\n\n/** Only write to stderr when MCP_DEBUG=1 for quieter default DX. */\nfunction log(msg: string): void {\n if (process.env.MCP_DEBUG === \"1\") {\n process.stderr.write(msg);\n }\n}\n\nexport function initAnalytics(): void {\n const apiKey = process.env.POSTHOG_MCP_KEY || __SYNERGYOS_POSTHOG_KEY__;\n if (!apiKey) {\n log(\"[MCP-ANALYTICS] No PostHog key — tracking disabled (set SYNERGYOS_POSTHOG_KEY at build time for publish)\\n\");\n return;\n }\n\n client = new PostHog(apiKey, {\n host: POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 5000,\n });\n distinctId = process.env.MCP_USER_ID || fallbackDistinctId();\n\n log(`[MCP-ANALYTICS] Initialized — host=${POSTHOG_HOST} distinctId=${distinctId}\\n`);\n}\n\nfunction fallbackDistinctId(): string {\n try {\n return userInfo().username;\n } catch {\n return `os-${process.pid}`;\n }\n}\n\nexport function trackSessionStarted(\n workspaceId: string,\n serverVersion: string,\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_session_started\",\n properties: {\n workspace_id: workspaceId,\n server_version: serverVersion,\n source: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n}\n\nexport function trackToolCall(\n fn: string,\n status: \"ok\" | \"error\",\n durationMs: number,\n workspaceId: string,\n errorMsg?: string,\n): void {\n const properties: Record<string, unknown> = {\n tool: fn,\n status,\n duration_ms: durationMs,\n workspace_id: workspaceId,\n source: \"mcp-server\",\n $groups: { workspace: workspaceId },\n };\n if (errorMsg) properties.error = errorMsg;\n\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_tool_called\",\n properties,\n });\n}\n\nexport function trackSetupStarted(): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_setup_started\",\n properties: {\n source: \"mcp-server\",\n platform: process.platform,\n },\n });\n}\n\nexport function trackSetupCompleted(\n chosenClient: string,\n outcome: \"config_written\" | \"config_existed\" | \"snippet_shown\" | \"write_error\",\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_setup_completed\",\n properties: {\n client: chosenClient,\n outcome,\n source: \"mcp-server\",\n platform: process.platform,\n },\n });\n}\n\nexport async function shutdownAnalytics(): Promise<void> {\n await client?.shutdown();\n}\n"],"mappings":";AAMA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAExB,IAAI,SAAyB;AAC7B,IAAI,aAAa;AAEjB,IAAM,eAAe;AAMrB,SAAS,IAAI,KAAmB;AAC9B,MAAI,QAAQ,IAAI,cAA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