@productbrain/mcp 0.0.1-beta.11288 → 0.0.1-beta.11296

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.
@@ -1,257 +1,3 @@
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 getBuildTimeKey() {
13
- try {
14
- return "";
15
- } catch {
16
- return "";
17
- }
18
- }
19
- function initAnalytics() {
20
- const apiKey = process.env.POSTHOG_MCP_KEY || getBuildTimeKey();
21
- if (!apiKey) {
22
- log("[MCP-ANALYTICS] No PostHog key \u2014 tracking disabled (set SYNERGYOS_POSTHOG_KEY at build time for publish)\n");
23
- return;
24
- }
25
- client = new PostHog(apiKey, {
26
- host: POSTHOG_HOST,
27
- flushAt: 1,
28
- flushInterval: 5e3,
29
- featureFlagsPollingInterval: 3e4
30
- });
31
- distinctId = process.env.MCP_USER_ID || fallbackDistinctId();
32
- log(`[MCP-ANALYTICS] Initialized \u2014 host=${POSTHOG_HOST} distinctId=${distinctId}
33
- `);
34
- }
35
- function fallbackDistinctId() {
36
- try {
37
- return userInfo().username;
38
- } catch {
39
- return `os-${process.pid}`;
40
- }
41
- }
42
- function trackSessionStarted(workspaceId, serverVersion) {
43
- if (!client) return;
44
- client.capture({
45
- distinctId,
46
- event: "mcp_session_started",
47
- properties: {
48
- workspace_id: workspaceId,
49
- server_version: serverVersion,
50
- source: "mcp-server",
51
- $groups: { workspace: workspaceId }
52
- }
53
- });
54
- }
55
- function trackToolCall(fn, status, durationMs, workspaceId, errorMsg) {
56
- const properties = {
57
- tool: fn,
58
- status,
59
- duration_ms: durationMs,
60
- workspace_id: workspaceId,
61
- source: "mcp-server",
62
- $groups: { workspace: workspaceId }
63
- };
64
- if (errorMsg) properties.error = errorMsg;
65
- if (!client) return;
66
- client.capture({
67
- distinctId,
68
- event: "mcp_tool_called",
69
- properties
70
- });
71
- }
72
- function trackCompoundToolAction(tool, action, workspaceId) {
73
- if (!client) return;
74
- client.capture({
75
- distinctId,
76
- event: "mcp_compound_tool_action",
77
- properties: {
78
- tool,
79
- action: action ?? null,
80
- workspace_id: workspaceId,
81
- source: "mcp-server",
82
- $groups: { workspace: workspaceId }
83
- }
84
- });
85
- }
86
- function trackSetupStarted() {
87
- if (!client) return;
88
- client.capture({
89
- distinctId,
90
- event: "mcp_setup_started",
91
- properties: {
92
- source: "mcp-server",
93
- platform: process.platform
94
- }
95
- });
96
- }
97
- function trackSetupCompleted(chosenClient, outcome) {
98
- if (!client) return;
99
- client.capture({
100
- distinctId,
101
- event: "mcp_setup_completed",
102
- properties: {
103
- client: chosenClient,
104
- outcome,
105
- source: "mcp-server",
106
- platform: process.platform
107
- }
108
- });
109
- }
110
- function trackQualityVerdict(workspaceId, props) {
111
- if (!client) return;
112
- client.capture({
113
- distinctId,
114
- event: "quality_verdict_generated",
115
- properties: {
116
- ...props,
117
- workspace_id: workspaceId,
118
- source_system: "mcp-server",
119
- $groups: { workspace: workspaceId }
120
- }
121
- });
122
- }
123
- function trackQualityCheck(workspaceId, props) {
124
- if (!client) return;
125
- client.capture({
126
- distinctId,
127
- event: "quality_verdict_checked",
128
- properties: {
129
- ...props,
130
- workspace_id: workspaceId,
131
- source_system: "mcp-server",
132
- $groups: { workspace: workspaceId }
133
- }
134
- });
135
- }
136
- function trackChainEntryCommitted(workspaceId, props) {
137
- if (!client) return;
138
- try {
139
- client.capture({
140
- distinctId,
141
- event: "chain_entry_committed",
142
- properties: {
143
- workspace_id: workspaceId,
144
- source_system: "mcp-server",
145
- $groups: { workspace: workspaceId },
146
- ...props
147
- }
148
- });
149
- } catch {
150
- }
151
- }
152
- function trackKnowledgeGap(workspaceId, props) {
153
- if (!client) return;
154
- try {
155
- client.capture({
156
- distinctId,
157
- event: "knowledge_gap_detected",
158
- properties: {
159
- ...props,
160
- query: props.query.slice(0, 200),
161
- workspace_id: workspaceId,
162
- source_system: "mcp-server",
163
- $groups: { workspace: workspaceId }
164
- }
165
- });
166
- } catch {
167
- }
168
- }
169
- function trackCaptureQualityHints(workspaceId, props) {
170
- if (!client) return;
171
- try {
172
- client.capture({
173
- distinctId,
174
- event: "mcp_capture_quality_hints",
175
- properties: {
176
- ...props,
177
- workspace_id: workspaceId,
178
- source_system: "mcp-server",
179
- $groups: { workspace: workspaceId }
180
- }
181
- });
182
- } catch {
183
- }
184
- }
185
- function trackSessionCaptureRate(workspaceId, props) {
186
- if (!client) return;
187
- try {
188
- client.capture({
189
- distinctId,
190
- event: "session_capture_rate",
191
- properties: {
192
- ...props,
193
- workspace_id: workspaceId,
194
- source_system: "mcp-server",
195
- $groups: { workspace: workspaceId }
196
- }
197
- });
198
- } catch {
199
- }
200
- }
201
- function trackZeroCaptureAuditFired(workspaceId) {
202
- if (!client) return;
203
- try {
204
- client.capture({
205
- distinctId,
206
- event: "zero_capture_audit_fired",
207
- properties: {
208
- workspace_id: workspaceId,
209
- source_system: "mcp-server",
210
- $groups: { workspace: workspaceId }
211
- }
212
- });
213
- } catch {
214
- }
215
- }
216
- function trackCaptureContractMiss(workspaceId, props) {
217
- if (!client) return;
218
- try {
219
- client.capture({
220
- distinctId,
221
- event: "capture_contract_miss",
222
- properties: {
223
- ...props,
224
- workspace_id: workspaceId,
225
- source_system: "mcp-server",
226
- $groups: { workspace: workspaceId }
227
- }
228
- });
229
- } catch {
230
- }
231
- }
232
- function trackCommitErrorByCode(workspaceId, props) {
233
- if (!client) return;
234
- try {
235
- client.capture({
236
- distinctId,
237
- event: "commit_error_by_code",
238
- properties: {
239
- ...props,
240
- workspace_id: workspaceId,
241
- source_system: "mcp-server",
242
- $groups: { workspace: workspaceId }
243
- }
244
- });
245
- } catch {
246
- }
247
- }
248
- function getPostHogClient() {
249
- return client;
250
- }
251
- async function shutdownAnalytics() {
252
- await client?.shutdown();
253
- }
254
-
255
1
  // src/auth.ts
