recall-mcp-v3 3.9.3 → 3.9.4
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/dist/__tests__/started-beacon.test.d.ts +14 -0
- package/dist/__tests__/started-beacon.test.d.ts.map +1 -0
- package/dist/__tests__/started-beacon.test.js +200 -0
- package/dist/__tests__/started-beacon.test.js.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/started-beacon.d.ts +37 -0
- package/dist/started-beacon.d.ts.map +1 -0
- package/dist/started-beacon.js +80 -0
- package/dist/started-beacon.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the MCP startup beacon factory (PR 7).
|
|
3
|
+
*
|
|
4
|
+
* Pinned contracts:
|
|
5
|
+
* - First invocation calls heartbeat() with state='mcp_started',
|
|
6
|
+
* mcp_client from detection, clientVersion from factory opts,
|
|
7
|
+
* transport='stdio'.
|
|
8
|
+
* - Subsequent invocations are no-ops (process-local guard).
|
|
9
|
+
* - Heartbeat failures are caught + logged; beacon function never throws.
|
|
10
|
+
* - The factory is independent — two factories from one process each
|
|
11
|
+
* have their own guard.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=started-beacon.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"started-beacon.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/started-beacon.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the MCP startup beacon factory (PR 7).
|
|
3
|
+
*
|
|
4
|
+
* Pinned contracts:
|
|
5
|
+
* - First invocation calls heartbeat() with state='mcp_started',
|
|
6
|
+
* mcp_client from detection, clientVersion from factory opts,
|
|
7
|
+
* transport='stdio'.
|
|
8
|
+
* - Subsequent invocations are no-ops (process-local guard).
|
|
9
|
+
* - Heartbeat failures are caught + logged; beacon function never throws.
|
|
10
|
+
* - The factory is independent — two factories from one process each
|
|
11
|
+
* have their own guard.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
14
|
+
import { createStartedBeacon } from '../started-beacon.js';
|
|
15
|
+
const FAKE_DETECTION = {
|
|
16
|
+
mcp_client: 'claude-code',
|
|
17
|
+
ai_provider: 'anthropic',
|
|
18
|
+
environment: 'terminal',
|
|
19
|
+
os: 'darwin',
|
|
20
|
+
transport: 'stdio',
|
|
21
|
+
confidence: 'high',
|
|
22
|
+
raw: {},
|
|
23
|
+
};
|
|
24
|
+
describe('createStartedBeacon', () => {
|
|
25
|
+
it('first call fires heartbeat with mcp_started + injected detection + version', async () => {
|
|
26
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
27
|
+
const beacon = createStartedBeacon({
|
|
28
|
+
version: '3.9.4',
|
|
29
|
+
heartbeat: heartbeatMock,
|
|
30
|
+
getDetection: () => FAKE_DETECTION,
|
|
31
|
+
});
|
|
32
|
+
await beacon();
|
|
33
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(1);
|
|
34
|
+
expect(heartbeatMock).toHaveBeenCalledWith({
|
|
35
|
+
state: 'mcp_started',
|
|
36
|
+
mcpClient: 'claude-code',
|
|
37
|
+
clientVersion: '3.9.4',
|
|
38
|
+
transport: 'stdio',
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('second call is a no-op (process-local guard)', async () => {
|
|
42
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
43
|
+
const beacon = createStartedBeacon({
|
|
44
|
+
version: '3.9.4',
|
|
45
|
+
heartbeat: heartbeatMock,
|
|
46
|
+
getDetection: () => FAKE_DETECTION,
|
|
47
|
+
});
|
|
48
|
+
await beacon();
|
|
49
|
+
await beacon();
|
|
50
|
+
await beacon();
|
|
51
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
it('does NOT fire detection more than once when called twice', async () => {
|
|
54
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
55
|
+
const detectionMock = vi.fn(() => FAKE_DETECTION);
|
|
56
|
+
const beacon = createStartedBeacon({
|
|
57
|
+
version: '3.9.4',
|
|
58
|
+
heartbeat: heartbeatMock,
|
|
59
|
+
getDetection: detectionMock,
|
|
60
|
+
});
|
|
61
|
+
await beacon();
|
|
62
|
+
await beacon();
|
|
63
|
+
expect(detectionMock).toHaveBeenCalledTimes(1);
|
|
64
|
+
});
|
|
65
|
+
it('catches and logs heartbeat failures (does not throw to caller)', async () => {
|
|
66
|
+
const heartbeatMock = vi.fn(async () => {
|
|
67
|
+
throw new Error('No auth token persisted');
|
|
68
|
+
});
|
|
69
|
+
const logMock = vi.fn();
|
|
70
|
+
const beacon = createStartedBeacon({
|
|
71
|
+
version: '3.9.4',
|
|
72
|
+
heartbeat: heartbeatMock,
|
|
73
|
+
getDetection: () => FAKE_DETECTION,
|
|
74
|
+
log: logMock,
|
|
75
|
+
});
|
|
76
|
+
// Must not reject — beacon is fire-and-forget at every call site.
|
|
77
|
+
await expect(beacon()).resolves.toBeUndefined();
|
|
78
|
+
expect(logMock).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(logMock.mock.calls[0][0]).toMatch(/mcp_started beacon.*No auth token persisted/);
|
|
80
|
+
});
|
|
81
|
+
it('locks the guard on permanent failures (no auth token) — avoids retry storm', async () => {
|
|
82
|
+
const heartbeatMock = vi.fn(async (_input) => {
|
|
83
|
+
throw new Error('No auth token persisted; run `recall-mcp-v3 auth` before sending heartbeats');
|
|
84
|
+
});
|
|
85
|
+
const beacon = createStartedBeacon({
|
|
86
|
+
version: '3.9.4',
|
|
87
|
+
heartbeat: heartbeatMock,
|
|
88
|
+
getDetection: () => FAKE_DETECTION,
|
|
89
|
+
log: () => undefined,
|
|
90
|
+
});
|
|
91
|
+
await beacon();
|
|
92
|
+
await beacon();
|
|
93
|
+
await beacon();
|
|
94
|
+
// No-token-persisted is stable for the life of the process; retrying
|
|
95
|
+
// would hammer the API on every request without changing the answer.
|
|
96
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(1);
|
|
97
|
+
});
|
|
98
|
+
it('allows retry on transient failures (network error / timeout / 5xx)', async () => {
|
|
99
|
+
let attempt = 0;
|
|
100
|
+
const heartbeatMock = vi.fn(async (_input) => {
|
|
101
|
+
attempt += 1;
|
|
102
|
+
if (attempt === 1) {
|
|
103
|
+
throw new Error('Heartbeat failed: HTTP 503 Service Unavailable — transient');
|
|
104
|
+
}
|
|
105
|
+
// Subsequent attempts succeed.
|
|
106
|
+
});
|
|
107
|
+
const beacon = createStartedBeacon({
|
|
108
|
+
version: '3.9.4',
|
|
109
|
+
heartbeat: heartbeatMock,
|
|
110
|
+
getDetection: () => FAKE_DETECTION,
|
|
111
|
+
log: () => undefined,
|
|
112
|
+
});
|
|
113
|
+
await beacon();
|
|
114
|
+
await beacon();
|
|
115
|
+
// Transient failure unlocks the guard so the second request retries.
|
|
116
|
+
// A flaky moment must not permanently drop the funnel signal for the
|
|
117
|
+
// life of a long-running session.
|
|
118
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(2);
|
|
119
|
+
});
|
|
120
|
+
it('locks the guard once a transient failure eventually succeeds', async () => {
|
|
121
|
+
let attempt = 0;
|
|
122
|
+
const heartbeatMock = vi.fn(async (_input) => {
|
|
123
|
+
attempt += 1;
|
|
124
|
+
if (attempt === 1) {
|
|
125
|
+
throw new Error('Heartbeat failed: AbortError');
|
|
126
|
+
}
|
|
127
|
+
// Second call succeeds.
|
|
128
|
+
});
|
|
129
|
+
const beacon = createStartedBeacon({
|
|
130
|
+
version: '3.9.4',
|
|
131
|
+
heartbeat: heartbeatMock,
|
|
132
|
+
getDetection: () => FAKE_DETECTION,
|
|
133
|
+
log: () => undefined,
|
|
134
|
+
});
|
|
135
|
+
await beacon();
|
|
136
|
+
await beacon();
|
|
137
|
+
// Third call after success should NOT re-fire.
|
|
138
|
+
await beacon();
|
|
139
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(2);
|
|
140
|
+
});
|
|
141
|
+
it('catches detection failures + leaves guard open for retry', async () => {
|
|
142
|
+
let detectionAttempt = 0;
|
|
143
|
+
const detectionMock = vi.fn(() => {
|
|
144
|
+
detectionAttempt += 1;
|
|
145
|
+
if (detectionAttempt === 1) {
|
|
146
|
+
throw new Error('detect failed: ENOENT');
|
|
147
|
+
}
|
|
148
|
+
return FAKE_DETECTION;
|
|
149
|
+
});
|
|
150
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
151
|
+
const logMock = vi.fn();
|
|
152
|
+
const beacon = createStartedBeacon({
|
|
153
|
+
version: '3.9.4',
|
|
154
|
+
heartbeat: heartbeatMock,
|
|
155
|
+
getDetection: detectionMock,
|
|
156
|
+
log: logMock,
|
|
157
|
+
});
|
|
158
|
+
// First call: detection throws. Must NOT reject, must NOT call heartbeat,
|
|
159
|
+
// must log + leave the guard open so a future call retries. Without this,
|
|
160
|
+
// a single transient detection error permanently drops mcp_started for
|
|
161
|
+
// the life of the process.
|
|
162
|
+
await expect(beacon()).resolves.toBeUndefined();
|
|
163
|
+
expect(heartbeatMock).not.toHaveBeenCalled();
|
|
164
|
+
expect(logMock).toHaveBeenCalledTimes(1);
|
|
165
|
+
expect(logMock.mock.calls[0][0]).toMatch(/mcp_started beacon.*detection failed.*ENOENT/);
|
|
166
|
+
// Second call: detection succeeds, heartbeat fires.
|
|
167
|
+
await beacon();
|
|
168
|
+
expect(detectionMock).toHaveBeenCalledTimes(2);
|
|
169
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(1);
|
|
170
|
+
});
|
|
171
|
+
it('two factories from one process have independent guards', async () => {
|
|
172
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
173
|
+
const detectionMock = () => FAKE_DETECTION;
|
|
174
|
+
const beaconA = createStartedBeacon({
|
|
175
|
+
version: '3.9.4',
|
|
176
|
+
heartbeat: heartbeatMock,
|
|
177
|
+
getDetection: detectionMock,
|
|
178
|
+
});
|
|
179
|
+
const beaconB = createStartedBeacon({
|
|
180
|
+
version: '3.9.4',
|
|
181
|
+
heartbeat: heartbeatMock,
|
|
182
|
+
getDetection: detectionMock,
|
|
183
|
+
});
|
|
184
|
+
await beaconA();
|
|
185
|
+
await beaconB();
|
|
186
|
+
// Each beacon fires once (independent state).
|
|
187
|
+
expect(heartbeatMock).toHaveBeenCalledTimes(2);
|
|
188
|
+
});
|
|
189
|
+
it('forwards different mcp_client values from detection', async () => {
|
|
190
|
+
const heartbeatMock = vi.fn(async (_input) => undefined);
|
|
191
|
+
const beacon = createStartedBeacon({
|
|
192
|
+
version: '3.9.4',
|
|
193
|
+
heartbeat: heartbeatMock,
|
|
194
|
+
getDetection: () => ({ ...FAKE_DETECTION, mcp_client: 'cursor' }),
|
|
195
|
+
});
|
|
196
|
+
await beacon();
|
|
197
|
+
expect(heartbeatMock.mock.calls[0][0]).toMatchObject({ mcpClient: 'cursor' });
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
//# sourceMappingURL=started-beacon.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"started-beacon.test.js","sourceRoot":"","sources":["../../src/__tests__/started-beacon.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,cAAc,GAAwB;IAC1C,UAAU,EAAE,aAAa;IACzB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,UAAU;IACvB,EAAE,EAAE,QAAQ;IACZ,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE,MAAM;IAClB,GAAG,EAAE,EAAE;CACR,CAAC;AAEF,QAAQ,CAAC,qBAAqB,EAAE,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AAO,EAAE,CAAC;QAEhB,8CAA8C;QAC9C,MAAM,CAAC,aAAa,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,aAAa,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,MAAe,EAAiB,EAAE,CAAC,SAAS,CAAC,CAAC;QAEjF,MAAM,MAAM,GAAG,mBAAmB,CAAC;YACjC,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,aAAa;YACxB,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;SAClE,CAAC,CAAC;QAEH,MAAM,MAAM,EAAE,CAAC;QACf,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const { version: MCP_VERSION } = require('../package.json');
|
|
|
17
17
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
18
18
|
import { getContext, getOrigin, getUserSessions, getHistory, getTranscripts, saveSession, logDecision, getTeamActivity, } from './tools.js';
|
|
19
19
|
import { runCli } from './cli.js';
|
|
20
|
+
import { createStartedBeacon } from './started-beacon.js';
|
|
20
21
|
// Tool definitions
|
|
21
22
|
const TOOLS = [
|
|
22
23
|
{
|
|
@@ -200,6 +201,7 @@ const TOOLS = [
|
|
|
200
201
|
];
|
|
201
202
|
class RecallServer {
|
|
202
203
|
server;
|
|
204
|
+
fireStartedBeacon;
|
|
203
205
|
constructor() {
|
|
204
206
|
this.server = new Server({
|
|
205
207
|
name: 'recall-mcp',
|
|
@@ -209,15 +211,26 @@ class RecallServer {
|
|
|
209
211
|
tools: {},
|
|
210
212
|
},
|
|
211
213
|
});
|
|
214
|
+
this.fireStartedBeacon = createStartedBeacon({ version: MCP_VERSION });
|
|
212
215
|
this.setupHandlers();
|
|
213
216
|
}
|
|
214
217
|
setupHandlers() {
|
|
215
218
|
// List available tools
|
|
216
219
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
220
|
+
// Fire mcp_started exactly once per process. ListTools is the first
|
|
221
|
+
// method any AI tool calls after MCP initialize; firing here proves
|
|
222
|
+
// the tool actually loaded the server (not just enumerated the
|
|
223
|
+
// binary). Fire-and-forget so the response is never blocked.
|
|
224
|
+
void this.fireStartedBeacon();
|
|
217
225
|
return { tools: TOOLS };
|
|
218
226
|
});
|
|
219
227
|
// Handle tool calls
|
|
220
228
|
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
229
|
+
// Belt-and-suspenders: some clients call CallTool without a
|
|
230
|
+
// prior ListTools (e.g., after a reconnection that skipped
|
|
231
|
+
// capability negotiation). The beacon's internal guard makes
|
|
232
|
+
// duplicate firings a cheap no-op.
|
|
233
|
+
void this.fireStartedBeacon();
|
|
221
234
|
const { name, arguments: args = {} } = request.params;
|
|
222
235
|
try {
|
|
223
236
|
let result;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,gCAAgC;AAChC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,WAAW,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,CAAC,KAAK,EAAE,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,CAAC;IACN,4DAA4D;IAC5D,MAAM,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;IAClC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP startup beacon factory — install-health PR 7 / P1.E.2.
|
|
3
|
+
*
|
|
4
|
+
* Lives in its own module (separate from index.ts) so tests can import
|
|
5
|
+
* it without booting a real `RecallServer` over stdio. The MCP entry
|
|
6
|
+
* binary's bottom-of-file bootstrap (`new RecallServer(); server.run()`)
|
|
7
|
+
* runs at module-load time; routing tests through this file keeps that
|
|
8
|
+
* side effect away from vitest workers.
|
|
9
|
+
*/
|
|
10
|
+
import { heartbeat } from './auth/heartbeat.js';
|
|
11
|
+
import { getCachedDetection } from './detect.js';
|
|
12
|
+
/**
|
|
13
|
+
* Build a once-only "MCP started" beacon callable.
|
|
14
|
+
*
|
|
15
|
+
* Calling the returned function fires `heartbeat({ state: 'mcp_started' })`
|
|
16
|
+
* exactly once per invocation of this factory, against a permanent
|
|
17
|
+
* failure mode. Transient failures (network blip, 5xx, AbortSignal
|
|
18
|
+
* timeout, or a detection probe error) leave the guard open so the
|
|
19
|
+
* next request retries.
|
|
20
|
+
*
|
|
21
|
+
* Designed to be called from the first incoming MCP request handler
|
|
22
|
+
* (ListTools or CallTool) — that's what proves the AI tool actually
|
|
23
|
+
* loaded the server, not just enumerated the binary.
|
|
24
|
+
*
|
|
25
|
+
* Failures are caught and logged to stderr; a beacon failure must
|
|
26
|
+
* never break the MCP request the user is making.
|
|
27
|
+
*
|
|
28
|
+
* Deps are injectable so tests can mock heartbeat + detection without
|
|
29
|
+
* patching modules.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createStartedBeacon(opts: {
|
|
32
|
+
version: string;
|
|
33
|
+
heartbeat?: typeof heartbeat;
|
|
34
|
+
getDetection?: typeof getCachedDetection;
|
|
35
|
+
log?: (msg: string) => void;
|
|
36
|
+
}): () => Promise<void>;
|
|
37
|
+
//# sourceMappingURL=started-beacon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"started-beacon.d.ts","sourceRoot":"","sources":["../src/started-beacon.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACzC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAgDtB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP startup beacon factory — install-health PR 7 / P1.E.2.
|
|
3
|
+
*
|
|
4
|
+
* Lives in its own module (separate from index.ts) so tests can import
|
|
5
|
+
* it without booting a real `RecallServer` over stdio. The MCP entry
|
|
6
|
+
* binary's bottom-of-file bootstrap (`new RecallServer(); server.run()`)
|
|
7
|
+
* runs at module-load time; routing tests through this file keeps that
|
|
8
|
+
* side effect away from vitest workers.
|
|
9
|
+
*/
|
|
10
|
+
import { heartbeat } from './auth/heartbeat.js';
|
|
11
|
+
import { getCachedDetection } from './detect.js';
|
|
12
|
+
/**
|
|
13
|
+
* Build a once-only "MCP started" beacon callable.
|
|
14
|
+
*
|
|
15
|
+
* Calling the returned function fires `heartbeat({ state: 'mcp_started' })`
|
|
16
|
+
* exactly once per invocation of this factory, against a permanent
|
|
17
|
+
* failure mode. Transient failures (network blip, 5xx, AbortSignal
|
|
18
|
+
* timeout, or a detection probe error) leave the guard open so the
|
|
19
|
+
* next request retries.
|
|
20
|
+
*
|
|
21
|
+
* Designed to be called from the first incoming MCP request handler
|
|
22
|
+
* (ListTools or CallTool) — that's what proves the AI tool actually
|
|
23
|
+
* loaded the server, not just enumerated the binary.
|
|
24
|
+
*
|
|
25
|
+
* Failures are caught and logged to stderr; a beacon failure must
|
|
26
|
+
* never break the MCP request the user is making.
|
|
27
|
+
*
|
|
28
|
+
* Deps are injectable so tests can mock heartbeat + detection without
|
|
29
|
+
* patching modules.
|
|
30
|
+
*/
|
|
31
|
+
export function createStartedBeacon(opts) {
|
|
32
|
+
let fired = false;
|
|
33
|
+
const heartbeatImpl = opts.heartbeat ?? heartbeat;
|
|
34
|
+
const detectionImpl = opts.getDetection ?? getCachedDetection;
|
|
35
|
+
const logImpl = opts.log ?? ((msg) => console.error(msg));
|
|
36
|
+
return async () => {
|
|
37
|
+
if (fired)
|
|
38
|
+
return;
|
|
39
|
+
fired = true;
|
|
40
|
+
let detection;
|
|
41
|
+
try {
|
|
42
|
+
detection = detectionImpl();
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
// Detection errors are always transient — env probing can blip on
|
|
46
|
+
// a transient FS/process read. Unlock the guard so the next request
|
|
47
|
+
// retries; never let detection failure silently drop the funnel
|
|
48
|
+
// signal for the life of a long-running session.
|
|
49
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
50
|
+
fired = false;
|
|
51
|
+
logImpl(`[mcp_started beacon] detection failed: ${msg}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
await heartbeatImpl({
|
|
56
|
+
state: 'mcp_started',
|
|
57
|
+
mcpClient: detection.mcp_client,
|
|
58
|
+
clientVersion: opts.version,
|
|
59
|
+
transport: 'stdio',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
64
|
+
// Differentiate permanent from transient failures:
|
|
65
|
+
// - "No auth token persisted" is stable for the life of this
|
|
66
|
+
// process (user hasn't run `recall-mcp-v3 auth` yet). Keep
|
|
67
|
+
// fired=true so we don't hammer the API on every request.
|
|
68
|
+
// - Network blips, 5xx, AbortSignal timeout are transient. Let
|
|
69
|
+
// the next request retry — a flaky moment shouldn't
|
|
70
|
+
// permanently drop the funnel signal for a long-running
|
|
71
|
+
// Claude Code session.
|
|
72
|
+
const isPermanent = msg.includes('No auth token persisted');
|
|
73
|
+
if (!isPermanent) {
|
|
74
|
+
fired = false;
|
|
75
|
+
}
|
|
76
|
+
logImpl(`[mcp_started beacon] heartbeat failed: ${msg}`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=started-beacon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"started-beacon.js","sourceRoot":"","sources":["../src/started-beacon.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAKnC;IACC,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,IAAI,kBAAkB,CAAC;IAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CA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