contextwise 0.1.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/LICENSE +21 -0
- package/README.md +333 -0
- package/bin/contextwise.js +17 -0
- package/dist/chunk-P7JW7EPW.js +4383 -0
- package/dist/chunk-P7JW7EPW.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +1116 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1435 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1435 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
|
|
5
|
+
declare const StdioUpstreamConfigSchema: z.ZodObject<{
|
|
6
|
+
command: z.ZodString;
|
|
7
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
9
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
10
|
+
autoRestart: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
command: string;
|
|
13
|
+
args: string[];
|
|
14
|
+
env: Record<string, string>;
|
|
15
|
+
autoRestart: boolean;
|
|
16
|
+
cwd?: string | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
command: string;
|
|
19
|
+
args?: string[] | undefined;
|
|
20
|
+
env?: Record<string, string> | undefined;
|
|
21
|
+
cwd?: string | undefined;
|
|
22
|
+
autoRestart?: boolean | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
declare const HttpUpstreamConfigSchema: z.ZodObject<{
|
|
25
|
+
url: z.ZodString;
|
|
26
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
27
|
+
transport: z.ZodDefault<z.ZodEnum<["streamable-http", "sse", "auto"]>>;
|
|
28
|
+
autoReconnect: z.ZodDefault<z.ZodBoolean>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
url: string;
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
transport: "streamable-http" | "sse" | "auto";
|
|
33
|
+
autoReconnect: boolean;
|
|
34
|
+
}, {
|
|
35
|
+
url: string;
|
|
36
|
+
headers?: Record<string, string> | undefined;
|
|
37
|
+
transport?: "streamable-http" | "sse" | "auto" | undefined;
|
|
38
|
+
autoReconnect?: boolean | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
declare const UpstreamServerConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
41
|
+
command: z.ZodString;
|
|
42
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
43
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
44
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
45
|
+
autoRestart: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
command: string;
|
|
48
|
+
args: string[];
|
|
49
|
+
env: Record<string, string>;
|
|
50
|
+
autoRestart: boolean;
|
|
51
|
+
cwd?: string | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
command: string;
|
|
54
|
+
args?: string[] | undefined;
|
|
55
|
+
env?: Record<string, string> | undefined;
|
|
56
|
+
cwd?: string | undefined;
|
|
57
|
+
autoRestart?: boolean | undefined;
|
|
58
|
+
}>, z.ZodObject<{
|
|
59
|
+
url: z.ZodString;
|
|
60
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
61
|
+
transport: z.ZodDefault<z.ZodEnum<["streamable-http", "sse", "auto"]>>;
|
|
62
|
+
autoReconnect: z.ZodDefault<z.ZodBoolean>;
|
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
|
64
|
+
url: string;
|
|
65
|
+
headers: Record<string, string>;
|
|
66
|
+
transport: "streamable-http" | "sse" | "auto";
|
|
67
|
+
autoReconnect: boolean;
|
|
68
|
+
}, {
|
|
69
|
+
url: string;
|
|
70
|
+
headers?: Record<string, string> | undefined;
|
|
71
|
+
transport?: "streamable-http" | "sse" | "auto" | undefined;
|
|
72
|
+
autoReconnect?: boolean | undefined;
|
|
73
|
+
}>]>;
|
|
74
|
+
declare function warnIfInsecureHttp(urlStr: string, headers?: Record<string, string>): void;
|
|
75
|
+
declare function isStdioUpstream(config: UpstreamServerConfig): config is z.infer<typeof StdioUpstreamConfigSchema>;
|
|
76
|
+
declare function isHttpUpstream(config: UpstreamServerConfig): config is z.infer<typeof HttpUpstreamConfigSchema>;
|
|
77
|
+
declare const ProxyConfigSchema: z.ZodObject<{
|
|
78
|
+
transport: z.ZodDefault<z.ZodEnum<["stdio", "sse", "http"]>>;
|
|
79
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
80
|
+
logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error", "silent"]>>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
transport: "sse" | "stdio" | "http";
|
|
83
|
+
port: number;
|
|
84
|
+
logLevel: "debug" | "info" | "warn" | "error" | "silent";
|
|
85
|
+
}, {
|
|
86
|
+
transport?: "sse" | "stdio" | "http" | undefined;
|
|
87
|
+
port?: number | undefined;
|
|
88
|
+
logLevel?: "debug" | "info" | "warn" | "error" | "silent" | undefined;
|
|
89
|
+
}>;
|
|
90
|
+
declare const RoutingConfigSchema: z.ZodObject<{
|
|
91
|
+
strategy: z.ZodDefault<z.ZodEnum<["hybrid", "bm25", "vector", "passthrough"]>>;
|
|
92
|
+
topK: z.ZodDefault<z.ZodNumber>;
|
|
93
|
+
similarityThreshold: z.ZodDefault<z.ZodNumber>;
|
|
94
|
+
pinnedTools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
95
|
+
maxActiveTools: z.ZodDefault<z.ZodNumber>;
|
|
96
|
+
enableBrowseServers: z.ZodDefault<z.ZodBoolean>;
|
|
97
|
+
enableAddServer: z.ZodDefault<z.ZodBoolean>;
|
|
98
|
+
allowCustomCommands: z.ZodDefault<z.ZodBoolean>;
|
|
99
|
+
persistAddedServers: z.ZodDefault<z.ZodBoolean>;
|
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
|
101
|
+
strategy: "passthrough" | "hybrid" | "bm25" | "vector";
|
|
102
|
+
topK: number;
|
|
103
|
+
similarityThreshold: number;
|
|
104
|
+
pinnedTools: string[];
|
|
105
|
+
maxActiveTools: number;
|
|
106
|
+
enableBrowseServers: boolean;
|
|
107
|
+
enableAddServer: boolean;
|
|
108
|
+
allowCustomCommands: boolean;
|
|
109
|
+
persistAddedServers: boolean;
|
|
110
|
+
}, {
|
|
111
|
+
strategy?: "passthrough" | "hybrid" | "bm25" | "vector" | undefined;
|
|
112
|
+
topK?: number | undefined;
|
|
113
|
+
similarityThreshold?: number | undefined;
|
|
114
|
+
pinnedTools?: string[] | undefined;
|
|
115
|
+
maxActiveTools?: number | undefined;
|
|
116
|
+
enableBrowseServers?: boolean | undefined;
|
|
117
|
+
enableAddServer?: boolean | undefined;
|
|
118
|
+
allowCustomCommands?: boolean | undefined;
|
|
119
|
+
persistAddedServers?: boolean | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
declare const GuardrailsConfigSchema: z.ZodObject<{
|
|
122
|
+
enableCache: z.ZodDefault<z.ZodBoolean>;
|
|
123
|
+
cacheTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
124
|
+
maxCallsPerMinute: z.ZodDefault<z.ZodNumber>;
|
|
125
|
+
loopBreakerThreshold: z.ZodDefault<z.ZodNumber>;
|
|
126
|
+
callTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
127
|
+
}, "strip", z.ZodTypeAny, {
|
|
128
|
+
enableCache: boolean;
|
|
129
|
+
cacheTtlSeconds: number;
|
|
130
|
+
maxCallsPerMinute: number;
|
|
131
|
+
loopBreakerThreshold: number;
|
|
132
|
+
callTimeoutMs: number;
|
|
133
|
+
}, {
|
|
134
|
+
enableCache?: boolean | undefined;
|
|
135
|
+
cacheTtlSeconds?: number | undefined;
|
|
136
|
+
maxCallsPerMinute?: number | undefined;
|
|
137
|
+
loopBreakerThreshold?: number | undefined;
|
|
138
|
+
callTimeoutMs?: number | undefined;
|
|
139
|
+
}>;
|
|
140
|
+
declare const ContextWiseConfigSchema: z.ZodObject<{
|
|
141
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
142
|
+
version: z.ZodDefault<z.ZodString>;
|
|
143
|
+
proxy: z.ZodDefault<z.ZodObject<{
|
|
144
|
+
transport: z.ZodDefault<z.ZodEnum<["stdio", "sse", "http"]>>;
|
|
145
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
146
|
+
logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error", "silent"]>>;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
transport: "sse" | "stdio" | "http";
|
|
149
|
+
port: number;
|
|
150
|
+
logLevel: "debug" | "info" | "warn" | "error" | "silent";
|
|
151
|
+
}, {
|
|
152
|
+
transport?: "sse" | "stdio" | "http" | undefined;
|
|
153
|
+
port?: number | undefined;
|
|
154
|
+
logLevel?: "debug" | "info" | "warn" | "error" | "silent" | undefined;
|
|
155
|
+
}>>;
|
|
156
|
+
routing: z.ZodDefault<z.ZodObject<{
|
|
157
|
+
strategy: z.ZodDefault<z.ZodEnum<["hybrid", "bm25", "vector", "passthrough"]>>;
|
|
158
|
+
topK: z.ZodDefault<z.ZodNumber>;
|
|
159
|
+
similarityThreshold: z.ZodDefault<z.ZodNumber>;
|
|
160
|
+
pinnedTools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
161
|
+
maxActiveTools: z.ZodDefault<z.ZodNumber>;
|
|
162
|
+
enableBrowseServers: z.ZodDefault<z.ZodBoolean>;
|
|
163
|
+
enableAddServer: z.ZodDefault<z.ZodBoolean>;
|
|
164
|
+
allowCustomCommands: z.ZodDefault<z.ZodBoolean>;
|
|
165
|
+
persistAddedServers: z.ZodDefault<z.ZodBoolean>;
|
|
166
|
+
}, "strip", z.ZodTypeAny, {
|
|
167
|
+
strategy: "passthrough" | "hybrid" | "bm25" | "vector";
|
|
168
|
+
topK: number;
|
|
169
|
+
similarityThreshold: number;
|
|
170
|
+
pinnedTools: string[];
|
|
171
|
+
maxActiveTools: number;
|
|
172
|
+
enableBrowseServers: boolean;
|
|
173
|
+
enableAddServer: boolean;
|
|
174
|
+
allowCustomCommands: boolean;
|
|
175
|
+
persistAddedServers: boolean;
|
|
176
|
+
}, {
|
|
177
|
+
strategy?: "passthrough" | "hybrid" | "bm25" | "vector" | undefined;
|
|
178
|
+
topK?: number | undefined;
|
|
179
|
+
similarityThreshold?: number | undefined;
|
|
180
|
+
pinnedTools?: string[] | undefined;
|
|
181
|
+
maxActiveTools?: number | undefined;
|
|
182
|
+
enableBrowseServers?: boolean | undefined;
|
|
183
|
+
enableAddServer?: boolean | undefined;
|
|
184
|
+
allowCustomCommands?: boolean | undefined;
|
|
185
|
+
persistAddedServers?: boolean | undefined;
|
|
186
|
+
}>>;
|
|
187
|
+
guardrails: z.ZodDefault<z.ZodObject<{
|
|
188
|
+
enableCache: z.ZodDefault<z.ZodBoolean>;
|
|
189
|
+
cacheTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
190
|
+
maxCallsPerMinute: z.ZodDefault<z.ZodNumber>;
|
|
191
|
+
loopBreakerThreshold: z.ZodDefault<z.ZodNumber>;
|
|
192
|
+
callTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
193
|
+
}, "strip", z.ZodTypeAny, {
|
|
194
|
+
enableCache: boolean;
|
|
195
|
+
cacheTtlSeconds: number;
|
|
196
|
+
maxCallsPerMinute: number;
|
|
197
|
+
loopBreakerThreshold: number;
|
|
198
|
+
callTimeoutMs: number;
|
|
199
|
+
}, {
|
|
200
|
+
enableCache?: boolean | undefined;
|
|
201
|
+
cacheTtlSeconds?: number | undefined;
|
|
202
|
+
maxCallsPerMinute?: number | undefined;
|
|
203
|
+
loopBreakerThreshold?: number | undefined;
|
|
204
|
+
callTimeoutMs?: number | undefined;
|
|
205
|
+
}>>;
|
|
206
|
+
upstreams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
207
|
+
command: z.ZodString;
|
|
208
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
209
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
210
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
211
|
+
autoRestart: z.ZodDefault<z.ZodBoolean>;
|
|
212
|
+
}, "strip", z.ZodTypeAny, {
|
|
213
|
+
command: string;
|
|
214
|
+
args: string[];
|
|
215
|
+
env: Record<string, string>;
|
|
216
|
+
autoRestart: boolean;
|
|
217
|
+
cwd?: string | undefined;
|
|
218
|
+
}, {
|
|
219
|
+
command: string;
|
|
220
|
+
args?: string[] | undefined;
|
|
221
|
+
env?: Record<string, string> | undefined;
|
|
222
|
+
cwd?: string | undefined;
|
|
223
|
+
autoRestart?: boolean | undefined;
|
|
224
|
+
}>, z.ZodObject<{
|
|
225
|
+
url: z.ZodString;
|
|
226
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
227
|
+
transport: z.ZodDefault<z.ZodEnum<["streamable-http", "sse", "auto"]>>;
|
|
228
|
+
autoReconnect: z.ZodDefault<z.ZodBoolean>;
|
|
229
|
+
}, "strip", z.ZodTypeAny, {
|
|
230
|
+
url: string;
|
|
231
|
+
headers: Record<string, string>;
|
|
232
|
+
transport: "streamable-http" | "sse" | "auto";
|
|
233
|
+
autoReconnect: boolean;
|
|
234
|
+
}, {
|
|
235
|
+
url: string;
|
|
236
|
+
headers?: Record<string, string> | undefined;
|
|
237
|
+
transport?: "streamable-http" | "sse" | "auto" | undefined;
|
|
238
|
+
autoReconnect?: boolean | undefined;
|
|
239
|
+
}>]>>>;
|
|
240
|
+
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
version: string;
|
|
242
|
+
proxy: {
|
|
243
|
+
transport: "sse" | "stdio" | "http";
|
|
244
|
+
port: number;
|
|
245
|
+
logLevel: "debug" | "info" | "warn" | "error" | "silent";
|
|
246
|
+
};
|
|
247
|
+
routing: {
|
|
248
|
+
strategy: "passthrough" | "hybrid" | "bm25" | "vector";
|
|
249
|
+
topK: number;
|
|
250
|
+
similarityThreshold: number;
|
|
251
|
+
pinnedTools: string[];
|
|
252
|
+
maxActiveTools: number;
|
|
253
|
+
enableBrowseServers: boolean;
|
|
254
|
+
enableAddServer: boolean;
|
|
255
|
+
allowCustomCommands: boolean;
|
|
256
|
+
persistAddedServers: boolean;
|
|
257
|
+
};
|
|
258
|
+
guardrails: {
|
|
259
|
+
enableCache: boolean;
|
|
260
|
+
cacheTtlSeconds: number;
|
|
261
|
+
maxCallsPerMinute: number;
|
|
262
|
+
loopBreakerThreshold: number;
|
|
263
|
+
callTimeoutMs: number;
|
|
264
|
+
};
|
|
265
|
+
upstreams: Record<string, {
|
|
266
|
+
command: string;
|
|
267
|
+
args: string[];
|
|
268
|
+
env: Record<string, string>;
|
|
269
|
+
autoRestart: boolean;
|
|
270
|
+
cwd?: string | undefined;
|
|
271
|
+
} | {
|
|
272
|
+
url: string;
|
|
273
|
+
headers: Record<string, string>;
|
|
274
|
+
transport: "streamable-http" | "sse" | "auto";
|
|
275
|
+
autoReconnect: boolean;
|
|
276
|
+
}>;
|
|
277
|
+
$schema?: string | undefined;
|
|
278
|
+
}, {
|
|
279
|
+
$schema?: string | undefined;
|
|
280
|
+
version?: string | undefined;
|
|
281
|
+
proxy?: {
|
|
282
|
+
transport?: "sse" | "stdio" | "http" | undefined;
|
|
283
|
+
port?: number | undefined;
|
|
284
|
+
logLevel?: "debug" | "info" | "warn" | "error" | "silent" | undefined;
|
|
285
|
+
} | undefined;
|
|
286
|
+
routing?: {
|
|
287
|
+
strategy?: "passthrough" | "hybrid" | "bm25" | "vector" | undefined;
|
|
288
|
+
topK?: number | undefined;
|
|
289
|
+
similarityThreshold?: number | undefined;
|
|
290
|
+
pinnedTools?: string[] | undefined;
|
|
291
|
+
maxActiveTools?: number | undefined;
|
|
292
|
+
enableBrowseServers?: boolean | undefined;
|
|
293
|
+
enableAddServer?: boolean | undefined;
|
|
294
|
+
allowCustomCommands?: boolean | undefined;
|
|
295
|
+
persistAddedServers?: boolean | undefined;
|
|
296
|
+
} | undefined;
|
|
297
|
+
guardrails?: {
|
|
298
|
+
enableCache?: boolean | undefined;
|
|
299
|
+
cacheTtlSeconds?: number | undefined;
|
|
300
|
+
maxCallsPerMinute?: number | undefined;
|
|
301
|
+
loopBreakerThreshold?: number | undefined;
|
|
302
|
+
callTimeoutMs?: number | undefined;
|
|
303
|
+
} | undefined;
|
|
304
|
+
upstreams?: Record<string, {
|
|
305
|
+
command: string;
|
|
306
|
+
args?: string[] | undefined;
|
|
307
|
+
env?: Record<string, string> | undefined;
|
|
308
|
+
cwd?: string | undefined;
|
|
309
|
+
autoRestart?: boolean | undefined;
|
|
310
|
+
} | {
|
|
311
|
+
url: string;
|
|
312
|
+
headers?: Record<string, string> | undefined;
|
|
313
|
+
transport?: "streamable-http" | "sse" | "auto" | undefined;
|
|
314
|
+
autoReconnect?: boolean | undefined;
|
|
315
|
+
}> | undefined;
|
|
316
|
+
}>;
|
|
317
|
+
type StdioUpstreamConfig = z.infer<typeof StdioUpstreamConfigSchema>;
|
|
318
|
+
type HttpUpstreamConfig = z.infer<typeof HttpUpstreamConfigSchema>;
|
|
319
|
+
type UpstreamServerConfig = z.infer<typeof UpstreamServerConfigSchema>;
|
|
320
|
+
type ProxyConfig = z.infer<typeof ProxyConfigSchema>;
|
|
321
|
+
type RoutingConfig = z.infer<typeof RoutingConfigSchema>;
|
|
322
|
+
type GuardrailsConfig = z.infer<typeof GuardrailsConfigSchema>;
|
|
323
|
+
type ContextWiseConfig = z.infer<typeof ContextWiseConfigSchema>;
|
|
324
|
+
|
|
325
|
+
interface LoadConfigOptions {
|
|
326
|
+
configPath?: string;
|
|
327
|
+
cwd?: string;
|
|
328
|
+
autoImport?: boolean;
|
|
329
|
+
}
|
|
330
|
+
declare class ConfigLoader {
|
|
331
|
+
/**
|
|
332
|
+
* Discovers and loads configuration from contextwise.json or imported client configs.
|
|
333
|
+
*/
|
|
334
|
+
static load(options?: LoadConfigOptions): ContextWiseConfig;
|
|
335
|
+
/**
|
|
336
|
+
* Parses and validates a JSON file against ContextWiseConfigSchema.
|
|
337
|
+
*/
|
|
338
|
+
static parseConfigFile(filePath: string): ContextWiseConfig;
|
|
339
|
+
/**
|
|
340
|
+
* Scans for Cursor and Claude Desktop configs to auto-import upstreams.
|
|
341
|
+
*/
|
|
342
|
+
static autoImportClientConfigs(cwd: string): ContextWiseConfig | null;
|
|
343
|
+
static getClaudeDesktopConfigPath(): string | null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
type ServerConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
347
|
+
interface NamespacedTool extends Tool {
|
|
348
|
+
/** Original name as reported by upstream server */
|
|
349
|
+
originalName: string;
|
|
350
|
+
/** Scoped name exposed to client: `${serverName}__${originalName}` or unchanged if unconflicted */
|
|
351
|
+
namespacedName: string;
|
|
352
|
+
/** Name of upstream server providing this tool */
|
|
353
|
+
serverName: string;
|
|
354
|
+
/** Inferred domain/category tags for routing */
|
|
355
|
+
tags?: string[];
|
|
356
|
+
/** Behavioral hints */
|
|
357
|
+
readOnlyHint?: boolean;
|
|
358
|
+
idempotentHint?: boolean;
|
|
359
|
+
destructiveHint?: boolean;
|
|
360
|
+
}
|
|
361
|
+
interface UpstreamServerStatus {
|
|
362
|
+
name: string;
|
|
363
|
+
status: ServerConnectionStatus;
|
|
364
|
+
transportType: 'stdio' | 'sse' | 'http' | 'streamable-http';
|
|
365
|
+
toolsCount: number;
|
|
366
|
+
lastConnected?: Date;
|
|
367
|
+
error?: string;
|
|
368
|
+
}
|
|
369
|
+
interface ToolExecutionRequest {
|
|
370
|
+
toolName: string;
|
|
371
|
+
arguments?: Record<string, unknown>;
|
|
372
|
+
sessionContext?: string;
|
|
373
|
+
}
|
|
374
|
+
interface ToolExecutionResponse {
|
|
375
|
+
result: CallToolResult;
|
|
376
|
+
cached?: boolean;
|
|
377
|
+
latencyMs: number;
|
|
378
|
+
serverName: string;
|
|
379
|
+
}
|
|
380
|
+
interface UpstreamClientEvents {
|
|
381
|
+
toolsChanged: (serverName: string, tools: NamespacedTool[]) => void;
|
|
382
|
+
statusChanged: (serverName: string, status: ServerConnectionStatus, error?: string) => void;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
interface SupervisedProcess {
|
|
386
|
+
pid: number;
|
|
387
|
+
name: string;
|
|
388
|
+
startTime: Date;
|
|
389
|
+
}
|
|
390
|
+
declare class ProcessSupervisor {
|
|
391
|
+
private static instance;
|
|
392
|
+
private trackedProcesses;
|
|
393
|
+
private hooksRegistered;
|
|
394
|
+
private constructor();
|
|
395
|
+
static getInstance(): ProcessSupervisor;
|
|
396
|
+
/**
|
|
397
|
+
* Registers a child PID under supervision.
|
|
398
|
+
*/
|
|
399
|
+
track(pid: number, name: string): void;
|
|
400
|
+
/**
|
|
401
|
+
* Unregisters a child PID (e.g., normal graceful exit).
|
|
402
|
+
*/
|
|
403
|
+
untrack(pid: number): void;
|
|
404
|
+
/**
|
|
405
|
+
* Kills an entire process tree for a given root PID.
|
|
406
|
+
* Cross-platform: handles Windows taskkill /T /F and POSIX process group kills.
|
|
407
|
+
*/
|
|
408
|
+
killProcessTree(pid: number, name?: string): void;
|
|
409
|
+
/**
|
|
410
|
+
* Shuts down all supervised processes cleanly.
|
|
411
|
+
*/
|
|
412
|
+
shutdownAll(): void;
|
|
413
|
+
/**
|
|
414
|
+
* Returns list of currently tracked processes.
|
|
415
|
+
*/
|
|
416
|
+
getTrackedProcesses(): SupervisedProcess[];
|
|
417
|
+
private registerGlobalHooks;
|
|
418
|
+
}
|
|
419
|
+
declare const supervisor: ProcessSupervisor;
|
|
420
|
+
|
|
421
|
+
declare function escapeWindowsCmdArg(arg: string): string;
|
|
422
|
+
declare function inferToolHints(toolName: string, desc?: string, annotations?: Record<string, unknown>): {
|
|
423
|
+
readOnlyHint: boolean;
|
|
424
|
+
idempotentHint: boolean;
|
|
425
|
+
destructiveHint: boolean;
|
|
426
|
+
};
|
|
427
|
+
declare class UpstreamMultiplexer extends EventEmitter {
|
|
428
|
+
private connections;
|
|
429
|
+
/** Mapping of exposed tool name -> { serverName, originalName } */
|
|
430
|
+
private toolRoutingTable;
|
|
431
|
+
constructor();
|
|
432
|
+
/**
|
|
433
|
+
* Initializes connections to all configured upstream servers in parallel.
|
|
434
|
+
*/
|
|
435
|
+
connectAll(upstreams: Record<string, UpstreamServerConfig>): Promise<void>;
|
|
436
|
+
/**
|
|
437
|
+
* Connects to a single upstream server.
|
|
438
|
+
*/
|
|
439
|
+
connectServer(name: string, config: UpstreamServerConfig): Promise<void>;
|
|
440
|
+
/**
|
|
441
|
+
* Refreshes the tools catalog for a specific upstream server.
|
|
442
|
+
*/
|
|
443
|
+
refreshServerTools(name: string): Promise<void>;
|
|
444
|
+
/**
|
|
445
|
+
* Rebuilds the global tool routing table with namespacing and fallback alias mapping.
|
|
446
|
+
*/
|
|
447
|
+
private rebuildRoutingTable;
|
|
448
|
+
/**
|
|
449
|
+
* Returns all aggregated tools with namespaced definitions.
|
|
450
|
+
*/
|
|
451
|
+
getAllTools(): NamespacedTool[];
|
|
452
|
+
/**
|
|
453
|
+
* Resolves a tool by name (namespaced or short name).
|
|
454
|
+
*/
|
|
455
|
+
resolveTool(name: string): {
|
|
456
|
+
serverName: string;
|
|
457
|
+
originalName: string;
|
|
458
|
+
tool: NamespacedTool;
|
|
459
|
+
} | undefined;
|
|
460
|
+
/**
|
|
461
|
+
* Executes a tool against its upstream MCP server with a timeout.
|
|
462
|
+
*/
|
|
463
|
+
executeTool(toolName: string, args?: Record<string, unknown>, timeoutMs?: number): Promise<ToolExecutionResponse>;
|
|
464
|
+
/**
|
|
465
|
+
* Returns status summaries for all configured upstreams.
|
|
466
|
+
*/
|
|
467
|
+
getStatus(): UpstreamServerStatus[];
|
|
468
|
+
/**
|
|
469
|
+
* Shuts down all upstream connections and processes.
|
|
470
|
+
*/
|
|
471
|
+
closeAll(): Promise<void>;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
interface ToolRegistryOptions {
|
|
475
|
+
pinnedToolNames?: string[];
|
|
476
|
+
maxActiveTools?: number;
|
|
477
|
+
}
|
|
478
|
+
declare class ToolRegistry {
|
|
479
|
+
private allTools;
|
|
480
|
+
private pinnedToolNames;
|
|
481
|
+
/** Set of dynamically activated tools in current session */
|
|
482
|
+
private dynamicActiveTools;
|
|
483
|
+
private maxActiveTools;
|
|
484
|
+
constructor(options?: ToolRegistryOptions);
|
|
485
|
+
setMaxActiveTools(max: number): void;
|
|
486
|
+
/**
|
|
487
|
+
* Updates LRU timestamp when a tool is invoked.
|
|
488
|
+
*/
|
|
489
|
+
touchTool(name: string): void;
|
|
490
|
+
setPinnedTools(toolNames: string[]): void;
|
|
491
|
+
/**
|
|
492
|
+
* Registers or updates all tools from upstreams into the catalog.
|
|
493
|
+
*/
|
|
494
|
+
setAllTools(tools: NamespacedTool[]): void;
|
|
495
|
+
/**
|
|
496
|
+
* Retrieves a tool by either its namespaced name or original name.
|
|
497
|
+
*/
|
|
498
|
+
getTool(name: string): NamespacedTool | undefined;
|
|
499
|
+
/**
|
|
500
|
+
* Activates tools dynamically (e.g. when summoned by contextwise_search_tools).
|
|
501
|
+
* Evicts least-recently-activated tools if exceeding maxActiveTools.
|
|
502
|
+
*/
|
|
503
|
+
activateTools(toolNames: string[]): NamespacedTool[];
|
|
504
|
+
/**
|
|
505
|
+
* Returns whether a tool is pinned.
|
|
506
|
+
*/
|
|
507
|
+
isPinned(name: string): boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Returns current active tool set to be presented to the AI client:
|
|
510
|
+
* (Pinned tools + Dynamically activated tools)
|
|
511
|
+
*/
|
|
512
|
+
getActiveTools(): NamespacedTool[];
|
|
513
|
+
/**
|
|
514
|
+
* Returns all known tools in the catalog.
|
|
515
|
+
*/
|
|
516
|
+
getAllTools(): NamespacedTool[];
|
|
517
|
+
}
|
|
518
|
+
declare const toolRegistry: ToolRegistry;
|
|
519
|
+
|
|
520
|
+
interface SearchResult {
|
|
521
|
+
tool: NamespacedTool;
|
|
522
|
+
score: number;
|
|
523
|
+
matchTerms: string[];
|
|
524
|
+
}
|
|
525
|
+
interface SearchOptions {
|
|
526
|
+
topK?: number;
|
|
527
|
+
domain?: string;
|
|
528
|
+
serverName?: string;
|
|
529
|
+
minScore?: number;
|
|
530
|
+
similarityThreshold?: number;
|
|
531
|
+
}
|
|
532
|
+
declare class HybridSearchEngine {
|
|
533
|
+
private miniSearch;
|
|
534
|
+
private toolMap;
|
|
535
|
+
constructor();
|
|
536
|
+
/**
|
|
537
|
+
* Indexes a collection of tools.
|
|
538
|
+
*/
|
|
539
|
+
indexTools(tools: NamespacedTool[]): void;
|
|
540
|
+
/**
|
|
541
|
+
* Adds or updates a single tool in the search index.
|
|
542
|
+
*/
|
|
543
|
+
addTool(tool: NamespacedTool): void;
|
|
544
|
+
/**
|
|
545
|
+
* Searches for tools matching query string.
|
|
546
|
+
*/
|
|
547
|
+
search(query: string, options?: SearchOptions): SearchResult[];
|
|
548
|
+
/**
|
|
549
|
+
* Returns total count of indexed tools.
|
|
550
|
+
*/
|
|
551
|
+
get size(): number;
|
|
552
|
+
}
|
|
553
|
+
declare const searchEngine: HybridSearchEngine;
|
|
554
|
+
|
|
555
|
+
interface SearchToolsResult {
|
|
556
|
+
message: string;
|
|
557
|
+
foundTools: Array<{
|
|
558
|
+
name: string;
|
|
559
|
+
server: string;
|
|
560
|
+
description: string;
|
|
561
|
+
parameters: unknown;
|
|
562
|
+
}>;
|
|
563
|
+
activatedNewTools: boolean;
|
|
564
|
+
}
|
|
565
|
+
declare class ContextRouter {
|
|
566
|
+
private config;
|
|
567
|
+
private registry;
|
|
568
|
+
private searchEngine;
|
|
569
|
+
constructor(config?: Partial<RoutingConfig>, registry?: ToolRegistry, search?: HybridSearchEngine);
|
|
570
|
+
updateConfig(config: Partial<RoutingConfig>): void;
|
|
571
|
+
getConfig(): RoutingConfig;
|
|
572
|
+
/**
|
|
573
|
+
* Prime active tools based on workspace environment (Mode 4).
|
|
574
|
+
*/
|
|
575
|
+
primeWorkspace(workspaceDir?: string): void;
|
|
576
|
+
/**
|
|
577
|
+
* Generates a succinct Dynamic Capability Manifest of connected upstream servers and tools.
|
|
578
|
+
*/
|
|
579
|
+
generateCapabilityManifest(): string;
|
|
580
|
+
/**
|
|
581
|
+
* Returns list of tools to expose to downstream AI client.
|
|
582
|
+
*/
|
|
583
|
+
getExposedTools(): Tool[];
|
|
584
|
+
/**
|
|
585
|
+
* Handles contextwise_search_tools meta-tool call.
|
|
586
|
+
*/
|
|
587
|
+
searchAndHydrate(query: string, domain?: string, topK?: number, activate?: boolean): SearchToolsResult;
|
|
588
|
+
}
|
|
589
|
+
declare const contextRouter: ContextRouter;
|
|
590
|
+
|
|
591
|
+
declare class ContextWiseProxy {
|
|
592
|
+
private server;
|
|
593
|
+
private multiplexer;
|
|
594
|
+
private router;
|
|
595
|
+
private transport?;
|
|
596
|
+
private config?;
|
|
597
|
+
private isRunning;
|
|
598
|
+
constructor();
|
|
599
|
+
private setupRequestHandlers;
|
|
600
|
+
/**
|
|
601
|
+
* Main tool execution pipeline handling meta-tools and proxied calls.
|
|
602
|
+
*/
|
|
603
|
+
handleToolCall(name: string, args?: Record<string, unknown>): Promise<CallToolResult>;
|
|
604
|
+
/**
|
|
605
|
+
* Handles contextwise_browse_servers execution.
|
|
606
|
+
*/
|
|
607
|
+
private handleBrowseServersCall;
|
|
608
|
+
/**
|
|
609
|
+
* Handles contextwise_add_server execution (hot-loading & persistence).
|
|
610
|
+
*/
|
|
611
|
+
private handleAddServerCall;
|
|
612
|
+
/**
|
|
613
|
+
* Handles contextwise_search_tools execution.
|
|
614
|
+
*/
|
|
615
|
+
private handleSearchToolsCall;
|
|
616
|
+
/**
|
|
617
|
+
* Dispatches tool call through guardrails and upstream multiplexer.
|
|
618
|
+
*/
|
|
619
|
+
private dispatchProxiedToolCall;
|
|
620
|
+
/**
|
|
621
|
+
* Starts ContextWise proxy using given configuration.
|
|
622
|
+
*/
|
|
623
|
+
start(config: ContextWiseConfig): Promise<void>;
|
|
624
|
+
/**
|
|
625
|
+
* Gracefully shuts down proxy and upstream connections.
|
|
626
|
+
*/
|
|
627
|
+
stop(): Promise<void>;
|
|
628
|
+
getMultiplexer(): UpstreamMultiplexer;
|
|
629
|
+
getRouter(): ContextRouter;
|
|
630
|
+
}
|
|
631
|
+
declare const proxy: ContextWiseProxy;
|
|
632
|
+
|
|
633
|
+
interface NormalizedToolDocument {
|
|
634
|
+
id: string;
|
|
635
|
+
toolName: string;
|
|
636
|
+
originalName: string;
|
|
637
|
+
serverName: string;
|
|
638
|
+
description: string;
|
|
639
|
+
parametersText: string;
|
|
640
|
+
tagsText: string;
|
|
641
|
+
fullSearchableText: string;
|
|
642
|
+
readOnlyHint: boolean;
|
|
643
|
+
destructiveHint: boolean;
|
|
644
|
+
}
|
|
645
|
+
declare class ToolNormalizer {
|
|
646
|
+
/**
|
|
647
|
+
* Normalizes a NamespacedTool into a searchable document for BM25 and vector indexing.
|
|
648
|
+
*/
|
|
649
|
+
static normalize(tool: NamespacedTool): NormalizedToolDocument;
|
|
650
|
+
/**
|
|
651
|
+
* Infers domain categorization tags from tool names and descriptions.
|
|
652
|
+
*/
|
|
653
|
+
static inferTags(tool: NamespacedTool): string[];
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
interface ValidationResult {
|
|
657
|
+
valid: boolean;
|
|
658
|
+
errors?: string[];
|
|
659
|
+
}
|
|
660
|
+
declare class ToolArgumentValidator {
|
|
661
|
+
private ajv;
|
|
662
|
+
private validatorCache;
|
|
663
|
+
constructor();
|
|
664
|
+
private computeSchemaHash;
|
|
665
|
+
/**
|
|
666
|
+
* Pre-flight validates tool arguments against the tool's inputSchema.
|
|
667
|
+
*/
|
|
668
|
+
validate(toolName: string, schema: unknown, args: unknown): ValidationResult;
|
|
669
|
+
clearCache(): void;
|
|
670
|
+
}
|
|
671
|
+
declare const argumentValidator: ToolArgumentValidator;
|
|
672
|
+
|
|
673
|
+
interface CacheStats {
|
|
674
|
+
hits: number;
|
|
675
|
+
misses: number;
|
|
676
|
+
size: number;
|
|
677
|
+
invalidations: number;
|
|
678
|
+
}
|
|
679
|
+
declare class ResponseCache {
|
|
680
|
+
private cache;
|
|
681
|
+
private defaultTtlMs;
|
|
682
|
+
private hits;
|
|
683
|
+
private misses;
|
|
684
|
+
private invalidations;
|
|
685
|
+
constructor(defaultTtlSeconds?: number);
|
|
686
|
+
setTtlSeconds(seconds: number): void;
|
|
687
|
+
/**
|
|
688
|
+
* Retrieves a cached result if available and unexpired.
|
|
689
|
+
*/
|
|
690
|
+
get(serverName: string, toolName: string, args?: Record<string, unknown>): CallToolResult | null;
|
|
691
|
+
/**
|
|
692
|
+
* Stores a tool result in the cache.
|
|
693
|
+
*/
|
|
694
|
+
set(serverName: string, toolName: string, args: Record<string, unknown> | undefined, result: CallToolResult, ttlMs?: number): void;
|
|
695
|
+
/**
|
|
696
|
+
* Invalidates all cache entries for a specific server (e.g. after a mutating call).
|
|
697
|
+
*/
|
|
698
|
+
invalidateServer(serverName: string): number;
|
|
699
|
+
/**
|
|
700
|
+
* Clears the entire cache.
|
|
701
|
+
*/
|
|
702
|
+
clear(): void;
|
|
703
|
+
/**
|
|
704
|
+
* Returns cache metrics.
|
|
705
|
+
*/
|
|
706
|
+
getStats(): CacheStats;
|
|
707
|
+
}
|
|
708
|
+
declare const responseCache: ResponseCache;
|
|
709
|
+
|
|
710
|
+
interface LoopBreakerConfig {
|
|
711
|
+
maxCallsPerMinute: number;
|
|
712
|
+
consecutiveFailureThreshold: number;
|
|
713
|
+
}
|
|
714
|
+
declare class RunawayLoopBreaker {
|
|
715
|
+
private callHistory;
|
|
716
|
+
private consecutiveFailures;
|
|
717
|
+
private maxCallsPerMinute;
|
|
718
|
+
private consecutiveFailureThreshold;
|
|
719
|
+
constructor(config?: Partial<LoopBreakerConfig>);
|
|
720
|
+
updateConfig(config: Partial<LoopBreakerConfig>): void;
|
|
721
|
+
/**
|
|
722
|
+
* Checks if a tool call is permitted before execution with detailed classification.
|
|
723
|
+
*/
|
|
724
|
+
checkPreFlightDetailed(serverName: string, toolName: string, args?: Record<string, unknown>): {
|
|
725
|
+
allowed: boolean;
|
|
726
|
+
reason?: 'rate_limited' | 'circuit_breaker';
|
|
727
|
+
message?: string;
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* Checks if a tool call is permitted before execution.
|
|
731
|
+
* Returns null if allowed, or an error string if blocked by guardrails.
|
|
732
|
+
*/
|
|
733
|
+
checkPreFlight(serverName: string, toolName: string, args?: Record<string, unknown>): string | null;
|
|
734
|
+
/**
|
|
735
|
+
* Records execution outcome of a tool call.
|
|
736
|
+
*/
|
|
737
|
+
recordCall(serverName: string, toolName: string, args?: Record<string, unknown>, isError?: boolean): void;
|
|
738
|
+
/**
|
|
739
|
+
* Resets all history and breakers.
|
|
740
|
+
*/
|
|
741
|
+
reset(): void;
|
|
742
|
+
}
|
|
743
|
+
declare const loopBreaker: RunawayLoopBreaker;
|
|
744
|
+
|
|
745
|
+
declare const SEARCH_TOOLS_NAME = "contextwise_search_tools";
|
|
746
|
+
declare const EXECUTE_TOOL_NAME = "contextwise_execute_tool";
|
|
747
|
+
declare const BROWSE_SERVERS_NAME = "contextwise_browse_servers";
|
|
748
|
+
declare const ADD_SERVER_NAME = "contextwise_add_server";
|
|
749
|
+
declare const SEARCH_TOOLS_DEFINITION: Tool;
|
|
750
|
+
declare const EXECUTE_TOOL_DEFINITION: Tool;
|
|
751
|
+
declare const BROWSE_SERVERS_DEFINITION: Tool;
|
|
752
|
+
declare const ADD_SERVER_DEFINITION: Tool;
|
|
753
|
+
|
|
754
|
+
interface WorkspaceContext {
|
|
755
|
+
detectedDomains: string[];
|
|
756
|
+
suggestedQueries: string[];
|
|
757
|
+
}
|
|
758
|
+
declare class WorkspaceContextPrimer {
|
|
759
|
+
/**
|
|
760
|
+
* Scans a workspace directory to detect technical domains and pre-prime relevant tools.
|
|
761
|
+
*/
|
|
762
|
+
static analyzeWorkspace(dirPath?: string): WorkspaceContext;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
type ServerCategory = 'database' | 'developer' | 'web' | 'filesystem' | 'communication' | 'devops';
|
|
766
|
+
interface RequiredParam {
|
|
767
|
+
name: string;
|
|
768
|
+
type: 'env' | 'arg';
|
|
769
|
+
description: string;
|
|
770
|
+
default?: string;
|
|
771
|
+
placeholder?: string;
|
|
772
|
+
}
|
|
773
|
+
interface KnownServerDefinition {
|
|
774
|
+
id: string;
|
|
775
|
+
name: string;
|
|
776
|
+
displayName: string;
|
|
777
|
+
category: ServerCategory;
|
|
778
|
+
description: string;
|
|
779
|
+
tags: string[];
|
|
780
|
+
command: string;
|
|
781
|
+
defaultArgs: string[];
|
|
782
|
+
defaultEnv: Record<string, string>;
|
|
783
|
+
requiredParams: RequiredParam[];
|
|
784
|
+
documentationUrl?: string;
|
|
785
|
+
}
|
|
786
|
+
declare const KNOWN_SERVERS: KnownServerDefinition[];
|
|
787
|
+
declare class KnownServerRegistry {
|
|
788
|
+
/**
|
|
789
|
+
* Returns all known server definitions.
|
|
790
|
+
*/
|
|
791
|
+
static getAll(): KnownServerDefinition[];
|
|
792
|
+
/**
|
|
793
|
+
* Finds a known server by ID or name.
|
|
794
|
+
*/
|
|
795
|
+
static find(idOrName: string): KnownServerDefinition | undefined;
|
|
796
|
+
/**
|
|
797
|
+
* Searches known servers by query string and/or category.
|
|
798
|
+
*/
|
|
799
|
+
static search(query?: string, category?: ServerCategory | string): KnownServerDefinition[];
|
|
800
|
+
/**
|
|
801
|
+
* Returns all unique categories available.
|
|
802
|
+
*/
|
|
803
|
+
static getCategories(): string[];
|
|
804
|
+
/**
|
|
805
|
+
* Builds an UpstreamServerConfig from a KnownServerDefinition and supplied parameters.
|
|
806
|
+
*/
|
|
807
|
+
static buildConfig(serverDef: KnownServerDefinition, params?: {
|
|
808
|
+
args?: string[];
|
|
809
|
+
env?: Record<string, string>;
|
|
810
|
+
}): UpstreamServerConfig;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
type RegistrySource = 'curated' | 'official' | 'smithery';
|
|
814
|
+
interface RegistryServerItem {
|
|
815
|
+
id: string;
|
|
816
|
+
name: string;
|
|
817
|
+
displayName: string;
|
|
818
|
+
description: string;
|
|
819
|
+
source: RegistrySource;
|
|
820
|
+
sourceLabel: string;
|
|
821
|
+
category: string;
|
|
822
|
+
tags: string[];
|
|
823
|
+
installHint: string;
|
|
824
|
+
homepage?: string;
|
|
825
|
+
verified?: boolean;
|
|
826
|
+
requiredParams: RequiredParam[];
|
|
827
|
+
suggestedConfig?: UpstreamServerConfig;
|
|
828
|
+
}
|
|
829
|
+
interface RegistrySearchOptions {
|
|
830
|
+
query?: string;
|
|
831
|
+
category?: string;
|
|
832
|
+
source?: RegistrySource | 'all';
|
|
833
|
+
limit?: number;
|
|
834
|
+
timeoutMs?: number;
|
|
835
|
+
smitheryApiKey?: string;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
declare class OfficialRegistryClient {
|
|
839
|
+
private static readonly BASE_URL;
|
|
840
|
+
/**
|
|
841
|
+
* Searches the official canonical MCP registry for public servers.
|
|
842
|
+
*/
|
|
843
|
+
static search(query?: string, limit?: number, timeoutMs?: number): Promise<RegistryServerItem[]>;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
declare class SmitheryClient {
|
|
847
|
+
private static readonly BASE_URL;
|
|
848
|
+
/**
|
|
849
|
+
* Searches the Smithery.ai registry for community and hosted MCP servers.
|
|
850
|
+
*/
|
|
851
|
+
static search(query?: string, apiKey?: string, timeoutMs?: number): Promise<RegistryServerItem[]>;
|
|
852
|
+
/**
|
|
853
|
+
* Builds an UpstreamServerConfig that runs a Smithery MCP server using @smithery/cli runner.
|
|
854
|
+
*/
|
|
855
|
+
static buildServerConfig(qualifiedName: string, options?: {
|
|
856
|
+
apiKey?: string;
|
|
857
|
+
env?: Record<string, string>;
|
|
858
|
+
}): UpstreamServerConfig;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
declare class UnifiedRegistryClient {
|
|
862
|
+
/**
|
|
863
|
+
* Searches across all available registries (Curated Presets, Official MCP Registry, and Smithery).
|
|
864
|
+
*/
|
|
865
|
+
static search(options?: RegistrySearchOptions): Promise<RegistryServerItem[]>;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
interface RecommendationOutput {
|
|
869
|
+
hasRecommendations: boolean;
|
|
870
|
+
message: string;
|
|
871
|
+
recommendedServers: RegistryServerItem[];
|
|
872
|
+
}
|
|
873
|
+
declare class ServerRecommender {
|
|
874
|
+
/**
|
|
875
|
+
* Generates actionable server recommendations when an agent lacks tools for a given task.
|
|
876
|
+
*/
|
|
877
|
+
static recommendForTask(query: string, domain?: string, limit?: number): Promise<RecommendationOutput>;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
declare class ServerManager {
|
|
881
|
+
/**
|
|
882
|
+
* Finds the path to contextwise.json in the current working directory.
|
|
883
|
+
*/
|
|
884
|
+
static findConfigPath(customPath?: string, cwd?: string): string;
|
|
885
|
+
/**
|
|
886
|
+
* Loads the current configuration or returns an empty default config.
|
|
887
|
+
*/
|
|
888
|
+
static loadConfig(configPath?: string, cwd?: string): {
|
|
889
|
+
config: ContextWiseConfig;
|
|
890
|
+
path: string;
|
|
891
|
+
};
|
|
892
|
+
/**
|
|
893
|
+
* Persists an upstream server configuration to contextwise.json.
|
|
894
|
+
*/
|
|
895
|
+
static saveUpstream(name: string, serverConfig: UpstreamServerConfig, configPath?: string, cwd?: string): string;
|
|
896
|
+
/**
|
|
897
|
+
* Removes an upstream server from contextwise.json.
|
|
898
|
+
*/
|
|
899
|
+
static removeUpstream(name: string, configPath?: string, cwd?: string): boolean;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
interface ExecutionMetric {
|
|
903
|
+
timestamp: number;
|
|
904
|
+
toolName: string;
|
|
905
|
+
serverName: string;
|
|
906
|
+
latencyMs: number;
|
|
907
|
+
cached: boolean;
|
|
908
|
+
tokensSavedEstimate: number;
|
|
909
|
+
isError: boolean;
|
|
910
|
+
}
|
|
911
|
+
interface DollarSavings {
|
|
912
|
+
claudeSonnet: number;
|
|
913
|
+
gpt4o: number;
|
|
914
|
+
claudeOpus: number;
|
|
915
|
+
haikuOrMini: number;
|
|
916
|
+
}
|
|
917
|
+
interface MetricsSummary {
|
|
918
|
+
firstRecordedAt: number;
|
|
919
|
+
lastRecordedAt: number;
|
|
920
|
+
totalCalls: number;
|
|
921
|
+
cachedCalls: number;
|
|
922
|
+
cacheHitRatePct: number;
|
|
923
|
+
errorCalls: number;
|
|
924
|
+
throttles: number;
|
|
925
|
+
loopsPrevented: number;
|
|
926
|
+
averageLatencyMs: number;
|
|
927
|
+
schemaPruningTokensSaved: number;
|
|
928
|
+
cacheTokensSaved: number;
|
|
929
|
+
loopPreventionTokensSaved: number;
|
|
930
|
+
estimatedTotalTokensSaved: number;
|
|
931
|
+
dollarSavings: DollarSavings;
|
|
932
|
+
activeUpstreamsCount: number;
|
|
933
|
+
totalCatalogToolsCount: number;
|
|
934
|
+
exposedToolsCount: number;
|
|
935
|
+
}
|
|
936
|
+
interface PersistentMetricsData {
|
|
937
|
+
version: number;
|
|
938
|
+
firstRecordedAt: number;
|
|
939
|
+
lastRecordedAt: number;
|
|
940
|
+
totalCalls: number;
|
|
941
|
+
cachedCalls: number;
|
|
942
|
+
errorCalls: number;
|
|
943
|
+
throttles: number;
|
|
944
|
+
loopsPrevented: number;
|
|
945
|
+
totalLatencyMs: number;
|
|
946
|
+
schemaPruningTokensSaved: number;
|
|
947
|
+
cacheTokensSaved: number;
|
|
948
|
+
loopPreventionTokensSaved: number;
|
|
949
|
+
totalTokensSaved: number;
|
|
950
|
+
recentCalls: ExecutionMetric[];
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Average token constants derived from MCP protocol benchmarks
|
|
954
|
+
*/
|
|
955
|
+
declare const SCHEMA_TOKENS_PER_TOOL = 150;
|
|
956
|
+
declare const CACHE_TOKENS_PER_HIT = 800;
|
|
957
|
+
declare const LOOP_PREVENTION_TOKENS_PER_TRIP = 2500;
|
|
958
|
+
/**
|
|
959
|
+
* Standard LLM input pricing per 1,000,000 tokens ($ USD)
|
|
960
|
+
*/
|
|
961
|
+
declare const LLM_PRICING: {
|
|
962
|
+
readonly CLAUDE_SONNET: 3;
|
|
963
|
+
readonly GPT_4O: 2.5;
|
|
964
|
+
readonly CLAUDE_OPUS: 15;
|
|
965
|
+
readonly HAIKU_OR_MINI: 0.25;
|
|
966
|
+
};
|
|
967
|
+
declare function calculateDollarSavings(tokens: number): DollarSavings;
|
|
968
|
+
declare function getDefaultMetricsPath(): string;
|
|
969
|
+
declare class MetricsCollector {
|
|
970
|
+
private storagePath;
|
|
971
|
+
private totalCatalogTools;
|
|
972
|
+
private currentlyExposedTools;
|
|
973
|
+
private debounceTimer;
|
|
974
|
+
private data;
|
|
975
|
+
constructor(storagePath?: string);
|
|
976
|
+
private createDefaultData;
|
|
977
|
+
setStoragePath(path: string): void;
|
|
978
|
+
getStoragePath(): string;
|
|
979
|
+
/**
|
|
980
|
+
* Reloads persisted state from disk.
|
|
981
|
+
*/
|
|
982
|
+
reload(): void;
|
|
983
|
+
private loadFromDisk;
|
|
984
|
+
/**
|
|
985
|
+
* Schedules a debounced disk flush.
|
|
986
|
+
*/
|
|
987
|
+
private schedulePersist;
|
|
988
|
+
/**
|
|
989
|
+
* Synchronously writes metrics to disk.
|
|
990
|
+
*/
|
|
991
|
+
flushSync(): void;
|
|
992
|
+
/**
|
|
993
|
+
* Updates catalog sizing to calculate per-turn token savings.
|
|
994
|
+
*/
|
|
995
|
+
updateToolCounts(catalogTotal: number, exposedTotal: number): void;
|
|
996
|
+
/**
|
|
997
|
+
* Records savings from pruning tools during schema listing.
|
|
998
|
+
*/
|
|
999
|
+
recordSchemaPruning(catalogTotal: number, exposedTotal: number): void;
|
|
1000
|
+
/**
|
|
1001
|
+
* Records a caught/prevented runaway loop or circuit breaker trip.
|
|
1002
|
+
*/
|
|
1003
|
+
recordLoopPrevented(toolName?: string, serverName?: string): void;
|
|
1004
|
+
/**
|
|
1005
|
+
* Records a rate-limit velocity throttle event (tracked separately from circuit trips).
|
|
1006
|
+
*/
|
|
1007
|
+
recordThrottle(toolName?: string, serverName?: string): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* Records a tool execution.
|
|
1010
|
+
*/
|
|
1011
|
+
recordExecution(params: {
|
|
1012
|
+
toolName: string;
|
|
1013
|
+
serverName: string;
|
|
1014
|
+
latencyMs: number;
|
|
1015
|
+
cached: boolean;
|
|
1016
|
+
isError?: boolean;
|
|
1017
|
+
}): void;
|
|
1018
|
+
/**
|
|
1019
|
+
* Returns aggregated metrics summary with dollar ROI calculations.
|
|
1020
|
+
*/
|
|
1021
|
+
getSummary(activeUpstreamsCount?: number): MetricsSummary;
|
|
1022
|
+
/**
|
|
1023
|
+
* Clears recorded metrics on disk and memory.
|
|
1024
|
+
*/
|
|
1025
|
+
reset(): void;
|
|
1026
|
+
}
|
|
1027
|
+
declare const metricsCollector: MetricsCollector;
|
|
1028
|
+
|
|
1029
|
+
interface SecretMetadata {
|
|
1030
|
+
key: string;
|
|
1031
|
+
scope: 'personal' | 'workspace' | 'team';
|
|
1032
|
+
backend: string;
|
|
1033
|
+
createdAt: number;
|
|
1034
|
+
updatedAt: number;
|
|
1035
|
+
}
|
|
1036
|
+
interface EncryptedVaultPayload {
|
|
1037
|
+
version: number;
|
|
1038
|
+
kdf: {
|
|
1039
|
+
algorithm: string;
|
|
1040
|
+
salt: string;
|
|
1041
|
+
iterations: number;
|
|
1042
|
+
};
|
|
1043
|
+
cipher: 'aes-256-gcm';
|
|
1044
|
+
iv: string;
|
|
1045
|
+
authTag: string;
|
|
1046
|
+
data: string;
|
|
1047
|
+
}
|
|
1048
|
+
interface VaultDriver {
|
|
1049
|
+
readonly name: string;
|
|
1050
|
+
isAvailable(): Promise<boolean>;
|
|
1051
|
+
get(key: string): Promise<string | null>;
|
|
1052
|
+
set(key: string, value: string, scope?: 'personal' | 'workspace' | 'team'): Promise<void>;
|
|
1053
|
+
delete(key: string): Promise<boolean>;
|
|
1054
|
+
list(): Promise<SecretMetadata[]>;
|
|
1055
|
+
}
|
|
1056
|
+
interface SecretAuditReport {
|
|
1057
|
+
timestamp: number;
|
|
1058
|
+
totalUpstreams: number;
|
|
1059
|
+
vaultReferencedCount: number;
|
|
1060
|
+
plaintextWarnings: Array<{
|
|
1061
|
+
serverName: string;
|
|
1062
|
+
envVar: string;
|
|
1063
|
+
severity: 'critical' | 'warn';
|
|
1064
|
+
reason: string;
|
|
1065
|
+
suggestion: string;
|
|
1066
|
+
}>;
|
|
1067
|
+
activeDriver: string;
|
|
1068
|
+
registeredSecretCount: number;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
declare class VaultAuditor {
|
|
1072
|
+
/**
|
|
1073
|
+
* Scans configuration for plaintext API keys, database credentials, and unvaulted secrets.
|
|
1074
|
+
*/
|
|
1075
|
+
static audit(config: ContextWiseConfig): Promise<SecretAuditReport>;
|
|
1076
|
+
private static evaluateSecret;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
interface AesGcmResult {
|
|
1080
|
+
iv: string;
|
|
1081
|
+
authTag: string;
|
|
1082
|
+
ciphertext: string;
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Encrypts UTF-8 plaintext using AES-256-GCM with a 96-bit random IV.
|
|
1086
|
+
*/
|
|
1087
|
+
declare function encryptAesGcm(plaintext: string, key: Buffer): AesGcmResult;
|
|
1088
|
+
/**
|
|
1089
|
+
* Decrypts AES-256-GCM ciphertext, verifying the 128-bit authentication tag.
|
|
1090
|
+
*/
|
|
1091
|
+
declare function decryptAesGcm(ciphertext: string, key: Buffer, ivBase64: string, authTagBase64: string): string;
|
|
1092
|
+
/**
|
|
1093
|
+
* Standard OWASP-recommended PBKDF2 iterations for SHA-512 key derivation.
|
|
1094
|
+
*/
|
|
1095
|
+
declare const VAULT_PBKDF2_ITERATIONS = 210000;
|
|
1096
|
+
/**
|
|
1097
|
+
* Derives a 256-bit encryption key from a passphrase using PBKDF2 with SHA-512.
|
|
1098
|
+
*/
|
|
1099
|
+
declare function deriveKeyFromPassphrase(passphrase: string, salt: Buffer, iterations?: number): Promise<Buffer>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Derives a key for the local encrypted vault.
|
|
1102
|
+
*
|
|
1103
|
+
* Security & Threat Model:
|
|
1104
|
+
* By default, this derives a deterministic machine-bound key from OS user and hardware
|
|
1105
|
+
* parameters and a random 32-byte salt stored at ~/.contextwise/.machine_salt (mode 0600).
|
|
1106
|
+
* This protects secrets against accidental repository commits, copy-pasting, and unprivileged processes.
|
|
1107
|
+
* For defense-in-depth against local attackers with read access to ~/.contextwise, users can set
|
|
1108
|
+
* the CONTEXTWISE_VAULT_PASSPHRASE environment variable, which derives the key directly from
|
|
1109
|
+
* their secret user passphrase instead of machine identifiers.
|
|
1110
|
+
*/
|
|
1111
|
+
declare function getOrCreateMachineKey(): Promise<Buffer>;
|
|
1112
|
+
/**
|
|
1113
|
+
* Generates an asymmetric X25519 keypair for team member envelope encryption.
|
|
1114
|
+
*/
|
|
1115
|
+
declare function generateKeyPairX25519(): {
|
|
1116
|
+
publicKey: string;
|
|
1117
|
+
privateKey: string;
|
|
1118
|
+
};
|
|
1119
|
+
/**
|
|
1120
|
+
* Derives a shared symmetric secret using ECDH / X25519 for team secret sharing.
|
|
1121
|
+
*/
|
|
1122
|
+
declare function deriveSharedSecretX25519(privateKeyPem: string, publicKeyPem: string): Buffer;
|
|
1123
|
+
|
|
1124
|
+
declare function getDefaultVaultFilePath(): string;
|
|
1125
|
+
declare class EncryptedFileVaultDriver implements VaultDriver {
|
|
1126
|
+
readonly name = "encrypted_file";
|
|
1127
|
+
private filePath;
|
|
1128
|
+
private keyPromise;
|
|
1129
|
+
private cache;
|
|
1130
|
+
constructor(filePath?: string, customKey?: Buffer);
|
|
1131
|
+
isAvailable(): Promise<boolean>;
|
|
1132
|
+
private load;
|
|
1133
|
+
private persist;
|
|
1134
|
+
get(key: string): Promise<string | null>;
|
|
1135
|
+
set(key: string, value: string, scope?: 'personal' | 'workspace' | 'team'): Promise<void>;
|
|
1136
|
+
delete(key: string): Promise<boolean>;
|
|
1137
|
+
list(): Promise<SecretMetadata[]>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Resets and clears all cached and persisted secrets.
|
|
1140
|
+
*/
|
|
1141
|
+
clear(): Promise<void>;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Native OS Keystore Driver.
|
|
1146
|
+
* Integrates with Windows Credential Manager / DPAPI, macOS Keychain, and Linux Secret Service.
|
|
1147
|
+
* Automatically signals availability; if native tools are missing or restricted, falls back gracefully.
|
|
1148
|
+
*/
|
|
1149
|
+
declare class OsKeystoreDriver implements VaultDriver {
|
|
1150
|
+
readonly name = "os_keystore";
|
|
1151
|
+
private available;
|
|
1152
|
+
private readonly serviceName;
|
|
1153
|
+
isAvailable(): Promise<boolean>;
|
|
1154
|
+
get(key: string): Promise<string | null>;
|
|
1155
|
+
set(key: string, value: string, _scope?: 'personal' | 'workspace' | 'team'): Promise<void>;
|
|
1156
|
+
delete(key: string): Promise<boolean>;
|
|
1157
|
+
list(): Promise<SecretMetadata[]>;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Stream & Text Redaction Engine for ContextWise.
|
|
1162
|
+
* Prevents sensitive API keys, database passwords, and vault tokens
|
|
1163
|
+
* from leaking into stdout, stderr, logs, or MCP prompt outputs.
|
|
1164
|
+
*/
|
|
1165
|
+
declare class RedactionFilter {
|
|
1166
|
+
private static instance;
|
|
1167
|
+
private registeredSecrets;
|
|
1168
|
+
static getInstance(): RedactionFilter;
|
|
1169
|
+
/**
|
|
1170
|
+
* Registers a plaintext secret value to be masked across all output streams.
|
|
1171
|
+
*/
|
|
1172
|
+
registerSecret(secret: string): void;
|
|
1173
|
+
registerSecrets(secrets: string[]): void;
|
|
1174
|
+
getRegisteredCount(): number;
|
|
1175
|
+
clear(): void;
|
|
1176
|
+
/**
|
|
1177
|
+
* Redacts registered secrets and known API key patterns from an input string.
|
|
1178
|
+
*/
|
|
1179
|
+
redact(input: string): string;
|
|
1180
|
+
}
|
|
1181
|
+
declare const redactionFilter: RedactionFilter;
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* Secret Reference Resolver.
|
|
1185
|
+
* Resolves secret references in upstream server environment configurations:
|
|
1186
|
+
* - vault://<key> -> Resolves from ContextWise encrypted vault
|
|
1187
|
+
* - auth://<server> or mcp-auth://<server> -> Resolves from OpenCode mcp-auth.json
|
|
1188
|
+
* - env://${VAR_NAME} or env://VAR_NAME -> Resolves from system environment variables
|
|
1189
|
+
* - literal string -> Passed through directly (and registered for redaction if sensitive)
|
|
1190
|
+
*/
|
|
1191
|
+
declare class SecretResolver {
|
|
1192
|
+
/**
|
|
1193
|
+
* Resolves a single secret token reference (vault://, auth://, env://).
|
|
1194
|
+
*/
|
|
1195
|
+
static resolveSingleRef(ref: string, allowReferences?: boolean): Promise<string>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Resolves a single configuration value that may contain a vault://, auth://, or env:// reference.
|
|
1198
|
+
* If allowReferences is false, secret references are rejected to prevent unauthorized vault access.
|
|
1199
|
+
*/
|
|
1200
|
+
static resolveValue(val: string, allowReferences?: boolean): Promise<string>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Resolves an environment dictionary, replacing all vault:// and env:// references.
|
|
1203
|
+
*/
|
|
1204
|
+
static resolveEnv(envMap?: Record<string, string>, allowReferences?: boolean): Promise<Record<string, string>>;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
declare class SecretVault {
|
|
1208
|
+
private driver;
|
|
1209
|
+
private initialized;
|
|
1210
|
+
constructor(customDriver?: VaultDriver);
|
|
1211
|
+
initialize(): Promise<void>;
|
|
1212
|
+
getActiveDriverName(): string;
|
|
1213
|
+
setDriver(driver: VaultDriver): void;
|
|
1214
|
+
get(key: string): Promise<string | null>;
|
|
1215
|
+
set(key: string, value: string, scope?: 'personal' | 'workspace' | 'team'): Promise<void>;
|
|
1216
|
+
delete(key: string): Promise<boolean>;
|
|
1217
|
+
list(): Promise<SecretMetadata[]>;
|
|
1218
|
+
}
|
|
1219
|
+
declare const secretVault: SecretVault;
|
|
1220
|
+
|
|
1221
|
+
interface CloudAuthToken {
|
|
1222
|
+
token: string;
|
|
1223
|
+
userId: string;
|
|
1224
|
+
email: string;
|
|
1225
|
+
expiresAt: number;
|
|
1226
|
+
}
|
|
1227
|
+
interface DeviceMetadata {
|
|
1228
|
+
deviceId: string;
|
|
1229
|
+
deviceName: string;
|
|
1230
|
+
platform: string;
|
|
1231
|
+
publicKey: string;
|
|
1232
|
+
lastSeenAt: number;
|
|
1233
|
+
}
|
|
1234
|
+
interface WorkspaceMetadata {
|
|
1235
|
+
id: string;
|
|
1236
|
+
name: string;
|
|
1237
|
+
role: 'owner' | 'admin' | 'member';
|
|
1238
|
+
activeRevision: number;
|
|
1239
|
+
updatedAt: number;
|
|
1240
|
+
}
|
|
1241
|
+
interface EncryptedEnvelope {
|
|
1242
|
+
recipientPublicKey: string;
|
|
1243
|
+
ephemeralPublicKey: string;
|
|
1244
|
+
iv: string;
|
|
1245
|
+
authTag: string;
|
|
1246
|
+
ciphertext: string;
|
|
1247
|
+
}
|
|
1248
|
+
interface SyncPushPayload {
|
|
1249
|
+
workspaceId: string;
|
|
1250
|
+
deviceId: string;
|
|
1251
|
+
baseRevision: number;
|
|
1252
|
+
config: ContextWiseConfig;
|
|
1253
|
+
encryptedVault: EncryptedVaultPayload;
|
|
1254
|
+
envelopes?: EncryptedEnvelope[];
|
|
1255
|
+
timestamp: number;
|
|
1256
|
+
}
|
|
1257
|
+
interface SyncPushResult {
|
|
1258
|
+
status: 'committed' | 'conflict';
|
|
1259
|
+
revision: number;
|
|
1260
|
+
serverRevision?: number;
|
|
1261
|
+
message?: string;
|
|
1262
|
+
serverPayload?: SyncPullResult;
|
|
1263
|
+
}
|
|
1264
|
+
interface SyncPullResult {
|
|
1265
|
+
workspaceId: string;
|
|
1266
|
+
revision: number;
|
|
1267
|
+
config: ContextWiseConfig;
|
|
1268
|
+
encryptedVault: EncryptedVaultPayload;
|
|
1269
|
+
envelopes?: EncryptedEnvelope[];
|
|
1270
|
+
timestamp: number;
|
|
1271
|
+
}
|
|
1272
|
+
interface CloudClientOptions {
|
|
1273
|
+
apiUrl?: string;
|
|
1274
|
+
authToken?: string;
|
|
1275
|
+
storageDir?: string;
|
|
1276
|
+
allowOfflineSimulation?: boolean;
|
|
1277
|
+
}
|
|
1278
|
+
interface CloudProfileInfo {
|
|
1279
|
+
userId: string;
|
|
1280
|
+
email: string;
|
|
1281
|
+
plan: 'free' | 'pro' | 'team' | 'enterprise';
|
|
1282
|
+
subscriptionStatus: string;
|
|
1283
|
+
currentPeriodEnd?: number | null;
|
|
1284
|
+
workspaces: WorkspaceMetadata[];
|
|
1285
|
+
devices: DeviceMetadata[];
|
|
1286
|
+
}
|
|
1287
|
+
interface CheckoutSessionResult {
|
|
1288
|
+
sessionId: string;
|
|
1289
|
+
checkoutUrl: string;
|
|
1290
|
+
plan: string;
|
|
1291
|
+
interval: string;
|
|
1292
|
+
}
|
|
1293
|
+
interface BillingPortalResult {
|
|
1294
|
+
portalUrl: string;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
declare class ContextWiseCloudClient {
|
|
1298
|
+
private apiUrl;
|
|
1299
|
+
private storageDir;
|
|
1300
|
+
private allowOfflineSimulation;
|
|
1301
|
+
private token;
|
|
1302
|
+
constructor(options?: CloudClientOptions);
|
|
1303
|
+
private getTokenPath;
|
|
1304
|
+
private loadToken;
|
|
1305
|
+
saveToken(token: CloudAuthToken): void;
|
|
1306
|
+
clearToken(): void;
|
|
1307
|
+
getToken(): CloudAuthToken | null;
|
|
1308
|
+
isAuthenticated(): boolean;
|
|
1309
|
+
/**
|
|
1310
|
+
* Starts RFC 8628 device authorization flow.
|
|
1311
|
+
*/
|
|
1312
|
+
startDeviceFlow(): Promise<{
|
|
1313
|
+
device_code: string;
|
|
1314
|
+
user_code: string;
|
|
1315
|
+
verification_uri: string;
|
|
1316
|
+
expires_in: number;
|
|
1317
|
+
interval: number;
|
|
1318
|
+
}>;
|
|
1319
|
+
/**
|
|
1320
|
+
* Polls device token until user approves the code in their browser.
|
|
1321
|
+
*/
|
|
1322
|
+
pollDeviceToken(deviceCode: string, intervalSeconds?: number, maxWaitMs?: number): Promise<CloudAuthToken>;
|
|
1323
|
+
/**
|
|
1324
|
+
* Authenticates using a user API token or personal access key.
|
|
1325
|
+
*/
|
|
1326
|
+
loginWithKey(apiKey: string): Promise<CloudAuthToken>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Retrieves profile information for current authenticated account.
|
|
1329
|
+
*/
|
|
1330
|
+
whoami(): Promise<CloudProfileInfo>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Initiates Stripe Checkout session for Pro or Team upgrade.
|
|
1333
|
+
*/
|
|
1334
|
+
createCheckoutSession(plan?: 'pro' | 'team', interval?: 'month' | 'year'): Promise<CheckoutSessionResult>;
|
|
1335
|
+
/**
|
|
1336
|
+
* Generates Stripe Customer Portal session to manage subscription and invoices.
|
|
1337
|
+
*/
|
|
1338
|
+
createPortalSession(): Promise<BillingPortalResult>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Pushes a workspace snapshot (config + encrypted vault) to the Cloudflare Workers / D1 backend.
|
|
1341
|
+
*/
|
|
1342
|
+
pushSync(payload: SyncPushPayload): Promise<SyncPushResult>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Pulls the latest workspace snapshot (config + encrypted vault) from the cloud backend.
|
|
1345
|
+
*/
|
|
1346
|
+
pullSync(workspaceId: string, sinceRevision?: number): Promise<SyncPullResult | null>;
|
|
1347
|
+
}
|
|
1348
|
+
declare const cloudClient: ContextWiseCloudClient;
|
|
1349
|
+
|
|
1350
|
+
interface DeviceIdentity {
|
|
1351
|
+
deviceId: string;
|
|
1352
|
+
publicKey: string;
|
|
1353
|
+
privateKey: string;
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Creates an asymmetric public-key envelope (X25519 ECDH + AES-256-GCM)
|
|
1357
|
+
* encrypting a workspace key specifically for a recipient's device public key.
|
|
1358
|
+
*/
|
|
1359
|
+
declare function createEnvelope(workspaceKey: Buffer, recipientPublicKeyPem: string): EncryptedEnvelope;
|
|
1360
|
+
/**
|
|
1361
|
+
* Opens an asymmetric envelope using the recipient's private key.
|
|
1362
|
+
*/
|
|
1363
|
+
declare function openEnvelope(envelope: EncryptedEnvelope, recipientPrivateKeyPem: string): Buffer;
|
|
1364
|
+
/**
|
|
1365
|
+
* Retrieves or generates the local device identity and asymmetric X25519 keypair.
|
|
1366
|
+
*/
|
|
1367
|
+
declare function getOrCreateDeviceIdentity(storageDir?: string): DeviceIdentity;
|
|
1368
|
+
|
|
1369
|
+
declare class SyncManager {
|
|
1370
|
+
private syncStatePath;
|
|
1371
|
+
private localConfigPath?;
|
|
1372
|
+
constructor(storageDir?: string, localConfigPath?: string);
|
|
1373
|
+
private loadSyncState;
|
|
1374
|
+
private saveSyncState;
|
|
1375
|
+
/**
|
|
1376
|
+
* Pushes local configuration and encrypted vault payload to the cloud.
|
|
1377
|
+
*/
|
|
1378
|
+
push(workspaceId?: string): Promise<SyncPushResult>;
|
|
1379
|
+
/**
|
|
1380
|
+
* Pulls the latest cloud configuration and merges upstream servers.
|
|
1381
|
+
*/
|
|
1382
|
+
pull(workspaceId?: string): Promise<SyncPullResult | null>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Semantically merges remote configuration into local contextwise.json.
|
|
1385
|
+
*/
|
|
1386
|
+
private mergeConfigIntoLocal;
|
|
1387
|
+
private createEmptyEncryptedVault;
|
|
1388
|
+
getStatus(): {
|
|
1389
|
+
isLoggedIn: boolean;
|
|
1390
|
+
userEmail?: string;
|
|
1391
|
+
workspaceId: string;
|
|
1392
|
+
revision: number;
|
|
1393
|
+
lastSyncedAt: number;
|
|
1394
|
+
deviceId: string;
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
declare const syncManager: SyncManager;
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Structured Logger for ContextWise
|
|
1401
|
+
*
|
|
1402
|
+
* CRITICAL MCP REQUIREMENT:
|
|
1403
|
+
* In stdio mode, stdout is strictly reserved for JSON-RPC 2.0 messages.
|
|
1404
|
+
* Any log messages must be written to stderr or log files to prevent protocol corruption.
|
|
1405
|
+
*/
|
|
1406
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
1407
|
+
declare class Logger {
|
|
1408
|
+
private level;
|
|
1409
|
+
private prefix;
|
|
1410
|
+
constructor(prefix?: string, level?: LogLevel);
|
|
1411
|
+
setLevel(level: LogLevel): void;
|
|
1412
|
+
getLevel(): LogLevel;
|
|
1413
|
+
private shouldLog;
|
|
1414
|
+
private formatMessage;
|
|
1415
|
+
debug(message: string, meta?: unknown): void;
|
|
1416
|
+
info(message: string, meta?: unknown): void;
|
|
1417
|
+
warn(message: string, meta?: unknown): void;
|
|
1418
|
+
error(message: string, meta?: unknown): void;
|
|
1419
|
+
}
|
|
1420
|
+
declare const logger: Logger;
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Deterministically stringifies an object by sorting its keys recursively.
|
|
1424
|
+
*/
|
|
1425
|
+
declare function canonicalJsonStringify(obj: unknown, seen?: WeakSet<object>): string;
|
|
1426
|
+
/**
|
|
1427
|
+
* Computes SHA-256 hash of a string.
|
|
1428
|
+
*/
|
|
1429
|
+
declare function sha256(input: string): string;
|
|
1430
|
+
/**
|
|
1431
|
+
* Generates a content-addressable cache key for tool invocations.
|
|
1432
|
+
*/
|
|
1433
|
+
declare function generateToolCallCacheKey(serverName: string, toolName: string, args?: Record<string, unknown>): string;
|
|
1434
|
+
|
|
1435
|
+
export { ADD_SERVER_DEFINITION, ADD_SERVER_NAME, type AesGcmResult, BROWSE_SERVERS_DEFINITION, BROWSE_SERVERS_NAME, type BillingPortalResult, CACHE_TOKENS_PER_HIT, type CacheStats, type CheckoutSessionResult, type CloudAuthToken, type CloudClientOptions, type CloudProfileInfo, ConfigLoader, ContextRouter, ContextWiseCloudClient, type ContextWiseConfig, ContextWiseConfigSchema, ContextWiseProxy, type DeviceIdentity, type DeviceMetadata, type DollarSavings, EXECUTE_TOOL_DEFINITION, EXECUTE_TOOL_NAME, type EncryptedEnvelope, EncryptedFileVaultDriver, type EncryptedVaultPayload, type ExecutionMetric, type GuardrailsConfig, GuardrailsConfigSchema, type HttpUpstreamConfig, HttpUpstreamConfigSchema, HybridSearchEngine, KNOWN_SERVERS, type KnownServerDefinition, KnownServerRegistry, LLM_PRICING, LOOP_PREVENTION_TOKENS_PER_TRIP, type LoadConfigOptions, type LogLevel, Logger, type LoopBreakerConfig, MetricsCollector, type MetricsSummary, type NamespacedTool, type NormalizedToolDocument, OfficialRegistryClient, OsKeystoreDriver, type PersistentMetricsData, ProcessSupervisor, type ProxyConfig, ProxyConfigSchema, type RecommendationOutput, RedactionFilter, type RegistrySearchOptions, type RegistryServerItem, type RegistrySource, type RequiredParam, ResponseCache, type RoutingConfig, RoutingConfigSchema, RunawayLoopBreaker, SCHEMA_TOKENS_PER_TOOL, SEARCH_TOOLS_DEFINITION, SEARCH_TOOLS_NAME, type SearchOptions, type SearchResult, type SearchToolsResult, type SecretAuditReport, type SecretMetadata, SecretResolver, SecretVault, type ServerCategory, type ServerConnectionStatus, ServerManager, ServerRecommender, SmitheryClient, type StdioUpstreamConfig, StdioUpstreamConfigSchema, type SupervisedProcess, SyncManager, type SyncPullResult, type SyncPushPayload, type SyncPushResult, ToolArgumentValidator, type ToolExecutionRequest, type ToolExecutionResponse, ToolNormalizer, ToolRegistry, type ToolRegistryOptions, UnifiedRegistryClient, type UpstreamClientEvents, UpstreamMultiplexer, type UpstreamServerConfig, UpstreamServerConfigSchema, type UpstreamServerStatus, VAULT_PBKDF2_ITERATIONS, type ValidationResult, VaultAuditor, type VaultDriver, type WorkspaceContext, WorkspaceContextPrimer, type WorkspaceMetadata, argumentValidator, calculateDollarSavings, canonicalJsonStringify, cloudClient, contextRouter, createEnvelope, decryptAesGcm, deriveKeyFromPassphrase, deriveSharedSecretX25519, encryptAesGcm, escapeWindowsCmdArg, generateKeyPairX25519, generateToolCallCacheKey, getDefaultMetricsPath, getDefaultVaultFilePath, getOrCreateDeviceIdentity, getOrCreateMachineKey, inferToolHints, isHttpUpstream, isStdioUpstream, logger, loopBreaker, metricsCollector, openEnvelope, proxy, redactionFilter, responseCache, searchEngine, secretVault, sha256, supervisor, syncManager, toolRegistry, warnIfInsecureHttp };
|