256
2
  import { AsyncLocalStorage } from "async_hooks";
257
3
  import { createHash } from "crypto";
@@ -359,8 +105,8 @@ function readJsonSafe(path) {
359
105
  return {};
360
106
  }
361
107
  }
362
- async function writeClientConfig(client2, apiKey) {
363
- const config = readJsonSafe(client2.configPath);
108
+ async function writeClientConfig(client, apiKey) {
109
+ const config = readJsonSafe(client.configPath);
364
110
  const serversKey = "mcpServers";
365
111
  if (!config[serversKey]) config[serversKey] = {};
366
112
  if (config[serversKey][LEGACY_ENTRY_KEY]) {
@@ -374,11 +120,11 @@ async function writeClientConfig(client2, apiKey) {
374
120
  const existing = config[serversKey][SERVER_ENTRY_KEY];
375
121
  config[serversKey][SERVER_ENTRY_KEY] = existing ? { ...existing, env: { ...existing.env, PRODUCTBRAIN_API_KEY: apiKey } } : buildServerEntry(apiKey);
376
122
  }
377
- const dir = dirname(client2.configPath);
123
+ const dir = dirname(client.configPath);
378
124
  if (!existsSync(dir)) {
379
125
  mkdirSync(dir, { recursive: true });
380
126
  }
381
- writeFileSync(client2.configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
127
+ writeFileSync(client.configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
382
128
  return true;
383
129
  }
384
130
 
@@ -836,7 +582,6 @@ function recordGatewayCall(params) {
836
582
  if (timedOut) entry.timedOut = true;
837
583
  appendAuditEntry(entry);
838
584
  recordSeamCounters(workspace, fn, status, durationMs, timedOut === true);
839
- trackToolCall(fn, status, durationMs, workspace, errorMsg);
840
585
  if (!shouldLogAudit(status)) return;
841
586
  const base = `[MCP-AUDIT] ${ts} fn=${fn} workspace=${workspace} status=${status} duration=${durationMs}ms${budgetMs !== void 0 ? ` budget=${budgetMs}ms` : ""}${timedOut ? " timedOut=true" : ""}`;
842
587
  process.stderr.write(
@@ -1316,7 +1061,6 @@ function getConversationId() {
1316
1061
  var toolContextStore = new AsyncLocalStorage3();
1317
1062
  function runWithToolContext(ctx, fn) {
1318
1063
  recordToolAction(ctx.tool, ctx.action);
1319
- trackCompoundToolAction(ctx.tool, ctx.action, state().workspaceId ?? "unresolved");
1320
1064
  return toolContextStore.run(ctx, () => runWithCommandId(fn));
1321
1065
  }
1322
1066
  function getToolContext() {
@@ -1804,21 +1548,6 @@ function apiKeysUrl() {
1804
1548
  }
1805
1549
 
1806
1550
  export {
1807
- initAnalytics,
1808
- trackSessionStarted,
1809
- trackSetupStarted,
1810
- trackSetupCompleted,
1811
- trackQualityVerdict,
1812
- trackQualityCheck,
1813
- trackChainEntryCommitted,
1814
- trackKnowledgeGap,
1815
- trackCaptureQualityHints,
1816
- trackSessionCaptureRate,
1817
- trackZeroCaptureAuditFired,
1818
- trackCaptureContractMiss,
1819
- trackCommitErrorByCode,
1820
- getPostHogClient,
1821
- shutdownAnalytics,
1822
1551
  getAuditLog,
1823
1552
  getMergedGatewaySeamCounters,
1824
1553
  formatGatewaySeamSummary,
@@ -1869,4 +1598,4 @@ export {
1869
1598
  appUrl,
1870
1599
  apiKeysUrl
1871
1600
  };
1872
- //# sourceMappingURL=chunk-GQCZUKKL.js.map
1601
+ //# sourceMappingURL=chunk-XAFCPBXE.js.map