@veilio-inc/mcp 0.5.1 → 0.6.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/README.md +34 -0
- package/dist/cloud-tools.d.ts +18 -0
- package/dist/cloud-tools.d.ts.map +1 -0
- package/dist/cloud-tools.js +296 -0
- package/dist/cloud-tools.js.map +1 -0
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +14 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/namespace.d.ts +8 -1
- package/dist/namespace.d.ts.map +1 -1
- package/dist/namespace.js +70 -6
- package/dist/namespace.js.map +1 -1
- package/dist/server.d.ts +23 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +65 -6
- package/dist/server.js.map +1 -1
- package/dist/sign-in-watch.d.ts +15 -0
- package/dist/sign-in-watch.d.ts.map +1 -0
- package/dist/sign-in-watch.js +38 -0
- package/dist/sign-in-watch.js.map +1 -0
- package/dist/tools.d.ts +32 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +70 -5
- package/dist/tools.js.map +1 -1
- package/package.json +4 -4
package/dist/namespace.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
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';
|
|
@@ -62,21 +64,51 @@ async function fetchNamespace(home, opts) {
|
|
|
62
64
|
*/
|
|
63
65
|
export function primeNamespace(home, opts = {}) {
|
|
64
66
|
primedWith = { home, opts };
|
|
67
|
+
primed = true;
|
|
65
68
|
lastAttemptAt = Date.now();
|
|
66
69
|
if (!priming) {
|
|
70
|
+
// The project is read when the fetch STARTS, and the fetch is for that
|
|
71
|
+
// project only. Its answer is kept only if it is still the newest fetch
|
|
72
|
+
// and the credential still names that project: a prime that finishes
|
|
73
|
+
// after the project changed holds the OLD project's maps, and assigning
|
|
74
|
+
// it would put that project's placeholders into this one's work - the
|
|
75
|
+
// cross-project leak FR-013 forbids (security review).
|
|
76
|
+
const project = readCredential(home)?.project ?? null;
|
|
77
|
+
const generation = ++primeGeneration;
|
|
78
|
+
primedProject = project;
|
|
79
|
+
settledFlag = false;
|
|
67
80
|
priming = fetchNamespace(home, { deadlineMs: STARTUP_DEADLINE_MS, ...opts }).then((resolved) => {
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
const still = (readCredential(home)?.project ?? null) === project;
|
|
82
|
+
if (generation === primeGeneration && still) {
|
|
83
|
+
current = resolved;
|
|
84
|
+
settledFlag = true;
|
|
85
|
+
}
|
|
86
|
+
return current;
|
|
70
87
|
});
|
|
71
88
|
}
|
|
72
89
|
return priming;
|
|
73
90
|
}
|
|
91
|
+
/** Which fetch is the newest; an older one's answer is discarded. */
|
|
92
|
+
let primeGeneration = 0;
|
|
74
93
|
/** A hung instance must not hold the agent's first tool call for 30 s. */
|
|
75
94
|
const STARTUP_DEADLINE_MS = 10_000;
|
|
76
95
|
/** How often an 'unavailable' team is asked again, from a tool call. */
|
|
77
96
|
const UNAVAILABLE_RECHECK_MS = 30_000;
|
|
78
97
|
let primedWith = { opts: {} };
|
|
79
98
|
let lastAttemptAt = 0;
|
|
99
|
+
let primed = false;
|
|
100
|
+
/** The project the cached namespace is for (spec 052 FR-013). */
|
|
101
|
+
let primedProject = null;
|
|
102
|
+
/** Set by a team write through this server: the cache no longer matches. */
|
|
103
|
+
let invalidated = false;
|
|
104
|
+
/**
|
|
105
|
+
* The team's maps just changed through this server - a team map created,
|
|
106
|
+
* updated or removed, or another project chosen - so the cached namespace is
|
|
107
|
+
* out of date. The next tool call starts loading it again.
|
|
108
|
+
*/
|
|
109
|
+
export function invalidateNamespace() {
|
|
110
|
+
invalidated = true;
|
|
111
|
+
}
|
|
80
112
|
/**
|
|
81
113
|
* The cache must not outlive the reason it was cached (review): `veilio team
|
|
82
114
|
* unlock` run after this server started said "restore again" and every retry
|
|
@@ -86,6 +118,37 @@ let lastAttemptAt = 0;
|
|
|
86
118
|
* sees the result. A settled `team` or `local` is kept for the process.
|
|
87
119
|
*/
|
|
88
120
|
export function refreshNamespaceIfStale() {
|
|
121
|
+
// Another project chosen - by `veilio projects use` in a terminal while this
|
|
122
|
+
// server runs, or by projects_use here - or a team write made here: the
|
|
123
|
+
// namespace cached for the old state must not go on numbering the new one
|
|
124
|
+
// (spec 052 edge case: the next call uses the new state).
|
|
125
|
+
if (primed) {
|
|
126
|
+
// Checked FIRST, whatever is in flight: a fetch already running is for the
|
|
127
|
+
// project it started with, and is dropped (security review).
|
|
128
|
+
const project = readCredential(primedWith.home)?.project ?? null;
|
|
129
|
+
if (project !== primedProject) {
|
|
130
|
+
// The cached namespace is the OLD project's, and numbering with it -
|
|
131
|
+
// even for the one call that noticed - would put that project's
|
|
132
|
+
// placeholders into this one's store (FR-013). Until the new project's
|
|
133
|
+
// maps load there is no team namespace, and that is said.
|
|
134
|
+
current = localFrom({
|
|
135
|
+
status: 'unavailable',
|
|
136
|
+
reason: "the team's maps for the project now in use are still loading",
|
|
137
|
+
});
|
|
138
|
+
invalidated = false;
|
|
139
|
+
priming = null;
|
|
140
|
+
void primeNamespace(primedWith.home, primedWith.opts);
|
|
141
|
+
return 'changed';
|
|
142
|
+
}
|
|
143
|
+
// The same project, changed by a write made here: reload when nothing is
|
|
144
|
+
// already loading, keeping the current (same-project) namespace meanwhile.
|
|
145
|
+
if (invalidated && (!priming || settledFlag)) {
|
|
146
|
+
invalidated = false;
|
|
147
|
+
priming = null;
|
|
148
|
+
void primeNamespace(primedWith.home, primedWith.opts);
|
|
149
|
+
return 'changed';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
89
152
|
const status = current.found.status;
|
|
90
153
|
if (status !== 'locked' && status !== 'unavailable')
|
|
91
154
|
return null;
|
|
@@ -100,10 +163,7 @@ export function refreshNamespaceIfStale() {
|
|
|
100
163
|
if (!due)
|
|
101
164
|
return null;
|
|
102
165
|
priming = null;
|
|
103
|
-
|
|
104
|
-
void primeNamespace(primedWith.home, primedWith.opts).then(() => {
|
|
105
|
-
settledFlag = true;
|
|
106
|
-
});
|
|
166
|
+
void primeNamespace(primedWith.home, primedWith.opts);
|
|
107
167
|
return status === 'locked' ? 'unlocked' : 'retrying';
|
|
108
168
|
}
|
|
109
169
|
let settledFlag = true;
|
|
@@ -124,6 +184,10 @@ export function resetNamespaceCache() {
|
|
|
124
184
|
settledFlag = true;
|
|
125
185
|
lastAttemptAt = 0;
|
|
126
186
|
primedWith = { opts: {} };
|
|
187
|
+
primed = false;
|
|
188
|
+
primedProject = null;
|
|
189
|
+
invalidated = false;
|
|
190
|
+
primeGeneration++;
|
|
127
191
|
}
|
|
128
192
|
/**
|
|
129
193
|
* The namespace line every anonymize result carries, with the reason when the
|
package/dist/namespace.js.map
CHANGED
|
@@ -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,6EAA6E;AAC7E,wEAAwE;AACxE,+EAA+E;AAC/E,4BAA4B;AAE5B,OAAO,EAAE,oBAAoB,EAA4B,MAAM,gCAAgC,CAAA;AAC/F,OAAO,EAAE,cAAc,EAAE,MAA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,CAAA;IACpB,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,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
|
-
/**
|
|
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
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AASA,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAI9F,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;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,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equire } from 'node:module';
|
|
8
8
|
import { PRODUCT_NAME } from '@veilio-inc/engine';
|
|
9
|
-
import { callTool,
|
|
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
|
-
|
|
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:
|
|
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
|
-
/**
|
|
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)) {
|
|
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 =
|
|
119
|
-
if (response
|
|
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
|
package/dist/server.js.map
CHANGED
|
@@ -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;AACj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G,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,20 @@
|
|
|
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;
|
|
6
18
|
}
|
|
7
19
|
export interface ToolResult {
|
|
8
20
|
text: string;
|
|
@@ -21,4 +33,24 @@ export declare const TOOLS_BY_NAME: Map<string, ToolDefinition>;
|
|
|
21
33
|
* protocol-level fault — MCP clients surface tool errors to the model so it can
|
|
22
34
|
* correct itself, whereas a JSON-RPC error usually aborts the call. */
|
|
23
35
|
export declare function callTool(name: string, args: Record<string, unknown>, ctx: ToolContext): ToolResult;
|
|
36
|
+
/**
|
|
37
|
+
* The tools this server offers right now (spec 052 FR-023).
|
|
38
|
+
*
|
|
39
|
+
* Signed out - always, in the Community Edition - exactly the five offline
|
|
40
|
+
* tools, as before: an agent shown map tools it can never use would keep
|
|
41
|
+
* reaching for them. Signed in, the map, team and project tools too. Asked on
|
|
42
|
+
* every `tools/list`, from the credential file, so signing in or out while the
|
|
43
|
+
* server runs is picked up without a restart.
|
|
44
|
+
*/
|
|
45
|
+
export declare function listTools(ctx: ToolContext): (ToolDefinition | CloudToolDefinition)[];
|
|
46
|
+
/**
|
|
47
|
+
* Run any tool, the Cloud ones included, which need the network and so answer
|
|
48
|
+
* asynchronously. The offline five run exactly as `callTool` runs them.
|
|
49
|
+
*
|
|
50
|
+
* A Cloud tool called with nobody signed in - listed by an older client, or
|
|
51
|
+
* named from memory - answers with the sign-in sentence and sends nothing.
|
|
52
|
+
*/
|
|
53
|
+
export declare function callToolAsync(name: string, args: Record<string, unknown>, ctx: ToolContext): Promise<ToolResult>;
|
|
54
|
+
/** Whether a call goes to a Cloud tool, and so answers asynchronously. */
|
|
55
|
+
export declare function isCloudTool(name: string): boolean;
|
|
24
56
|
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAmBA,OAAO,eAAe,CAAA;AAyCtB,OAAO,EAEL,WAAW,EAGX,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAA;IACX,yEAAyE;IACzE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB;uEACmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;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;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,CAAC,cAAc,GAAG,mBAAmB,CAAC,EAAE,CAEpF;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,UAAU,CAAC,CAYrB;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD"}
|
package/dist/tools.js
CHANGED
|
@@ -15,21 +15,30 @@
|
|
|
15
15
|
// `anonymize_text` exists for the case where the agent legitimately already has
|
|
16
16
|
// the text (a user pasted it into chat). Its description says so plainly, so the
|
|
17
17
|
// model does not reach for it out of convenience and quietly defeat the purpose.
|
|
18
|
+
// First: every request this process makes is labelled as the MCP server's.
|
|
19
|
+
import './identity.js';
|
|
18
20
|
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
19
21
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
20
|
-
import { detectSecrets, isPlaceholder, restore, restoreLayers, disputedNote, locallyNumberedNote, summarizeSecrets, withAiPreamble, BIN_NAME, LANGUAGES, LANGUAGE_LABELS, PRODUCT_NAME, alteredNote, } from '@veilio-inc/engine';
|
|
22
|
+
import { detectSecrets, isPlaceholder, restore, restoreLayers, disputedNote, locallyNumberedNote, summarizeSecrets, withAiPreamble, BIN_NAME, LANGUAGES, LANGUAGE_LABELS, PRODUCT_NAME, alteredNote, keepRule, languageOfPath, } from '@veilio-inc/engine';
|
|
21
23
|
import { loadMap, resolveMapPath, saveMap } from '@veilio-inc/cli/store';
|
|
22
24
|
import { getNamespace, namespaceLine, refreshNamespaceIfStale } from './namespace.js';
|
|
23
25
|
import { teamLayerNote } from '@veilio-inc/cli/team-namespace';
|
|
24
26
|
import { anonymizeOverTeam } from '@veilio-inc/cli/team-anonymize';
|
|
25
27
|
/** Said when a tool call has just started reloading the team's maps. */
|
|
26
28
|
function loadingNote(why) {
|
|
29
|
+
if (why === 'changed')
|
|
30
|
+
return "Note: the team's maps changed (a team map written, or another project chosen) - loading them now; call again in a moment to use them.";
|
|
27
31
|
return why === 'unlocked'
|
|
28
32
|
? "Note: the team key was unlocked - loading the team's maps now; call again in a moment to use them."
|
|
29
33
|
: "Note: asking Cloud for the team's maps again; call again in a moment to use them.";
|
|
30
34
|
}
|
|
31
35
|
import { getRules } from './rules.js';
|
|
32
36
|
import { describeAge } from '@veilio-inc/cli/rules';
|
|
37
|
+
import { thirdPartyNames } from '@veilio-inc/cli/third-party';
|
|
38
|
+
import { readCredential } from '@veilio-inc/cli/credential';
|
|
39
|
+
import { refusal } from '@veilio-inc/cli/client';
|
|
40
|
+
import { ArgumentError, CLOUD_TOOLS, CLOUD_TOOLS_BY_NAME, refusalResult, } from './cloud-tools.js';
|
|
41
|
+
export { CLOUD_TOOLS };
|
|
33
42
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
34
43
|
class ToolError extends Error {
|
|
35
44
|
}
|
|
@@ -189,13 +198,27 @@ const LANGUAGE_PROP = {
|
|
|
189
198
|
enum: LANGUAGE_ENUM,
|
|
190
199
|
description: `Source language. "auto" (default) detects it. Supported: ${LANGUAGES.map((l) => LANGUAGE_LABELS[l]).join(', ')}.`,
|
|
191
200
|
};
|
|
192
|
-
function runAnonymize(source, label, args, ctx
|
|
201
|
+
function runAnonymize(source, label, args, ctx,
|
|
202
|
+
/** The file's path, relative to the project root, when the input is a file. */
|
|
203
|
+
file) {
|
|
193
204
|
const mapPath = resolveMapPath(ctx.mapPath, ctx.cwd);
|
|
194
205
|
const localMap = loadMap(mapPath);
|
|
195
206
|
const refreshing = refreshNamespaceIfStale();
|
|
196
207
|
const resolved = getNamespace();
|
|
197
208
|
const { namespace, highest, conflicts } = resolved;
|
|
198
|
-
|
|
209
|
+
// A file is masked in its extension's language unless one is asked for, and
|
|
210
|
+
// keeps the names it takes from a public package as written - the rule
|
|
211
|
+
// `veilio scrub <file>` follows, from the same module, so the two give the
|
|
212
|
+
// same placeholders for the same file (spec 030 FR-005, spec 050 T033-T036).
|
|
213
|
+
// Inline text has no file and no project: nothing is proven third-party.
|
|
214
|
+
const asked = (str(args, 'language') ?? 'auto');
|
|
215
|
+
const language = asked !== 'auto' || !file ? asked : (languageOfPath(file) ?? 'auto');
|
|
216
|
+
const keep = file
|
|
217
|
+
? (() => {
|
|
218
|
+
const input = { name: file, text: source };
|
|
219
|
+
return thirdPartyNames([input], [localMap, namespace], ctx.cwd).get(input) ?? new Set();
|
|
220
|
+
})()
|
|
221
|
+
: new Set();
|
|
199
222
|
const rules = getRules();
|
|
200
223
|
// The same composition `veilio scrub` uses (spec 030): the team's maps over
|
|
201
224
|
// this project's, new names above both, and only the team entries the output
|
|
@@ -203,7 +226,10 @@ function runAnonymize(source, label, args, ctx) {
|
|
|
203
226
|
const { result, toPersist } = anonymizeOverTeam(source, localMap, { namespace, highest, conflicts }, {
|
|
204
227
|
language,
|
|
205
228
|
secrets: 'redact',
|
|
206
|
-
rules:
|
|
229
|
+
rules: [
|
|
230
|
+
...(rules.rules ?? []),
|
|
231
|
+
...keepRule(keep, 'veilio-scrub-third-party', 'veilio scrub: third-party names'),
|
|
232
|
+
],
|
|
207
233
|
});
|
|
208
234
|
saveMap(mapPath, toPersist);
|
|
209
235
|
const body = args.preamble === true ? withAiPreamble(result.anonymized, result.map) : result.anonymized;
|
|
@@ -276,7 +302,7 @@ export const TOOLS = [
|
|
|
276
302
|
catch {
|
|
277
303
|
throw new ToolError(`cannot read "${path}"`);
|
|
278
304
|
}
|
|
279
|
-
return runAnonymize(source, path, args, ctx);
|
|
305
|
+
return runAnonymize(source, path, args, ctx, path);
|
|
280
306
|
},
|
|
281
307
|
},
|
|
282
308
|
{
|
|
@@ -450,4 +476,43 @@ export function callTool(name, args, ctx) {
|
|
|
450
476
|
return { text: `${PRODUCT_NAME}: ${message}`, isError: true };
|
|
451
477
|
}
|
|
452
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* The tools this server offers right now (spec 052 FR-023).
|
|
481
|
+
*
|
|
482
|
+
* Signed out - always, in the Community Edition - exactly the five offline
|
|
483
|
+
* tools, as before: an agent shown map tools it can never use would keep
|
|
484
|
+
* reaching for them. Signed in, the map, team and project tools too. Asked on
|
|
485
|
+
* every `tools/list`, from the credential file, so signing in or out while the
|
|
486
|
+
* server runs is picked up without a restart.
|
|
487
|
+
*/
|
|
488
|
+
export function listTools(ctx) {
|
|
489
|
+
return readCredential(ctx.home) ? [...TOOLS, ...CLOUD_TOOLS] : TOOLS;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Run any tool, the Cloud ones included, which need the network and so answer
|
|
493
|
+
* asynchronously. The offline five run exactly as `callTool` runs them.
|
|
494
|
+
*
|
|
495
|
+
* A Cloud tool called with nobody signed in - listed by an older client, or
|
|
496
|
+
* named from memory - answers with the sign-in sentence and sends nothing.
|
|
497
|
+
*/
|
|
498
|
+
export async function callToolAsync(name, args, ctx) {
|
|
499
|
+
const cloud = CLOUD_TOOLS_BY_NAME.get(name);
|
|
500
|
+
if (!cloud)
|
|
501
|
+
return callTool(name, args, ctx);
|
|
502
|
+
if (!readCredential(ctx.home))
|
|
503
|
+
return refusalResult(refusal('not_signed_in'));
|
|
504
|
+
try {
|
|
505
|
+
return await cloud.handler(args, ctx);
|
|
506
|
+
}
|
|
507
|
+
catch (err) {
|
|
508
|
+
if (err instanceof ArgumentError)
|
|
509
|
+
return { text: `${PRODUCT_NAME}: ${err.message}`, isError: true };
|
|
510
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
511
|
+
return { text: `${PRODUCT_NAME}: ${message}`, isError: true };
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/** Whether a call goes to a Cloud tool, and so answers asynchronously. */
|
|
515
|
+
export function isCloudTool(name) {
|
|
516
|
+
return CLOUD_TOOLS_BY_NAME.has(name);
|
|
517
|
+
}
|
|
453
518
|
//# sourceMappingURL=tools.js.map
|