@veilio-inc/mcp 0.5.2 → 0.6.1

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/namespace.js CHANGED
@@ -15,9 +15,26 @@
15
15
  // whole JSON-RPC pipeline (server.ts, tools.ts) synchronous rather than
16
16
  // threading a Promise through 78 existing call sites for one network call that
17
17
  // happens once per process.
18
+ // The namespace read is the MCP server's request too.
19
+ import './identity.js';
18
20
  import { resolveTeamNamespace } from '@veilio-inc/cli/team-namespace';
19
21
  import { readCredential } from '@veilio-inc/cli/credential';
20
22
  import { readTeamUnlock } from '@veilio-inc/cli/team-unlock';
23
+ import { projectOverride, resolveOverride } from '@veilio-inc/cli/client';
24
+ /**
25
+ * The project the namespace is for, as a cache key: VEILIO_PROJECT's value
26
+ * when the server's environment sets it (spec 052 FR-012a), else the choice
27
+ * kept with the sign-in. With the variable set, a `projects use` in a
28
+ * terminal changes nothing here - the variable wins - so it must not throw
29
+ * away a namespace the variable pinned.
30
+ */
31
+ function scopeKey(home, env) {
32
+ const override = projectOverride(env);
33
+ if (override !== null)
34
+ return `env:${override}`;
35
+ const stored = readCredential(home)?.project;
36
+ return stored ? `stored:${stored}` : null;
37
+ }
21
38
  function localFrom(found) {
22
39
  return {
23
40
  source: 'local',
@@ -62,21 +79,74 @@ async function fetchNamespace(home, opts) {
62
79
  */
63
80
  export function primeNamespace(home, opts = {}) {
64
81
  primedWith = { home, opts };
82
+ primed = true;
65
83
  lastAttemptAt = Date.now();
66
84
  if (!priming) {
67
- priming = fetchNamespace(home, { deadlineMs: STARTUP_DEADLINE_MS, ...opts }).then((resolved) => {
68
- current = resolved;
69
- return resolved;
85
+ // The project is read when the fetch STARTS, and the fetch is for that
86
+ // project only. Its answer is kept only if it is still the newest fetch
87
+ // and the credential still names that project: a prime that finishes
88
+ // after the project changed holds the OLD project's maps, and assigning
89
+ // it would put that project's placeholders into this one's work - the
90
+ // cross-project leak FR-013 forbids (security review).
91
+ const project = scopeKey(home, opts.env);
92
+ const generation = ++primeGeneration;
93
+ primedProject = project;
94
+ settledFlag = false;
95
+ // The id the fetch resolved the project to: what the cache is FOR.
96
+ let resolvedId = null;
97
+ priming = fetchNamespace(home, {
98
+ deadlineMs: STARTUP_DEADLINE_MS,
99
+ ...opts,
100
+ onProject: (id) => (resolvedId = id),
101
+ }).then((resolved) => {
102
+ const still = scopeKey(home, opts.env) === project;
103
+ if (generation === primeGeneration && still) {
104
+ current = resolved;
105
+ primedProjectId = resolvedId;
106
+ // The fetch asked the server which project the variable names: that
107
+ // answer is a confirmation (a failed listing is not one).
108
+ if (projectOverride(opts.env) !== null &&
109
+ (resolvedId !== null || resolved.found.status === 'refused'))
110
+ confirmedAt = performance.now();
111
+ settledFlag = true;
112
+ }
113
+ return current;
70
114
  });
71
115
  }
72
116
  return priming;
73
117
  }
118
+ /** Which fetch is the newest; an older one's answer is discarded. */
119
+ let primeGeneration = 0;
74
120
  /** A hung instance must not hold the agent's first tool call for 30 s. */
75
121
  const STARTUP_DEADLINE_MS = 10_000;
76
122
  /** How often an 'unavailable' team is asked again, from a tool call. */
77
123
  const UNAVAILABLE_RECHECK_MS = 30_000;
78
124
  let primedWith = { opts: {} };
79
125
  let lastAttemptAt = 0;
126
+ let primed = false;
127
+ /** The project the cached namespace is for (spec 052 FR-013). */
128
+ let primedProject = null;
129
+ /**
130
+ * The project ID the cached namespace was read for. VEILIO_PROJECT's value is
131
+ * only a name, and a name can move: the project renamed, another one given the
132
+ * old name, the value unchanged. The value says when to ASK again
133
+ * (`confirmProject`); the id says whether the answer changed.
134
+ */
135
+ let primedProjectId = null;
136
+ /** When the server last said which project the variable names (monotonic ms). */
137
+ let confirmedAt = null;
138
+ /** How long a confirmation is trusted before the next masking call asks again. */
139
+ export const CONFIRM_TTL_MS = 30_000;
140
+ /** Set by a team write through this server: the cache no longer matches. */
141
+ let invalidated = false;
142
+ /**
143
+ * The team's maps just changed through this server - a team map created,
144
+ * updated or removed, or another project chosen - so the cached namespace is
145
+ * out of date. The next tool call starts loading it again.
146
+ */
147
+ export function invalidateNamespace() {
148
+ invalidated = true;
149
+ }
80
150
  /**
81
151
  * The cache must not outlive the reason it was cached (review): `veilio team
82
152
  * unlock` run after this server started said "restore again" and every retry
@@ -86,7 +156,35 @@ let lastAttemptAt = 0;
86
156
  * sees the result. A settled `team` or `local` is kept for the process.
87
157
  */
88
158
  export function refreshNamespaceIfStale() {
159
+ // Another project chosen - by `veilio projects use` in a terminal while this
160
+ // server runs, or by projects_use here - or a team write made here: the
161
+ // namespace cached for the old state must not go on numbering the new one
162
+ // (spec 052 edge case: the next call uses the new state).
163
+ if (primed) {
164
+ // Checked FIRST, whatever is in flight: a fetch already running is for the
165
+ // project it started with, and is dropped (security review).
166
+ const project = scopeKey(primedWith.home, primedWith.opts.env);
167
+ if (project !== primedProject) {
168
+ // The cached namespace is the OLD project's (FR-013): see
169
+ // reloadForAnotherProject. Until the new project's maps load there is no
170
+ // team namespace, and that is said.
171
+ void reloadForAnotherProject();
172
+ return 'changed';
173
+ }
174
+ // The same project, changed by a write made here: reload when nothing is
175
+ // already loading, keeping the current (same-project) namespace meanwhile.
176
+ if (invalidated && (!priming || settledFlag)) {
177
+ invalidated = false;
178
+ priming = null;
179
+ void primeNamespace(primedWith.home, primedWith.opts);
180
+ return 'changed';
181
+ }
182
+ }
89
183
  const status = current.found.status;
184
+ // 'refused' is not asked again here: it exists only with the variable set,
185
+ // the server's projects can change under it (one created, a shared name made
186
+ // unique), and `confirmProject` asks that on its own TTL - two paths asking
187
+ // the same question would pay for it twice.
90
188
  if (status !== 'locked' && status !== 'unavailable')
91
189
  return null;
92
190
  if (priming && !settledFlag)
@@ -100,13 +198,82 @@ export function refreshNamespaceIfStale() {
100
198
  if (!due)
101
199
  return null;
102
200
  priming = null;
103
- settledFlag = false;
104
- void primeNamespace(primedWith.home, primedWith.opts).then(() => {
105
- settledFlag = true;
106
- });
201
+ void primeNamespace(primedWith.home, primedWith.opts);
107
202
  return status === 'locked' ? 'unlocked' : 'retrying';
108
203
  }
109
204
  let settledFlag = true;
205
+ /** Drop what is cached and load again, saying so: the old answer was for
206
+ * another project, and numbering with it - even once - would put that
207
+ * project's placeholders into this one's store (FR-013). */
208
+ function reloadForAnotherProject() {
209
+ current = localFrom({
210
+ status: 'unavailable',
211
+ reason: "the team's maps for the project now in use are still loading",
212
+ });
213
+ invalidated = false;
214
+ priming = null;
215
+ return primeNamespace(primedWith.home, primedWith.opts);
216
+ }
217
+ /** A masking call never waits longer than this on the confirming listing. */
218
+ export const CONFIRM_DEADLINE_MS = 3_000;
219
+ /** The confirmation in flight: calls arriving meanwhile share it. */
220
+ let confirming = null;
221
+ /**
222
+ * With VEILIO_PROJECT set, ask the server which project the value names NOW
223
+ * (one project listing) and compare its ID with the one the cache was read
224
+ * for. A different id - or a value that names nothing any more - drops the
225
+ * cache and waits for the reload, so the call that follows numbers from the
226
+ * right project. Without the variable, and before the first prime, it asks
227
+ * nothing: the stored choice is checked by `refreshNamespaceIfStale`.
228
+ *
229
+ * Run before a tool that numbers or restores from the team namespace
230
+ * (anonymize, restore), at most once per CONFIRM_TTL_MS, and once however many
231
+ * calls arrive together. The listing has a short deadline, and one that fails
232
+ * or times out backs off for the TTL like one that answered: Cloud being down
233
+ * is not a reason to stall masking, or to throw a good namespace away.
234
+ */
235
+ export function confirmProject() {
236
+ if (!primed || projectOverride(primedWith.opts.env) === null)
237
+ return Promise.resolve();
238
+ confirming ??= confirmOnce().finally(() => {
239
+ confirming = null;
240
+ });
241
+ return confirming;
242
+ }
243
+ async function confirmOnce() {
244
+ const { home, opts } = primedWith;
245
+ const value = projectOverride(opts.env);
246
+ if (value === null)
247
+ return;
248
+ if (priming && !settledFlag)
249
+ await priming;
250
+ // Trusted for CONFIRM_TTL_MS, on a clock a changed system time cannot move.
251
+ if (confirmedAt !== null && performance.now() - confirmedAt < CONFIRM_TTL_MS)
252
+ return;
253
+ const credential = readCredential(home);
254
+ if (!credential)
255
+ return;
256
+ const giveUp = new AbortController();
257
+ const timer = setTimeout(() => giveUp.abort(), CONFIRM_DEADLINE_MS);
258
+ let now;
259
+ try {
260
+ const scoped = await resolveOverride(credential, value, giveUp.signal);
261
+ now = scoped.ok ? (scoped.value.project ?? null) : null;
262
+ }
263
+ catch {
264
+ confirmedAt = performance.now();
265
+ return;
266
+ }
267
+ finally {
268
+ clearTimeout(timer);
269
+ }
270
+ const refusedAlready = current.found.status === 'refused';
271
+ if (now === null ? refusedAlready : now === primedProjectId) {
272
+ confirmedAt = performance.now();
273
+ return;
274
+ }
275
+ await reloadForAnotherProject();
276
+ }
110
277
  /** Test support and callers that can wait: the in-flight (or last) resolution. */
111
278
  export function namespaceSettled() {
112
279
  return priming ?? Promise.resolve(current);
@@ -124,6 +291,12 @@ export function resetNamespaceCache() {
124
291
  settledFlag = true;
125
292
  lastAttemptAt = 0;
126
293
  primedWith = { opts: {} };
294
+ primed = false;
295
+ primedProject = null;
296
+ primedProjectId = null;
297
+ confirmedAt = null;
298
+ invalidated = false;
299
+ primeGeneration++;
127
300
  }
128
301
  /**
129
302
  * The namespace line every anonymize result carries, with the reason when the
@@ -137,6 +310,8 @@ export function namespaceLine(resolved) {
137
310
  return 'Namespace: local (the team key is locked on this machine - run `veilio team unlock`)';
138
311
  if (found.status === 'unavailable')
139
312
  return `Namespace: local (could not read the team's maps: ${found.reason})`;
313
+ if (found.status === 'refused')
314
+ return `Namespace: none (${found.refusal.message})`;
140
315
  return 'Namespace: local';
141
316
  }
142
317
  //# sourceMappingURL=namespace.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"namespace.js","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,iFAAiF;AACjF,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,8EAA8E;AAC9E,iEAAiE;AACjE,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,+EAA+E;AAC/E,6EA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CAAA;AAC5C,CAAC;AAED;;4EAE4E;AAC5E,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,mBAAmB;IACjC,OAAO,GAAG,KAAK,CAAA;IACf,OAAO,GAAG,IAAI,CAAA;IACd,WAAW,GAAG,IAAI,CAAA;IAClB,aAAa,GAAG,CAAC,CAAA;IACjB,UAAU,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;IACzB,MAAM,GAAG,KAAK,CAAA;IACd,aAAa,GAAG,IAAI,CAAA;IACpB,eAAe,GAAG,IAAI,CAAA;IACtB,WAAW,GAAG,IAAI,CAAA;IAClB,WAAW,GAAG,KAAK,CAAA;IACnB,eAAe,EAAE,CAAA;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAA2B;IACvD,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,iBAAiB,CAAA;IACxD,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAA;IAC1B,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ;QAC3B,OAAO,sFAAsF,CAAA;IAC/F,IAAI,KAAK,CAAC,MAAM,KAAK,aAAa;QAChC,OAAO,qDAAqD,KAAK,CAAC,MAAM,GAAG,CAAA;IAC7E,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,oBAAoB,KAAK,CAAC,OAAO,CAAC,OAAO,GAAG,CAAA;IACnF,OAAO,kBAAkB,CAAA;AAC3B,CAAC"}
package/dist/server.d.ts CHANGED
@@ -23,15 +23,37 @@ export interface JsonRpcResponse {
23
23
  /** Handle one parsed message. Returns null for notifications, which by spec
24
24
  * MUST NOT be answered. */
25
25
  export declare function handleMessage(message: unknown, ctx: ToolContext): JsonRpcResponse | null;
26
- /** Parse and handle one newline-delimited frame. */
26
+ /**
27
+ * Handle one message, the Cloud tools included (spec 052).
28
+ *
29
+ * `handleMessage` stays synchronous for everything it always answered: the
30
+ * offline tools never wait on anything, and making them return a Promise would
31
+ * thread one through every caller for a network call they never make. A call
32
+ * to a Cloud tool is the one thing that needs the network, so it alone answers
33
+ * with a Promise. JSON-RPC matches answers to requests by id, so a slow Cloud
34
+ * call finishing after a later offline one is in order.
35
+ */
36
+ export declare function respond(message: unknown, ctx: ToolContext): JsonRpcResponse | null | Promise<JsonRpcResponse>;
37
+ /** Parse and handle one newline-delimited frame. Synchronous: the offline
38
+ * path, as it always was. The stdio reader uses `respondToFrame`. */
27
39
  export declare function handleFrame(line: string, ctx: ToolContext): JsonRpcResponse | null;
40
+ /** One frame, the Cloud tools included. */
41
+ export declare function respondToFrame(line: string, ctx: ToolContext): JsonRpcResponse | null | Promise<JsonRpcResponse>;
28
42
  /** Accumulates stdin chunks and emits one response per complete line. Kept
29
43
  * separate from process wiring so it can be driven directly in tests. */
30
44
  export declare class FrameReader {
31
45
  private readonly ctx;
32
46
  private readonly send;
33
47
  private buffer;
48
+ /** Cloud answers still on their way. */
49
+ private pending;
34
50
  constructor(ctx: ToolContext, send: (response: JsonRpcResponse) => void);
35
51
  push(chunk: string): void;
52
+ /**
53
+ * Wait for every Cloud answer still on its way. Called when stdin closes:
54
+ * exiting at once would drop a result - and abort a write mid-request, so
55
+ * nobody could say whether a map was updated or removed (code review).
56
+ */
57
+ drain(): Promise<void>;
36
58
  }
37
59
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AASA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAI9D,eAAO,MAAM,cAAc,EAAE,MAEpB,CAAA;AAET;;4CAE4C;AAC5C,eAAO,MAAM,2BAA2B,UAA6C,CAAA;AAGrF,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA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;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
package/dist/server.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // ~150 lines of message plumbing.
7
7
  import { createRequire } from 'node:module';
8
8
  import { PRODUCT_NAME } from '@veilio-inc/engine';
9
- import { callTool, TOOLS } from './tools.js';
9
+ import { callTool, callToolAsync, isCloudTool, listTools } from './tools.js';
10
10
  // Read from the package, not typed here - told to every MCP client, and a
11
11
  // literal drifted from what npm published (found 2026-09-26).
12
12
  export const SERVER_VERSION = createRequire(import.meta.url)('../package.json').version;
@@ -47,7 +47,8 @@ export function handleMessage(message, ctx) {
47
47
  : LATEST_PROTOCOL_VERSION;
48
48
  return ok(id, {
49
49
  protocolVersion,
50
- capabilities: { tools: { listChanged: false } },
50
+ // The list follows the sign-in (spec 052 FR-023): see sign-in-watch.ts.
51
+ capabilities: { tools: { listChanged: true } },
51
52
  serverInfo: { name: `${PRODUCT_NAME} MCP`, version: SERVER_VERSION },
52
53
  instructions: `Use anonymize_file before reasoning about proprietary source: it reads the file ` +
53
54
  `itself and returns only masked code, so real identifiers never enter your context. ` +
@@ -61,7 +62,7 @@ export function handleMessage(message, ctx) {
61
62
  return ok(id, {});
62
63
  case 'tools/list':
63
64
  return ok(id, {
64
- tools: TOOLS.map((t) => ({
65
+ tools: listTools(ctx).map((t) => ({
65
66
  name: t.name,
66
67
  title: t.title,
67
68
  description: t.description,
@@ -86,7 +87,38 @@ export function handleMessage(message, ctx) {
86
87
  return fail(id, METHOD_NOT_FOUND, `unknown method "${req.method}"`);
87
88
  }
88
89
  }
89
- /** Parse and handle one newline-delimited frame. */
90
+ /**
91
+ * Handle one message, the Cloud tools included (spec 052).
92
+ *
93
+ * `handleMessage` stays synchronous for everything it always answered: the
94
+ * offline tools never wait on anything, and making them return a Promise would
95
+ * thread one through every caller for a network call they never make. A call
96
+ * to a Cloud tool is the one thing that needs the network, so it alone answers
97
+ * with a Promise. JSON-RPC matches answers to requests by id, so a slow Cloud
98
+ * call finishing after a later offline one is in order.
99
+ */
100
+ export function respond(message, ctx) {
101
+ if (typeof message === 'object' && message !== null && !Array.isArray(message)) {
102
+ const req = message;
103
+ const params = req.params ?? {};
104
+ if (req.method === 'tools/call' &&
105
+ typeof params.name === 'string' &&
106
+ isCloudTool(params.name, ctx)) {
107
+ const rawArgs = params.arguments;
108
+ const args = typeof rawArgs === 'object' && rawArgs !== null && !Array.isArray(rawArgs)
109
+ ? rawArgs
110
+ : {};
111
+ const id = req.id ?? null;
112
+ return callToolAsync(params.name, args, ctx).then((result) => ok(id, {
113
+ content: [{ type: 'text', text: result.text }],
114
+ isError: result.isError === true,
115
+ }));
116
+ }
117
+ }
118
+ return handleMessage(message, ctx);
119
+ }
120
+ /** Parse and handle one newline-delimited frame. Synchronous: the offline
121
+ * path, as it always was. The stdio reader uses `respondToFrame`. */
90
122
  export function handleFrame(line, ctx) {
91
123
  let parsed;
92
124
  try {
@@ -97,12 +129,25 @@ export function handleFrame(line, ctx) {
97
129
  }
98
130
  return handleMessage(parsed, ctx);
99
131
  }
132
+ /** One frame, the Cloud tools included. */
133
+ export function respondToFrame(line, ctx) {
134
+ let parsed;
135
+ try {
136
+ parsed = JSON.parse(line);
137
+ }
138
+ catch {
139
+ return fail(null, PARSE_ERROR, 'invalid JSON');
140
+ }
141
+ return respond(parsed, ctx);
142
+ }
100
143
  /** Accumulates stdin chunks and emits one response per complete line. Kept
101
144
  * separate from process wiring so it can be driven directly in tests. */
102
145
  export class FrameReader {
103
146
  ctx;
104
147
  send;
105
148
  buffer = '';
149
+ /** Cloud answers still on their way. */
150
+ pending = new Set();
106
151
  constructor(ctx, send) {
107
152
  this.ctx = ctx;
108
153
  this.send = send;
@@ -115,10 +160,24 @@ export class FrameReader {
115
160
  this.buffer = this.buffer.slice(index + 1);
116
161
  if (line.length === 0)
117
162
  continue;
118
- const response = handleFrame(line, this.ctx);
119
- if (response !== null)
163
+ const response = respondToFrame(line, this.ctx);
164
+ if (response instanceof Promise) {
165
+ const sending = response.then((r) => this.send(r));
166
+ this.pending.add(sending);
167
+ void sending.finally(() => this.pending.delete(sending));
168
+ }
169
+ else if (response !== null)
120
170
  this.send(response);
121
171
  }
122
172
  }
173
+ /**
174
+ * Wait for every Cloud answer still on its way. Called when stdin closes:
175
+ * exiting at once would drop a result - and abort a write mid-request, so
176
+ * nobody could say whether a map was updated or removed (code review).
177
+ */
178
+ async drain() {
179
+ while (this.pending.size > 0)
180
+ await Promise.allSettled([...this.pending]);
181
+ }
123
182
  }
124
183
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAoB,MAAM,YAAY,CAAA;AAE9D,0EAA0E;AAC1E,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GACzB,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CACjD,CAAC,OAAO,CAAA;AAET;;4CAE4C;AAC5C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAA;AACrF,MAAM,uBAAuB,GAAG,2BAA2B,CAAC,CAAC,CAAC,CAAA;AAgB9D,iCAAiC;AACjC,MAAM,WAAW,GAAG,CAAC,KAAK,CAAA;AAC1B,MAAM,eAAe,GAAG,CAAC,KAAK,CAAA;AAC9B,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAA;AAE/B,SAAS,EAAE,CAAC,EAA0B,EAAE,MAAe;IACrD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,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AC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAA;YAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;YAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAQ;YAC/B,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;YAC/C,IAAI,QAAQ,YAAY,OAAO,EAAE,CAAC;gBAChC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBAClD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACzB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;YAC1D,CAAC;iBAAM,IAAI,QAAQ,KAAK,IAAI;gBAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC;YAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IAC3E,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ /** The notification MCP defines for a changed tool list. No id: not a request. */
2
+ export declare const TOOLS_LIST_CHANGED: {
3
+ readonly jsonrpc: "2.0";
4
+ readonly method: "notifications/tools/list_changed";
5
+ };
6
+ export declare const SIGN_IN_POLL_MS = 2000;
7
+ export declare class SignInWatcher {
8
+ private readonly home;
9
+ private readonly notify;
10
+ private signedIn;
11
+ constructor(home: string | undefined, notify: () => void);
12
+ /** Whether the sign-in changed since the last check; notifies once if so. */
13
+ check(): boolean;
14
+ }
15
+ //# sourceMappingURL=sign-in-watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-watch.d.ts","sourceRoot":"","sources":["../src/sign-in-watch.ts"],"names":[],"mappings":"AAcA,kFAAkF;AAClF,eAAO,MAAM,kBAAkB;;;CAGrB,CAAA;AAEV,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAS;gBAGN,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,MAAM,EAAE,MAAM,IAAI;IAKrC,6EAA6E;IAC7E,KAAK,IAAI,OAAO;CAOjB"}
@@ -0,0 +1,38 @@
1
+ // Signing in or out while the server runs changes its tool list (spec 052
2
+ // FR-023): the map, team and project tools exist only for a signed-in person.
3
+ // The server declares `listChanged: true` and, when the credential file
4
+ // appears or disappears, sends `notifications/tools/list_changed`. Without it,
5
+ // a client that read the list once at start would never offer the map tools
6
+ // after `veilio login`, and would go on offering them after `veilio logout`.
7
+ //
8
+ // Polled rather than `fs.watch`-ed. The file is replaced and removed whole, a
9
+ // watch on a file that does not exist yet needs a watch on its directory, and
10
+ // both behave differently across platforms. A local read every two seconds is
11
+ // cheap and the same everywhere.
12
+ import { readCredential } from '@veilio-inc/cli/credential';
13
+ /** The notification MCP defines for a changed tool list. No id: not a request. */
14
+ export const TOOLS_LIST_CHANGED = {
15
+ jsonrpc: '2.0',
16
+ method: 'notifications/tools/list_changed',
17
+ };
18
+ export const SIGN_IN_POLL_MS = 2000;
19
+ export class SignInWatcher {
20
+ home;
21
+ notify;
22
+ signedIn;
23
+ constructor(home, notify) {
24
+ this.home = home;
25
+ this.notify = notify;
26
+ this.signedIn = readCredential(home) !== null;
27
+ }
28
+ /** Whether the sign-in changed since the last check; notifies once if so. */
29
+ check() {
30
+ const now = readCredential(this.home) !== null;
31
+ if (now === this.signedIn)
32
+ return false;
33
+ this.signedIn = now;
34
+ this.notify();
35
+ return true;
36
+ }
37
+ }
38
+ //# sourceMappingURL=sign-in-watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-watch.js","sourceRoot":"","sources":["../src/sign-in-watch.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,wEAAwE;AACxE,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,iCAAiC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,kCAAkC;CAClC,CAAA;AAEV,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAA;AAEnC,MAAM,OAAO,aAAa;IAIL;IACA;IAJX,QAAQ,CAAS;IAEzB,YACmB,IAAwB,EACxB,MAAkB;QADlB,SAAI,GAAJ,IAAI,CAAoB;QACxB,WAAM,GAAN,MAAM,CAAY;QAEnC,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;IAC/C,CAAC;IAED,6EAA6E;IAC7E,KAAK;QACH,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;QAC9C,IAAI,GAAG,KAAK,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAA;QACnB,IAAI,CAAC,MAAM,EAAE,CAAA;QACb,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
package/dist/tools.d.ts CHANGED
@@ -1,8 +1,26 @@
1
+ import './identity.js';
2
+ import { CLOUD_TOOLS, type CloudToolDefinition } from './cloud-tools.js';
3
+ export { CLOUD_TOOLS };
1
4
  export interface ToolContext {
2
5
  /** Root the server is allowed to read from. */
3
6
  cwd: string;
4
7
  /** Override for the symbol-map location; null uses the project store. */
5
8
  mapPath: string | null;
9
+ /** Home the sign-in and unlocked keys are read from. Undefined: the real
10
+ * one. Injectable so tests never read a developer's ~/.veilio. */
11
+ home?: string;
12
+ /**
13
+ * Removing maps and updates that drop entries allowed (spec 052 FR-010).
14
+ * Set ONLY from VEILIO_MCP_DESTRUCTIVE=1 when the server starts - the
15
+ * person's choice, never a tool argument's.
16
+ */
17
+ destructive?: boolean;
18
+ /**
19
+ * The server's environment, for VEILIO_PROJECT (spec 052 FR-012a): set in a
20
+ * repository's `.mcp.json` `env`, it pins that repository's project for
21
+ * every tool call. Undefined: this process's environment.
22
+ */
23
+ env?: Readonly<Record<string, string | undefined>>;
6
24
  }
7
25
  export interface ToolResult {
8
26
  text: string;
@@ -21,4 +39,25 @@ export declare const TOOLS_BY_NAME: Map<string, ToolDefinition>;
21
39
  * protocol-level fault — MCP clients surface tool errors to the model so it can
22
40
  * correct itself, whereas a JSON-RPC error usually aborts the call. */
23
41
  export declare function callTool(name: string, args: Record<string, unknown>, ctx: ToolContext): ToolResult;
42
+ /**
43
+ * The tools this server offers right now (spec 052 FR-023).
44
+ *
45
+ * Signed out - always, in the Community Edition - exactly the five offline
46
+ * tools, as before: an agent shown map tools it can never use would keep
47
+ * reaching for them. Signed in, the map, team and project tools too. Asked on
48
+ * every `tools/list`, from the credential file, so signing in or out while the
49
+ * server runs is picked up without a restart.
50
+ */
51
+ export declare function listTools(ctx: ToolContext): (ToolDefinition | CloudToolDefinition)[];
52
+ /**
53
+ * Run any tool, the Cloud ones included, which need the network and so answer
54
+ * asynchronously. The offline five run exactly as `callTool` runs them.
55
+ *
56
+ * A Cloud tool called with nobody signed in - listed by an older client, or
57
+ * named from memory - answers with the sign-in sentence and sends nothing.
58
+ */
59
+ export declare function callToolAsync(name: string, args: Record<string, unknown>, ctx: ToolContext): Promise<ToolResult>;
60
+ /** Whether a call answers asynchronously: a Cloud tool, or a masking tool
61
+ * that first confirms the project the variable names. */
62
+ export declare function isCloudTool(name: string, ctx?: ToolContext): boolean;
24
63
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAuDA,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAA;IACX,yEAAyE;IACzE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,UAAU,CAAA;CACzE;AAoQD,eAAO,MAAM,KAAK,EAAE,cAAc,EAwMjC,CAAA;AAED,eAAO,MAAM,aAAa,6BAAyC,CAAA;AAEnE;;wEAEwE;AACxE,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,WAAW,GACf,UAAU,CASZ"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAmBA,OAAO,eAAe,CAAA;AA8Ct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