@neurynae/toolcairn-mcp 0.8.4 → 0.8.6
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/bin/toolpilot-mcp.js +22 -3
- package/dist/index.js +572 -81
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -77,9 +77,442 @@ var require_dist = __commonJS({
|
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
// ../../packages/errors/dist/error-codes.js
|
|
81
|
+
var require_error_codes = __commonJS({
|
|
82
|
+
"../../packages/errors/dist/error-codes.js"(exports) {
|
|
83
|
+
"use strict";
|
|
84
|
+
init_esm_shims();
|
|
85
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
+
exports.ErrorCode = void 0;
|
|
87
|
+
exports.ErrorCode = {
|
|
88
|
+
// ── Database ────────────────────────────────────────────────────────────────
|
|
89
|
+
ERR_DB_CONNECTION: "ERR_DB_CONNECTION",
|
|
90
|
+
ERR_DB_QUERY: "ERR_DB_QUERY",
|
|
91
|
+
ERR_DB_TIMEOUT: "ERR_DB_TIMEOUT",
|
|
92
|
+
ERR_DB_CONSTRAINT: "ERR_DB_CONSTRAINT",
|
|
93
|
+
ERR_DB_NOT_FOUND: "ERR_DB_NOT_FOUND",
|
|
94
|
+
// ── Validation ──────────────────────────────────────────────────────────────
|
|
95
|
+
ERR_VALIDATION_INPUT: "ERR_VALIDATION_INPUT",
|
|
96
|
+
ERR_VALIDATION_SCHEMA: "ERR_VALIDATION_SCHEMA",
|
|
97
|
+
// ── Auth ────────────────────────────────────────────────────────────────────
|
|
98
|
+
ERR_AUTH_TOKEN_EXPIRED: "ERR_AUTH_TOKEN_EXPIRED",
|
|
99
|
+
ERR_AUTH_UNAUTHORIZED: "ERR_AUTH_UNAUTHORIZED",
|
|
100
|
+
ERR_AUTH_FORBIDDEN: "ERR_AUTH_FORBIDDEN",
|
|
101
|
+
// ── External services ───────────────────────────────────────────────────────
|
|
102
|
+
ERR_EXTERNAL_GITHUB: "ERR_EXTERNAL_GITHUB",
|
|
103
|
+
ERR_EXTERNAL_NOMIC: "ERR_EXTERNAL_NOMIC",
|
|
104
|
+
ERR_EXTERNAL_QDRANT: "ERR_EXTERNAL_QDRANT",
|
|
105
|
+
ERR_EXTERNAL_MEMGRAPH: "ERR_EXTERNAL_MEMGRAPH",
|
|
106
|
+
ERR_EXTERNAL_RAZORPAY: "ERR_EXTERNAL_RAZORPAY",
|
|
107
|
+
// ── Queue ───────────────────────────────────────────────────────────────────
|
|
108
|
+
ERR_QUEUE_PUBLISH: "ERR_QUEUE_PUBLISH",
|
|
109
|
+
ERR_QUEUE_CONSUME: "ERR_QUEUE_CONSUME",
|
|
110
|
+
ERR_QUEUE_TIMEOUT: "ERR_QUEUE_TIMEOUT",
|
|
111
|
+
// ── Search ──────────────────────────────────────────────────────────────────
|
|
112
|
+
ERR_SEARCH_PIPELINE: "ERR_SEARCH_PIPELINE",
|
|
113
|
+
ERR_SEARCH_EMBEDDING: "ERR_SEARCH_EMBEDDING",
|
|
114
|
+
ERR_SEARCH_NO_RESULTS: "ERR_SEARCH_NO_RESULTS",
|
|
115
|
+
// ── Indexer ─────────────────────────────────────────────────────────────────
|
|
116
|
+
ERR_INDEXER_CRAWL: "ERR_INDEXER_CRAWL",
|
|
117
|
+
ERR_INDEXER_PROCESS: "ERR_INDEXER_PROCESS",
|
|
118
|
+
ERR_INDEXER_WRITE: "ERR_INDEXER_WRITE",
|
|
119
|
+
// ── Network ─────────────────────────────────────────────────────────────────
|
|
120
|
+
ERR_NETWORK_TIMEOUT: "ERR_NETWORK_TIMEOUT",
|
|
121
|
+
ERR_NETWORK_UNREACHABLE: "ERR_NETWORK_UNREACHABLE",
|
|
122
|
+
// ── MCP ─────────────────────────────────────────────────────────────────────
|
|
123
|
+
ERR_MCP_HANDLER: "ERR_MCP_HANDLER",
|
|
124
|
+
ERR_MCP_AUTH: "ERR_MCP_AUTH",
|
|
125
|
+
// ── Generic ─────────────────────────────────────────────────────────────────
|
|
126
|
+
ERR_INTERNAL: "ERR_INTERNAL",
|
|
127
|
+
ERR_NOT_FOUND: "ERR_NOT_FOUND",
|
|
128
|
+
ERR_RATE_LIMIT: "ERR_RATE_LIMIT"
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ../../packages/errors/dist/errors.js
|
|
134
|
+
var require_errors = __commonJS({
|
|
135
|
+
"../../packages/errors/dist/errors.js"(exports) {
|
|
136
|
+
"use strict";
|
|
137
|
+
init_esm_shims();
|
|
138
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
139
|
+
exports.VectorError = exports.IndexerError = exports.SearchError = exports.QueueError = exports.ExternalServiceError = exports.AuthError = exports.ValidationError = exports.NetworkError = exports.DatabaseError = exports.AppError = void 0;
|
|
140
|
+
var error_codes_js_1 = require_error_codes();
|
|
141
|
+
var AppError = class extends Error {
|
|
142
|
+
code;
|
|
143
|
+
httpStatus;
|
|
144
|
+
severity;
|
|
145
|
+
isOperational;
|
|
146
|
+
context;
|
|
147
|
+
timestamp;
|
|
148
|
+
constructor(opts) {
|
|
149
|
+
super(opts.message, { cause: opts.cause });
|
|
150
|
+
this.name = this.constructor.name;
|
|
151
|
+
this.code = opts.code;
|
|
152
|
+
this.httpStatus = opts.httpStatus ?? 500;
|
|
153
|
+
this.severity = opts.severity ?? "medium";
|
|
154
|
+
this.isOperational = opts.isOperational ?? true;
|
|
155
|
+
this.context = opts.context ?? {};
|
|
156
|
+
this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
157
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
158
|
+
}
|
|
159
|
+
/** Structured JSON representation used by the pino error serializer */
|
|
160
|
+
toJSON() {
|
|
161
|
+
return {
|
|
162
|
+
name: this.name,
|
|
163
|
+
code: this.code,
|
|
164
|
+
message: this.message,
|
|
165
|
+
httpStatus: this.httpStatus,
|
|
166
|
+
severity: this.severity,
|
|
167
|
+
isOperational: this.isOperational,
|
|
168
|
+
context: this.context,
|
|
169
|
+
timestamp: this.timestamp,
|
|
170
|
+
stack: this.stack,
|
|
171
|
+
cause: this.cause instanceof Error ? { name: this.cause.name, message: this.cause.message, stack: this.cause.stack } : this.cause
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.AppError = AppError;
|
|
176
|
+
var DatabaseError = class extends AppError {
|
|
177
|
+
constructor(opts) {
|
|
178
|
+
super({
|
|
179
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_DB_QUERY,
|
|
180
|
+
message: opts.message,
|
|
181
|
+
httpStatus: 503,
|
|
182
|
+
severity: "high",
|
|
183
|
+
isOperational: true,
|
|
184
|
+
cause: opts.cause,
|
|
185
|
+
context: opts.context
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
exports.DatabaseError = DatabaseError;
|
|
190
|
+
var NetworkError2 = class extends AppError {
|
|
191
|
+
constructor(opts) {
|
|
192
|
+
super({
|
|
193
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_NETWORK_TIMEOUT,
|
|
194
|
+
message: opts.message,
|
|
195
|
+
httpStatus: 502,
|
|
196
|
+
severity: "high",
|
|
197
|
+
isOperational: true,
|
|
198
|
+
cause: opts.cause,
|
|
199
|
+
context: opts.context
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
exports.NetworkError = NetworkError2;
|
|
204
|
+
var ValidationError = class extends AppError {
|
|
205
|
+
constructor(opts) {
|
|
206
|
+
super({
|
|
207
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_VALIDATION_INPUT,
|
|
208
|
+
message: opts.message,
|
|
209
|
+
httpStatus: 400,
|
|
210
|
+
severity: "low",
|
|
211
|
+
isOperational: true,
|
|
212
|
+
cause: opts.cause,
|
|
213
|
+
context: opts.context
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
exports.ValidationError = ValidationError;
|
|
218
|
+
var AuthError2 = class extends AppError {
|
|
219
|
+
constructor(opts) {
|
|
220
|
+
super({
|
|
221
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_AUTH_UNAUTHORIZED,
|
|
222
|
+
message: opts.message,
|
|
223
|
+
httpStatus: 401,
|
|
224
|
+
severity: "medium",
|
|
225
|
+
isOperational: true,
|
|
226
|
+
cause: opts.cause,
|
|
227
|
+
context: opts.context
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
exports.AuthError = AuthError2;
|
|
232
|
+
var ExternalServiceError = class extends AppError {
|
|
233
|
+
constructor(opts) {
|
|
234
|
+
super({
|
|
235
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_INTERNAL,
|
|
236
|
+
message: `[${opts.service}] ${opts.message}`,
|
|
237
|
+
httpStatus: 502,
|
|
238
|
+
severity: "high",
|
|
239
|
+
isOperational: true,
|
|
240
|
+
cause: opts.cause,
|
|
241
|
+
context: { ...opts.context, service: opts.service }
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
exports.ExternalServiceError = ExternalServiceError;
|
|
246
|
+
var QueueError = class extends AppError {
|
|
247
|
+
constructor(opts) {
|
|
248
|
+
super({
|
|
249
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_QUEUE_PUBLISH,
|
|
250
|
+
message: opts.message,
|
|
251
|
+
httpStatus: 503,
|
|
252
|
+
severity: "high",
|
|
253
|
+
isOperational: true,
|
|
254
|
+
cause: opts.cause,
|
|
255
|
+
context: opts.context
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
exports.QueueError = QueueError;
|
|
260
|
+
var SearchError = class extends AppError {
|
|
261
|
+
constructor(opts) {
|
|
262
|
+
super({
|
|
263
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_SEARCH_PIPELINE,
|
|
264
|
+
message: opts.message,
|
|
265
|
+
httpStatus: 500,
|
|
266
|
+
severity: "medium",
|
|
267
|
+
isOperational: true,
|
|
268
|
+
cause: opts.cause,
|
|
269
|
+
context: opts.context
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
exports.SearchError = SearchError;
|
|
274
|
+
var IndexerError = class extends AppError {
|
|
275
|
+
constructor(opts) {
|
|
276
|
+
super({
|
|
277
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_INDEXER_PROCESS,
|
|
278
|
+
message: opts.message,
|
|
279
|
+
httpStatus: 500,
|
|
280
|
+
severity: "medium",
|
|
281
|
+
isOperational: true,
|
|
282
|
+
cause: opts.cause,
|
|
283
|
+
context: opts.context
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
exports.IndexerError = IndexerError;
|
|
288
|
+
var VectorError = class extends AppError {
|
|
289
|
+
constructor(opts) {
|
|
290
|
+
super({
|
|
291
|
+
code: opts.code ?? error_codes_js_1.ErrorCode.ERR_EXTERNAL_NOMIC,
|
|
292
|
+
message: opts.message,
|
|
293
|
+
httpStatus: 502,
|
|
294
|
+
severity: "high",
|
|
295
|
+
isOperational: true,
|
|
296
|
+
cause: opts.cause,
|
|
297
|
+
context: opts.context
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
exports.VectorError = VectorError;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// ../../packages/errors/dist/serializers.js
|
|
306
|
+
var require_serializers = __commonJS({
|
|
307
|
+
"../../packages/errors/dist/serializers.js"(exports) {
|
|
308
|
+
"use strict";
|
|
309
|
+
init_esm_shims();
|
|
310
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
311
|
+
exports.errorSerializer = errorSerializer;
|
|
312
|
+
var errors_js_1 = require_errors();
|
|
313
|
+
function errorSerializer(err) {
|
|
314
|
+
if (err instanceof errors_js_1.AppError) {
|
|
315
|
+
return err.toJSON();
|
|
316
|
+
}
|
|
317
|
+
if (err instanceof Error) {
|
|
318
|
+
return {
|
|
319
|
+
name: err.name,
|
|
320
|
+
message: err.message,
|
|
321
|
+
stack: err.stack,
|
|
322
|
+
cause: err.cause instanceof Error ? { name: err.cause.name, message: err.cause.message, stack: err.cause.stack } : err.cause
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return { message: String(err) };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// ../../packages/errors/dist/logger.js
|
|
331
|
+
var require_logger = __commonJS({
|
|
332
|
+
"../../packages/errors/dist/logger.js"(exports) {
|
|
333
|
+
"use strict";
|
|
334
|
+
init_esm_shims();
|
|
335
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
336
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
337
|
+
};
|
|
338
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
339
|
+
exports.createMcpLogger = createMcpLogger10;
|
|
340
|
+
exports.createLogger = createMcpLogger10;
|
|
341
|
+
var node_os_1 = __require("os");
|
|
342
|
+
var node_path_1 = __require("path");
|
|
343
|
+
var pino_1 = __importDefault(__require("pino"));
|
|
344
|
+
var serializers_js_1 = require_serializers();
|
|
345
|
+
var REDACT_PATHS = [
|
|
346
|
+
"password",
|
|
347
|
+
"token",
|
|
348
|
+
"accessToken",
|
|
349
|
+
"access_token",
|
|
350
|
+
"refreshToken",
|
|
351
|
+
"refresh_token",
|
|
352
|
+
"apiKey",
|
|
353
|
+
"api_key",
|
|
354
|
+
"secret",
|
|
355
|
+
"TOOLPILOT_API_KEY",
|
|
356
|
+
"authorization",
|
|
357
|
+
"cookie",
|
|
358
|
+
"*.password",
|
|
359
|
+
"*.token",
|
|
360
|
+
"*.secret",
|
|
361
|
+
"*.apiKey",
|
|
362
|
+
"*.api_key"
|
|
363
|
+
];
|
|
364
|
+
function createMcpLogger10(opts) {
|
|
365
|
+
const level = opts.level ?? process.env.LOG_LEVEL ?? (process.env.NODE_ENV !== "production" ? "debug" : "info");
|
|
366
|
+
const pinoOpts = {
|
|
367
|
+
name: opts.name,
|
|
368
|
+
level,
|
|
369
|
+
serializers: {
|
|
370
|
+
err: serializers_js_1.errorSerializer,
|
|
371
|
+
error: serializers_js_1.errorSerializer
|
|
372
|
+
},
|
|
373
|
+
redact: {
|
|
374
|
+
paths: REDACT_PATHS,
|
|
375
|
+
censor: "[REDACTED]"
|
|
376
|
+
},
|
|
377
|
+
timestamp: pino_1.default.stdTimeFunctions.isoTime,
|
|
378
|
+
base: {
|
|
379
|
+
pid: process.pid,
|
|
380
|
+
...opts.defaultFields
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
384
|
+
if (!isProd) {
|
|
385
|
+
return (0, pino_1.default)({ ...pinoOpts, transport: { target: "pino/file", options: { destination: 2 } } });
|
|
386
|
+
}
|
|
387
|
+
const logDir = (0, node_path_1.join)((0, node_os_1.homedir)(), ".toolcairn", "logs");
|
|
388
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
389
|
+
const errorLogPath = (0, node_path_1.join)(logDir, `mcp-error-${today}.log`);
|
|
390
|
+
const transport = pino_1.default.transport({
|
|
391
|
+
targets: [
|
|
392
|
+
{ target: "pino/file", options: { destination: 2 }, level },
|
|
393
|
+
{ target: "pino/file", options: { destination: errorLogPath, mkdir: true }, level: "warn" }
|
|
394
|
+
]
|
|
395
|
+
});
|
|
396
|
+
return (0, pino_1.default)(pinoOpts, transport);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// ../../packages/errors/dist/mcp-error-wrapper.js
|
|
402
|
+
var require_mcp_error_wrapper = __commonJS({
|
|
403
|
+
"../../packages/errors/dist/mcp-error-wrapper.js"(exports) {
|
|
404
|
+
"use strict";
|
|
405
|
+
init_esm_shims();
|
|
406
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
407
|
+
exports.withErrorHandling = withErrorHandling2;
|
|
408
|
+
var error_codes_js_1 = require_error_codes();
|
|
409
|
+
var errors_js_1 = require_errors();
|
|
410
|
+
function withErrorHandling2(toolName, logger10, handler) {
|
|
411
|
+
return async (args) => {
|
|
412
|
+
try {
|
|
413
|
+
return await handler(args);
|
|
414
|
+
} catch (err) {
|
|
415
|
+
if (err instanceof errors_js_1.AppError) {
|
|
416
|
+
const logLevel = err.severity === "critical" || err.severity === "high" ? "error" : "warn";
|
|
417
|
+
logger10[logLevel]({ err, tool: toolName }, `Tool ${toolName} failed: ${err.message}`);
|
|
418
|
+
return {
|
|
419
|
+
content: [
|
|
420
|
+
{
|
|
421
|
+
type: "text",
|
|
422
|
+
text: JSON.stringify({
|
|
423
|
+
ok: false,
|
|
424
|
+
error: err.code,
|
|
425
|
+
message: err.isOperational ? err.message : "An internal error occurred"
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
],
|
|
429
|
+
isError: true
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
logger10.error({ err, tool: toolName }, `Unexpected error in tool ${toolName}`);
|
|
433
|
+
return {
|
|
434
|
+
content: [
|
|
435
|
+
{
|
|
436
|
+
type: "text",
|
|
437
|
+
text: JSON.stringify({
|
|
438
|
+
ok: false,
|
|
439
|
+
error: error_codes_js_1.ErrorCode.ERR_MCP_HANDLER,
|
|
440
|
+
message: err instanceof Error ? err.message : String(err)
|
|
441
|
+
})
|
|
442
|
+
}
|
|
443
|
+
],
|
|
444
|
+
isError: true
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// ../../packages/errors/dist/index.js
|
|
453
|
+
var require_dist2 = __commonJS({
|
|
454
|
+
"../../packages/errors/dist/index.js"(exports) {
|
|
455
|
+
"use strict";
|
|
456
|
+
init_esm_shims();
|
|
457
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
458
|
+
exports.withErrorHandling = exports.createLogger = exports.createMcpLogger = exports.errorSerializer = exports.VectorError = exports.IndexerError = exports.SearchError = exports.QueueError = exports.ExternalServiceError = exports.AuthError = exports.ValidationError = exports.NetworkError = exports.DatabaseError = exports.AppError = exports.ErrorCode = void 0;
|
|
459
|
+
var error_codes_js_1 = require_error_codes();
|
|
460
|
+
Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function() {
|
|
461
|
+
return error_codes_js_1.ErrorCode;
|
|
462
|
+
} });
|
|
463
|
+
var errors_js_1 = require_errors();
|
|
464
|
+
Object.defineProperty(exports, "AppError", { enumerable: true, get: function() {
|
|
465
|
+
return errors_js_1.AppError;
|
|
466
|
+
} });
|
|
467
|
+
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function() {
|
|
468
|
+
return errors_js_1.DatabaseError;
|
|
469
|
+
} });
|
|
470
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function() {
|
|
471
|
+
return errors_js_1.NetworkError;
|
|
472
|
+
} });
|
|
473
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
474
|
+
return errors_js_1.ValidationError;
|
|
475
|
+
} });
|
|
476
|
+
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function() {
|
|
477
|
+
return errors_js_1.AuthError;
|
|
478
|
+
} });
|
|
479
|
+
Object.defineProperty(exports, "ExternalServiceError", { enumerable: true, get: function() {
|
|
480
|
+
return errors_js_1.ExternalServiceError;
|
|
481
|
+
} });
|
|
482
|
+
Object.defineProperty(exports, "QueueError", { enumerable: true, get: function() {
|
|
483
|
+
return errors_js_1.QueueError;
|
|
484
|
+
} });
|
|
485
|
+
Object.defineProperty(exports, "SearchError", { enumerable: true, get: function() {
|
|
486
|
+
return errors_js_1.SearchError;
|
|
487
|
+
} });
|
|
488
|
+
Object.defineProperty(exports, "IndexerError", { enumerable: true, get: function() {
|
|
489
|
+
return errors_js_1.IndexerError;
|
|
490
|
+
} });
|
|
491
|
+
Object.defineProperty(exports, "VectorError", { enumerable: true, get: function() {
|
|
492
|
+
return errors_js_1.VectorError;
|
|
493
|
+
} });
|
|
494
|
+
var serializers_js_1 = require_serializers();
|
|
495
|
+
Object.defineProperty(exports, "errorSerializer", { enumerable: true, get: function() {
|
|
496
|
+
return serializers_js_1.errorSerializer;
|
|
497
|
+
} });
|
|
498
|
+
var logger_js_1 = require_logger();
|
|
499
|
+
Object.defineProperty(exports, "createMcpLogger", { enumerable: true, get: function() {
|
|
500
|
+
return logger_js_1.createMcpLogger;
|
|
501
|
+
} });
|
|
502
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function() {
|
|
503
|
+
return logger_js_1.createLogger;
|
|
504
|
+
} });
|
|
505
|
+
var mcp_error_wrapper_js_1 = require_mcp_error_wrapper();
|
|
506
|
+
Object.defineProperty(exports, "withErrorHandling", { enumerable: true, get: function() {
|
|
507
|
+
return mcp_error_wrapper_js_1.withErrorHandling;
|
|
508
|
+
} });
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
80
512
|
// src/index.prod.ts
|
|
81
513
|
init_esm_shims();
|
|
82
|
-
var
|
|
514
|
+
var import_config4 = __toESM(require_dist(), 1);
|
|
515
|
+
var import_errors11 = __toESM(require_dist2(), 1);
|
|
83
516
|
import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
84
517
|
|
|
85
518
|
// ../../packages/remote/dist/index.js
|
|
@@ -87,6 +520,7 @@ init_esm_shims();
|
|
|
87
520
|
|
|
88
521
|
// ../../packages/remote/dist/client.js
|
|
89
522
|
init_esm_shims();
|
|
523
|
+
var import_errors = __toESM(require_dist2(), 1);
|
|
90
524
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
91
525
|
var ToolCairnClient = class {
|
|
92
526
|
baseUrl;
|
|
@@ -167,7 +601,7 @@ var ToolCairnClient = class {
|
|
|
167
601
|
type: "text",
|
|
168
602
|
text: JSON.stringify({
|
|
169
603
|
ok: false,
|
|
170
|
-
error:
|
|
604
|
+
error: import_errors.ErrorCode.ERR_NETWORK_UNREACHABLE,
|
|
171
605
|
message: `ToolCairn API unreachable: ${msg}. Check your internet connection or try again later.`
|
|
172
606
|
})
|
|
173
607
|
}
|
|
@@ -287,6 +721,7 @@ async function clearAuthentication() {
|
|
|
287
721
|
|
|
288
722
|
// ../../packages/remote/dist/device-auth.js
|
|
289
723
|
init_esm_shims();
|
|
724
|
+
var import_errors2 = __toESM(require_dist2(), 1);
|
|
290
725
|
async function openBrowser(url) {
|
|
291
726
|
const { spawn } = await import("child_process");
|
|
292
727
|
try {
|
|
@@ -310,8 +745,12 @@ async function openBrowser(url) {
|
|
|
310
745
|
}
|
|
311
746
|
async function requestDeviceCode(apiUrl) {
|
|
312
747
|
const res = await fetch(`${apiUrl}/v1/auth/device-code`, { method: "POST" });
|
|
313
|
-
if (!res.ok)
|
|
314
|
-
throw new
|
|
748
|
+
if (!res.ok) {
|
|
749
|
+
throw new import_errors2.NetworkError({
|
|
750
|
+
code: import_errors2.ErrorCode.ERR_NETWORK_UNREACHABLE,
|
|
751
|
+
message: "Failed to start device auth. Check your internet connection."
|
|
752
|
+
});
|
|
753
|
+
}
|
|
315
754
|
const data = await res.json();
|
|
316
755
|
await savePendingAuth({
|
|
317
756
|
device_code: data.device_code,
|
|
@@ -379,10 +818,17 @@ async function pollForToken(apiUrl, deviceCode, intervalSec) {
|
|
|
379
818
|
continue;
|
|
380
819
|
if (data.error === "expired_token") {
|
|
381
820
|
await clearPendingAuth();
|
|
382
|
-
throw new
|
|
821
|
+
throw new import_errors2.AuthError({
|
|
822
|
+
code: import_errors2.ErrorCode.ERR_AUTH_TOKEN_EXPIRED,
|
|
823
|
+
message: "Device code expired. Please try again."
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
if (data.error) {
|
|
827
|
+
throw new import_errors2.AuthError({
|
|
828
|
+
code: import_errors2.ErrorCode.ERR_AUTH_UNAUTHORIZED,
|
|
829
|
+
message: `Authorization failed: ${data.error}`
|
|
830
|
+
});
|
|
383
831
|
}
|
|
384
|
-
if (data.error)
|
|
385
|
-
throw new Error(`Authorization failed: ${data.error}`);
|
|
386
832
|
if (data.access_token)
|
|
387
833
|
return data;
|
|
388
834
|
}
|
|
@@ -392,15 +838,14 @@ function sleep(ms) {
|
|
|
392
838
|
}
|
|
393
839
|
|
|
394
840
|
// src/index.prod.ts
|
|
395
|
-
import pino9 from "pino";
|
|
396
841
|
import { z as z3 } from "zod";
|
|
397
842
|
|
|
398
843
|
// src/project-setup.ts
|
|
399
844
|
init_esm_shims();
|
|
845
|
+
var import_errors3 = __toESM(require_dist2(), 1);
|
|
400
846
|
import { access, mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
401
847
|
import { platform, type } from "os";
|
|
402
848
|
import { join as join2 } from "path";
|
|
403
|
-
import pino from "pino";
|
|
404
849
|
|
|
405
850
|
// src/tools/generate-tracker.ts
|
|
406
851
|
init_esm_shims();
|
|
@@ -808,7 +1253,7 @@ if (!EVENTS_PATH || EVENTS_PATH === 'null') {
|
|
|
808
1253
|
}
|
|
809
1254
|
|
|
810
1255
|
// src/project-setup.ts
|
|
811
|
-
var logger =
|
|
1256
|
+
var logger = (0, import_errors3.createMcpLogger)({ name: "@toolcairn/mcp-server:project-setup" });
|
|
812
1257
|
var INITIAL_CONFIG = {
|
|
813
1258
|
version: "1.0",
|
|
814
1259
|
project: {
|
|
@@ -874,7 +1319,8 @@ async function createIfAbsent(filePath, content, label) {
|
|
|
874
1319
|
|
|
875
1320
|
// src/server.prod.ts
|
|
876
1321
|
init_esm_shims();
|
|
877
|
-
var
|
|
1322
|
+
var import_config2 = __toESM(require_dist(), 1);
|
|
1323
|
+
var import_errors10 = __toESM(require_dist2(), 1);
|
|
878
1324
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
879
1325
|
|
|
880
1326
|
// ../../packages/tools-local/dist/index.js
|
|
@@ -1021,8 +1467,8 @@ function errResult(error, message) {
|
|
|
1021
1467
|
|
|
1022
1468
|
// ../../packages/tools-local/dist/handlers/classify-prompt.js
|
|
1023
1469
|
init_esm_shims();
|
|
1024
|
-
|
|
1025
|
-
var logger2 =
|
|
1470
|
+
var import_errors4 = __toESM(require_dist2(), 1);
|
|
1471
|
+
var logger2 = (0, import_errors4.createMcpLogger)({ name: "@toolcairn/tools:classify-prompt" });
|
|
1026
1472
|
var TOOL_REQUIRED_CLASSIFICATIONS = [
|
|
1027
1473
|
"tool_discovery",
|
|
1028
1474
|
"stack_building",
|
|
@@ -1083,7 +1529,7 @@ Respond with ONLY 0 or 1.`;
|
|
|
1083
1529
|
|
|
1084
1530
|
// ../../packages/tools-local/dist/handlers/toolcairn-init.js
|
|
1085
1531
|
init_esm_shims();
|
|
1086
|
-
|
|
1532
|
+
var import_errors5 = __toESM(require_dist2(), 1);
|
|
1087
1533
|
|
|
1088
1534
|
// ../../packages/tools-local/dist/templates/agent-instructions.js
|
|
1089
1535
|
init_esm_shims();
|
|
@@ -1633,7 +2079,7 @@ if (!EVENTS_PATH || EVENTS_PATH === 'null') {
|
|
|
1633
2079
|
}
|
|
1634
2080
|
|
|
1635
2081
|
// ../../packages/tools-local/dist/handlers/toolcairn-init.js
|
|
1636
|
-
var logger3 =
|
|
2082
|
+
var logger3 = (0, import_errors5.createMcpLogger)({ name: "@toolcairn/tools:toolpilot-init" });
|
|
1637
2083
|
async function handleToolcairnInit(args) {
|
|
1638
2084
|
try {
|
|
1639
2085
|
logger3.info({ agent: args.agent, project_root: args.project_root }, "toolpilot_init called");
|
|
@@ -1721,8 +2167,8 @@ async function handleToolcairnInit(args) {
|
|
|
1721
2167
|
|
|
1722
2168
|
// ../../packages/tools-local/dist/handlers/init-project-config.js
|
|
1723
2169
|
init_esm_shims();
|
|
1724
|
-
|
|
1725
|
-
var logger4 =
|
|
2170
|
+
var import_errors6 = __toESM(require_dist2(), 1);
|
|
2171
|
+
var logger4 = (0, import_errors6.createMcpLogger)({ name: "@toolcairn/tools:init-project-config" });
|
|
1726
2172
|
async function handleInitProjectConfig(args) {
|
|
1727
2173
|
try {
|
|
1728
2174
|
logger4.info({ project: args.project_name }, "init_project_config called");
|
|
@@ -1735,7 +2181,7 @@ async function handleInitProjectConfig(args) {
|
|
|
1735
2181
|
chosen_reason: "Auto-detected from project files during toolpilot_init",
|
|
1736
2182
|
alternatives_considered: []
|
|
1737
2183
|
}));
|
|
1738
|
-
const
|
|
2184
|
+
const config5 = {
|
|
1739
2185
|
version: "1.0",
|
|
1740
2186
|
project: {
|
|
1741
2187
|
name: args.project_name,
|
|
@@ -1755,7 +2201,7 @@ async function handleInitProjectConfig(args) {
|
|
|
1755
2201
|
}
|
|
1756
2202
|
]
|
|
1757
2203
|
};
|
|
1758
|
-
const config_json = JSON.stringify(
|
|
2204
|
+
const config_json = JSON.stringify(config5, null, 2);
|
|
1759
2205
|
return okResult({
|
|
1760
2206
|
config_json,
|
|
1761
2207
|
file_path: ".toolpilot/config.json",
|
|
@@ -1771,8 +2217,8 @@ async function handleInitProjectConfig(args) {
|
|
|
1771
2217
|
|
|
1772
2218
|
// ../../packages/tools-local/dist/handlers/read-project-config.js
|
|
1773
2219
|
init_esm_shims();
|
|
1774
|
-
|
|
1775
|
-
var logger5 =
|
|
2220
|
+
var import_errors7 = __toESM(require_dist2(), 1);
|
|
2221
|
+
var logger5 = (0, import_errors7.createMcpLogger)({ name: "@toolcairn/tools:read-project-config" });
|
|
1776
2222
|
var STALENESS_THRESHOLD_DAYS = 90;
|
|
1777
2223
|
function daysSince(isoDate) {
|
|
1778
2224
|
return (Date.now() - new Date(isoDate).getTime()) / (1e3 * 60 * 60 * 24);
|
|
@@ -1780,18 +2226,18 @@ function daysSince(isoDate) {
|
|
|
1780
2226
|
async function handleReadProjectConfig(args) {
|
|
1781
2227
|
try {
|
|
1782
2228
|
logger5.info("read_project_config called");
|
|
1783
|
-
let
|
|
2229
|
+
let config5;
|
|
1784
2230
|
try {
|
|
1785
|
-
|
|
2231
|
+
config5 = JSON.parse(args.config_content);
|
|
1786
2232
|
} catch {
|
|
1787
2233
|
return errResult("parse_error", "config_content is not valid JSON");
|
|
1788
2234
|
}
|
|
1789
|
-
if (
|
|
1790
|
-
return errResult("version_error", `Unsupported config version: ${
|
|
2235
|
+
if (config5.version !== "1.0") {
|
|
2236
|
+
return errResult("version_error", `Unsupported config version: ${config5.version}`);
|
|
1791
2237
|
}
|
|
1792
|
-
const confirmedToolNames =
|
|
1793
|
-
const pendingToolNames =
|
|
1794
|
-
const staleTools =
|
|
2238
|
+
const confirmedToolNames = config5.tools.confirmed.map((t) => t.name);
|
|
2239
|
+
const pendingToolNames = config5.tools.pending_evaluation.map((t) => t.name);
|
|
2240
|
+
const staleTools = config5.tools.confirmed.filter((t) => {
|
|
1795
2241
|
const date = t.last_verified ?? t.chosen_at ?? t.confirmed_at;
|
|
1796
2242
|
return date ? daysSince(date) > STALENESS_THRESHOLD_DAYS : true;
|
|
1797
2243
|
}).map((t) => {
|
|
@@ -1804,10 +2250,10 @@ async function handleReadProjectConfig(args) {
|
|
|
1804
2250
|
recommendation: "Consider using check_issue to verify no new known issues"
|
|
1805
2251
|
};
|
|
1806
2252
|
});
|
|
1807
|
-
const non_oss_tools =
|
|
1808
|
-
const toolpilot_indexed_tools =
|
|
2253
|
+
const non_oss_tools = config5.tools.confirmed.filter((t) => t.source === "non_oss").map((t) => t.name);
|
|
2254
|
+
const toolpilot_indexed_tools = config5.tools.confirmed.filter((t) => t.source === "toolpilot").map((t) => t.name);
|
|
1809
2255
|
return okResult({
|
|
1810
|
-
project:
|
|
2256
|
+
project: config5.project,
|
|
1811
2257
|
confirmed_tools: confirmedToolNames,
|
|
1812
2258
|
pending_tools: pendingToolNames,
|
|
1813
2259
|
non_oss_tools,
|
|
@@ -1815,9 +2261,9 @@ async function handleReadProjectConfig(args) {
|
|
|
1815
2261
|
stale_tools: staleTools,
|
|
1816
2262
|
total_confirmed: confirmedToolNames.length,
|
|
1817
2263
|
total_pending: pendingToolNames.length,
|
|
1818
|
-
last_audit_entry:
|
|
2264
|
+
last_audit_entry: config5.audit_log.at(-1) ?? null,
|
|
1819
2265
|
agent_instructions: [
|
|
1820
|
-
`Project: ${
|
|
2266
|
+
`Project: ${config5.project.name} (${config5.project.language}${config5.project.framework ? `, ${config5.project.framework}` : ""})`,
|
|
1821
2267
|
`Already confirmed tools: ${confirmedToolNames.join(", ") || "none"}`,
|
|
1822
2268
|
"When recommending tools, skip any already in confirmed_tools.",
|
|
1823
2269
|
non_oss_tools.length > 0 ? `Non-OSS tools in project (handle separately): ${non_oss_tools.join(", ")}` : "",
|
|
@@ -1832,14 +2278,14 @@ async function handleReadProjectConfig(args) {
|
|
|
1832
2278
|
|
|
1833
2279
|
// ../../packages/tools-local/dist/handlers/update-project-config.js
|
|
1834
2280
|
init_esm_shims();
|
|
1835
|
-
|
|
1836
|
-
var logger6 =
|
|
2281
|
+
var import_errors8 = __toESM(require_dist2(), 1);
|
|
2282
|
+
var logger6 = (0, import_errors8.createMcpLogger)({ name: "@toolcairn/tools:update-project-config" });
|
|
1837
2283
|
async function handleUpdateProjectConfig(args) {
|
|
1838
2284
|
try {
|
|
1839
2285
|
logger6.info({ action: args.action, tool: args.tool_name }, "update_project_config called");
|
|
1840
|
-
let
|
|
2286
|
+
let config5;
|
|
1841
2287
|
try {
|
|
1842
|
-
|
|
2288
|
+
config5 = JSON.parse(args.current_config);
|
|
1843
2289
|
} catch {
|
|
1844
2290
|
return errResult("parse_error", "current_config is not valid JSON");
|
|
1845
2291
|
}
|
|
@@ -1847,8 +2293,8 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1847
2293
|
const data = args.data ?? {};
|
|
1848
2294
|
switch (args.action) {
|
|
1849
2295
|
case "add_tool": {
|
|
1850
|
-
|
|
1851
|
-
if (!
|
|
2296
|
+
config5.tools.pending_evaluation = config5.tools.pending_evaluation.filter((t) => t.name !== args.tool_name);
|
|
2297
|
+
if (!config5.tools.confirmed.some((t) => t.name === args.tool_name)) {
|
|
1852
2298
|
const newTool = {
|
|
1853
2299
|
name: args.tool_name,
|
|
1854
2300
|
source: data.source ?? "toolpilot",
|
|
@@ -1860,9 +2306,9 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1860
2306
|
query_id: data.query_id,
|
|
1861
2307
|
notes: data.notes
|
|
1862
2308
|
};
|
|
1863
|
-
|
|
2309
|
+
config5.tools.confirmed.push(newTool);
|
|
1864
2310
|
}
|
|
1865
|
-
|
|
2311
|
+
config5.audit_log.push({
|
|
1866
2312
|
action: "add_tool",
|
|
1867
2313
|
tool: args.tool_name,
|
|
1868
2314
|
timestamp: now,
|
|
@@ -1871,9 +2317,9 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1871
2317
|
break;
|
|
1872
2318
|
}
|
|
1873
2319
|
case "remove_tool": {
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2320
|
+
config5.tools.confirmed = config5.tools.confirmed.filter((t) => t.name !== args.tool_name);
|
|
2321
|
+
config5.tools.pending_evaluation = config5.tools.pending_evaluation.filter((t) => t.name !== args.tool_name);
|
|
2322
|
+
config5.audit_log.push({
|
|
1877
2323
|
action: "remove_tool",
|
|
1878
2324
|
tool: args.tool_name,
|
|
1879
2325
|
timestamp: now,
|
|
@@ -1882,22 +2328,22 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1882
2328
|
break;
|
|
1883
2329
|
}
|
|
1884
2330
|
case "update_tool": {
|
|
1885
|
-
const idx =
|
|
2331
|
+
const idx = config5.tools.confirmed.findIndex((t) => t.name === args.tool_name);
|
|
1886
2332
|
if (idx === -1) {
|
|
1887
2333
|
return errResult("not_found", `Tool "${args.tool_name}" not found in confirmed tools`);
|
|
1888
2334
|
}
|
|
1889
|
-
const existing =
|
|
2335
|
+
const existing = config5.tools.confirmed[idx];
|
|
1890
2336
|
if (!existing) {
|
|
1891
2337
|
return errResult("not_found", `Tool "${args.tool_name}" not found`);
|
|
1892
2338
|
}
|
|
1893
|
-
|
|
2339
|
+
config5.tools.confirmed[idx] = {
|
|
1894
2340
|
...existing,
|
|
1895
2341
|
...data.version !== void 0 ? { version: data.version } : {},
|
|
1896
2342
|
...data.notes !== void 0 ? { notes: data.notes } : {},
|
|
1897
2343
|
...data.chosen_reason !== void 0 ? { chosen_reason: data.chosen_reason } : {},
|
|
1898
2344
|
...data.alternatives_considered !== void 0 ? { alternatives_considered: data.alternatives_considered } : {}
|
|
1899
2345
|
};
|
|
1900
|
-
|
|
2346
|
+
config5.audit_log.push({
|
|
1901
2347
|
action: "update_tool",
|
|
1902
2348
|
tool: args.tool_name,
|
|
1903
2349
|
timestamp: now,
|
|
@@ -1906,15 +2352,15 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1906
2352
|
break;
|
|
1907
2353
|
}
|
|
1908
2354
|
case "add_evaluation": {
|
|
1909
|
-
if (!
|
|
2355
|
+
if (!config5.tools.pending_evaluation.some((t) => t.name === args.tool_name) && !config5.tools.confirmed.some((t) => t.name === args.tool_name)) {
|
|
1910
2356
|
const pending = {
|
|
1911
2357
|
name: args.tool_name,
|
|
1912
2358
|
category: data.category ?? "other",
|
|
1913
2359
|
added_at: now
|
|
1914
2360
|
};
|
|
1915
|
-
|
|
2361
|
+
config5.tools.pending_evaluation.push(pending);
|
|
1916
2362
|
}
|
|
1917
|
-
|
|
2363
|
+
config5.audit_log.push({
|
|
1918
2364
|
action: "add_evaluation",
|
|
1919
2365
|
tool: args.tool_name,
|
|
1920
2366
|
timestamp: now,
|
|
@@ -1923,14 +2369,14 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1923
2369
|
break;
|
|
1924
2370
|
}
|
|
1925
2371
|
}
|
|
1926
|
-
const updated_config_json = JSON.stringify(
|
|
2372
|
+
const updated_config_json = JSON.stringify(config5, null, 2);
|
|
1927
2373
|
return okResult({
|
|
1928
2374
|
updated_config_json,
|
|
1929
2375
|
file_path: ".toolpilot/config.json",
|
|
1930
2376
|
action_applied: args.action,
|
|
1931
2377
|
tool_name: args.tool_name,
|
|
1932
|
-
confirmed_count:
|
|
1933
|
-
pending_count:
|
|
2378
|
+
confirmed_count: config5.tools.confirmed.length,
|
|
2379
|
+
pending_count: config5.tools.pending_evaluation.length,
|
|
1934
2380
|
instructions: "Write updated_config_json to .toolpilot/config.json to persist this change."
|
|
1935
2381
|
});
|
|
1936
2382
|
} catch (e) {
|
|
@@ -1940,15 +2386,15 @@ async function handleUpdateProjectConfig(args) {
|
|
|
1940
2386
|
}
|
|
1941
2387
|
|
|
1942
2388
|
// src/server.prod.ts
|
|
1943
|
-
import pino8 from "pino";
|
|
1944
2389
|
import { z as z2 } from "zod";
|
|
1945
2390
|
|
|
1946
2391
|
// src/middleware/event-logger.ts
|
|
1947
2392
|
init_esm_shims();
|
|
2393
|
+
var import_config = __toESM(require_dist(), 1);
|
|
2394
|
+
var import_errors9 = __toESM(require_dist2(), 1);
|
|
1948
2395
|
import { appendFile, mkdir as mkdir3 } from "fs/promises";
|
|
1949
2396
|
import { dirname } from "path";
|
|
1950
|
-
|
|
1951
|
-
var logger7 = pino7({ name: "@toolcairn/mcp-server:event-logger" });
|
|
2397
|
+
var logger7 = (0, import_errors9.createMcpLogger)({ name: "@toolcairn/mcp-server:event-logger" });
|
|
1952
2398
|
function isTrackingEnabled() {
|
|
1953
2399
|
return process.env.TOOLCAIRN_TRACKING_ENABLED !== "false";
|
|
1954
2400
|
}
|
|
@@ -1995,6 +2441,28 @@ async function writeToFile(eventsPath, event) {
|
|
|
1995
2441
|
logger7.warn({ err: e, path: eventsPath }, "Failed to write event to JSONL file");
|
|
1996
2442
|
}
|
|
1997
2443
|
}
|
|
2444
|
+
async function sendToApi(event) {
|
|
2445
|
+
try {
|
|
2446
|
+
const creds = await loadCredentials();
|
|
2447
|
+
if (!creds) return;
|
|
2448
|
+
const headers = { "Content-Type": "application/json" };
|
|
2449
|
+
if (creds.access_token) headers.Authorization = `Bearer ${creds.access_token}`;
|
|
2450
|
+
if (creds.client_id) headers["X-ToolCairn-Key"] = creds.client_id;
|
|
2451
|
+
await fetch(`${import_config.config.TOOLPILOT_API_URL}/v1/events`, {
|
|
2452
|
+
method: "POST",
|
|
2453
|
+
headers,
|
|
2454
|
+
body: JSON.stringify({
|
|
2455
|
+
tool_name: event.tool_name,
|
|
2456
|
+
query_id: event.query_id,
|
|
2457
|
+
duration_ms: event.duration_ms,
|
|
2458
|
+
status: event.status,
|
|
2459
|
+
metadata: event.metadata
|
|
2460
|
+
})
|
|
2461
|
+
});
|
|
2462
|
+
} catch (e) {
|
|
2463
|
+
logger7.debug({ err: e }, "Failed to send event to API \u2014 non-fatal");
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
1998
2466
|
function withEventLogging(toolName, handler) {
|
|
1999
2467
|
return async (args) => {
|
|
2000
2468
|
if (!isTrackingEnabled()) {
|
|
@@ -2020,6 +2488,8 @@ function withEventLogging(toolName, handler) {
|
|
|
2020
2488
|
metadata: result ? extractMetadata(toolName, result) : null,
|
|
2021
2489
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2022
2490
|
};
|
|
2491
|
+
sendToApi(event).catch(() => {
|
|
2492
|
+
});
|
|
2023
2493
|
const eventsPath = getEventsPath();
|
|
2024
2494
|
if (eventsPath) {
|
|
2025
2495
|
writeToFile(eventsPath, event).catch(() => {
|
|
@@ -2031,7 +2501,7 @@ function withEventLogging(toolName, handler) {
|
|
|
2031
2501
|
}
|
|
2032
2502
|
|
|
2033
2503
|
// src/server.prod.ts
|
|
2034
|
-
var logger8 =
|
|
2504
|
+
var logger8 = (0, import_errors10.createMcpLogger)({ name: "@toolcairn/mcp-server:prod" });
|
|
2035
2505
|
var SETUP_INSTRUCTIONS = `
|
|
2036
2506
|
# ToolCairn \u2014 Agent Setup Instructions
|
|
2037
2507
|
|
|
@@ -2081,18 +2551,24 @@ async function addToolsToServer(server) {
|
|
|
2081
2551
|
throw new Error("ToolCairn: authentication required.");
|
|
2082
2552
|
}
|
|
2083
2553
|
const remote = new ToolCairnClient({
|
|
2084
|
-
baseUrl:
|
|
2554
|
+
baseUrl: import_config2.config.TOOLPILOT_API_URL,
|
|
2085
2555
|
apiKey: creds.client_id,
|
|
2086
2556
|
accessToken: creds.access_token
|
|
2087
2557
|
});
|
|
2088
2558
|
logger8.info({ user: creds.user_email }, "Registering production tools");
|
|
2559
|
+
function wrap(toolName, fn) {
|
|
2560
|
+
return withEventLogging(toolName, (0, import_errors10.withErrorHandling)(toolName, logger8, fn));
|
|
2561
|
+
}
|
|
2089
2562
|
server.registerTool(
|
|
2090
2563
|
"classify_prompt",
|
|
2091
2564
|
{
|
|
2092
2565
|
description: "Classify a developer prompt to determine if ToolCairn tool search is needed. Returns a structured classification prompt for the agent to evaluate.",
|
|
2093
2566
|
inputSchema: classifyPromptSchema
|
|
2094
2567
|
},
|
|
2095
|
-
|
|
2568
|
+
wrap(
|
|
2569
|
+
"classify_prompt",
|
|
2570
|
+
async (args) => handleClassifyPrompt(args)
|
|
2571
|
+
)
|
|
2096
2572
|
);
|
|
2097
2573
|
server.registerTool(
|
|
2098
2574
|
"toolcairn_init",
|
|
@@ -2100,7 +2576,10 @@ async function addToolsToServer(server) {
|
|
|
2100
2576
|
description: "Set up ToolCairn integration for the current project. Generates agent instruction content, MCP config entry, and project config initializer.",
|
|
2101
2577
|
inputSchema: toolpilotInitSchema
|
|
2102
2578
|
},
|
|
2103
|
-
|
|
2579
|
+
wrap(
|
|
2580
|
+
"toolcairn_init",
|
|
2581
|
+
async (args) => handleToolcairnInit(args)
|
|
2582
|
+
)
|
|
2104
2583
|
);
|
|
2105
2584
|
server.registerTool(
|
|
2106
2585
|
"init_project_config",
|
|
@@ -2108,7 +2587,10 @@ async function addToolsToServer(server) {
|
|
|
2108
2587
|
description: "Initialize a .toolcairn/config.json file for the current project. Returns the config JSON for the agent to write to disk.",
|
|
2109
2588
|
inputSchema: initProjectConfigSchema
|
|
2110
2589
|
},
|
|
2111
|
-
|
|
2590
|
+
wrap(
|
|
2591
|
+
"init_project_config",
|
|
2592
|
+
async (args) => handleInitProjectConfig(args)
|
|
2593
|
+
)
|
|
2112
2594
|
);
|
|
2113
2595
|
server.registerTool(
|
|
2114
2596
|
"read_project_config",
|
|
@@ -2116,7 +2598,10 @@ async function addToolsToServer(server) {
|
|
|
2116
2598
|
description: "Parse and validate a .toolcairn/config.json file. Returns confirmed tools, pending evaluations, stale tools, and agent instructions.",
|
|
2117
2599
|
inputSchema: readProjectConfigSchema
|
|
2118
2600
|
},
|
|
2119
|
-
|
|
2601
|
+
wrap(
|
|
2602
|
+
"read_project_config",
|
|
2603
|
+
async (args) => handleReadProjectConfig(args)
|
|
2604
|
+
)
|
|
2120
2605
|
);
|
|
2121
2606
|
server.registerTool(
|
|
2122
2607
|
"update_project_config",
|
|
@@ -2124,7 +2609,10 @@ async function addToolsToServer(server) {
|
|
|
2124
2609
|
description: "Apply a mutation to .toolcairn/config.json and return the updated content. Actions: add_tool, remove_tool, update_tool, add_evaluation.",
|
|
2125
2610
|
inputSchema: updateProjectConfigSchema
|
|
2126
2611
|
},
|
|
2127
|
-
|
|
2612
|
+
wrap(
|
|
2613
|
+
"update_project_config",
|
|
2614
|
+
async (args) => handleUpdateProjectConfig(args)
|
|
2615
|
+
)
|
|
2128
2616
|
);
|
|
2129
2617
|
server.registerTool(
|
|
2130
2618
|
"search_tools",
|
|
@@ -2132,7 +2620,7 @@ async function addToolsToServer(server) {
|
|
|
2132
2620
|
description: "Search for the best tool for a specific need using a natural language query. Initiates a guided discovery session with clarification questions when needed.",
|
|
2133
2621
|
inputSchema: searchToolsSchema
|
|
2134
2622
|
},
|
|
2135
|
-
|
|
2623
|
+
wrap("search_tools", async (args) => remote.searchTools(args))
|
|
2136
2624
|
);
|
|
2137
2625
|
server.registerTool(
|
|
2138
2626
|
"search_tools_respond",
|
|
@@ -2140,15 +2628,15 @@ async function addToolsToServer(server) {
|
|
|
2140
2628
|
description: "Submit clarification answers for an in-progress tool search session and receive refined results.",
|
|
2141
2629
|
inputSchema: searchToolsRespondSchema
|
|
2142
2630
|
},
|
|
2143
|
-
|
|
2631
|
+
wrap("search_tools_respond", async (args) => remote.searchToolsRespond(args))
|
|
2144
2632
|
);
|
|
2145
2633
|
server.registerTool(
|
|
2146
2634
|
"get_stack",
|
|
2147
2635
|
{
|
|
2148
|
-
description: "
|
|
2636
|
+
description: "Build a complementary tool stack for a project use case. Returns diverse, integration-aware tools across different functional layers (not competing alternatives), with docs, health signals, and notes on how stack members integrate with each other.",
|
|
2149
2637
|
inputSchema: getStackSchema
|
|
2150
2638
|
},
|
|
2151
|
-
|
|
2639
|
+
wrap("get_stack", async (args) => remote.getStack(args))
|
|
2152
2640
|
);
|
|
2153
2641
|
server.registerTool(
|
|
2154
2642
|
"check_compatibility",
|
|
@@ -2156,7 +2644,7 @@ async function addToolsToServer(server) {
|
|
|
2156
2644
|
description: "Check compatibility between two tools. Returns direct graph relationships and inferred compatibility from shared neighbors.",
|
|
2157
2645
|
inputSchema: checkCompatibilitySchema
|
|
2158
2646
|
},
|
|
2159
|
-
|
|
2647
|
+
wrap("check_compatibility", async (args) => remote.checkCompatibility(args))
|
|
2160
2648
|
);
|
|
2161
2649
|
server.registerTool(
|
|
2162
2650
|
"compare_tools",
|
|
@@ -2164,7 +2652,7 @@ async function addToolsToServer(server) {
|
|
|
2164
2652
|
description: "Compare two tools head-to-head using health signals, graph relationships, and community data.",
|
|
2165
2653
|
inputSchema: compareToolsSchema
|
|
2166
2654
|
},
|
|
2167
|
-
|
|
2655
|
+
wrap("compare_tools", async (args) => remote.compareTools(args))
|
|
2168
2656
|
);
|
|
2169
2657
|
server.registerTool(
|
|
2170
2658
|
"refine_requirement",
|
|
@@ -2172,7 +2660,7 @@ async function addToolsToServer(server) {
|
|
|
2172
2660
|
description: "Decompose a vague user use-case into specific, searchable tool requirements.",
|
|
2173
2661
|
inputSchema: refineRequirementSchema
|
|
2174
2662
|
},
|
|
2175
|
-
|
|
2663
|
+
wrap("refine_requirement", async (args) => remote.refineRequirement(args))
|
|
2176
2664
|
);
|
|
2177
2665
|
server.registerTool(
|
|
2178
2666
|
"check_issue",
|
|
@@ -2180,7 +2668,7 @@ async function addToolsToServer(server) {
|
|
|
2180
2668
|
description: "LAST RESORT \u2014 check GitHub Issues for a known error after 4+ retries and docs review.",
|
|
2181
2669
|
inputSchema: checkIssueSchema
|
|
2182
2670
|
},
|
|
2183
|
-
|
|
2671
|
+
wrap("check_issue", async (args) => remote.checkIssue(args))
|
|
2184
2672
|
);
|
|
2185
2673
|
server.registerTool(
|
|
2186
2674
|
"verify_suggestion",
|
|
@@ -2188,7 +2676,7 @@ async function addToolsToServer(server) {
|
|
|
2188
2676
|
description: "Validate agent-suggested tools against the ToolCairn graph.",
|
|
2189
2677
|
inputSchema: verifySuggestionSchema
|
|
2190
2678
|
},
|
|
2191
|
-
|
|
2679
|
+
wrap("verify_suggestion", async (args) => remote.verifySuggestion(args))
|
|
2192
2680
|
);
|
|
2193
2681
|
server.registerTool(
|
|
2194
2682
|
"report_outcome",
|
|
@@ -2196,7 +2684,7 @@ async function addToolsToServer(server) {
|
|
|
2196
2684
|
description: "Report the outcome of using a tool recommended by ToolCairn (fire-and-forget).",
|
|
2197
2685
|
inputSchema: reportOutcomeSchema
|
|
2198
2686
|
},
|
|
2199
|
-
|
|
2687
|
+
wrap("report_outcome", async (args) => remote.reportOutcome(args))
|
|
2200
2688
|
);
|
|
2201
2689
|
server.registerTool(
|
|
2202
2690
|
"suggest_graph_update",
|
|
@@ -2204,7 +2692,7 @@ async function addToolsToServer(server) {
|
|
|
2204
2692
|
description: "Suggest a new tool, relationship, use case, or health update to the ToolCairn graph.",
|
|
2205
2693
|
inputSchema: suggestGraphUpdateSchema
|
|
2206
2694
|
},
|
|
2207
|
-
|
|
2695
|
+
wrap("suggest_graph_update", async (args) => remote.suggestGraphUpdate(args))
|
|
2208
2696
|
);
|
|
2209
2697
|
server.registerTool(
|
|
2210
2698
|
"toolcairn_auth",
|
|
@@ -2249,7 +2737,7 @@ async function addToolsToServer(server) {
|
|
|
2249
2737
|
};
|
|
2250
2738
|
}
|
|
2251
2739
|
try {
|
|
2252
|
-
const user = await startDeviceAuth(
|
|
2740
|
+
const user = await startDeviceAuth(import_config2.config.TOOLPILOT_API_URL);
|
|
2253
2741
|
return {
|
|
2254
2742
|
content: [
|
|
2255
2743
|
{
|
|
@@ -2284,7 +2772,7 @@ async function buildProdServer() {
|
|
|
2284
2772
|
|
|
2285
2773
|
// src/transport.ts
|
|
2286
2774
|
init_esm_shims();
|
|
2287
|
-
var
|
|
2775
|
+
var import_config3 = __toESM(require_dist(), 1);
|
|
2288
2776
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2289
2777
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
2290
2778
|
function createTransport() {
|
|
@@ -2298,7 +2786,7 @@ function createTransport() {
|
|
|
2298
2786
|
|
|
2299
2787
|
// src/index.prod.ts
|
|
2300
2788
|
process.env.TOOLPILOT_MODE = "production";
|
|
2301
|
-
var logger9 =
|
|
2789
|
+
var logger9 = (0, import_errors11.createMcpLogger)({ name: "@toolcairn/mcp-server" });
|
|
2302
2790
|
async function main() {
|
|
2303
2791
|
await ensureProjectSetup();
|
|
2304
2792
|
const creds = await loadCredentials();
|
|
@@ -2317,7 +2805,7 @@ async function main() {
|
|
|
2317
2805
|
userCode = pending.user_code;
|
|
2318
2806
|
logger9.info({ userCode }, "Resuming pending sign-in");
|
|
2319
2807
|
} else {
|
|
2320
|
-
const codeData = await requestDeviceCode(
|
|
2808
|
+
const codeData = await requestDeviceCode(import_config4.config.TOOLPILOT_API_URL);
|
|
2321
2809
|
verificationUri = codeData.verification_uri;
|
|
2322
2810
|
userCode = codeData.user_code;
|
|
2323
2811
|
logger9.info({ userCode }, "New sign-in started");
|
|
@@ -2354,7 +2842,7 @@ Open the URL, sign in, and confirm the code shown. All 14 tools will appear auto
|
|
|
2354
2842
|
]
|
|
2355
2843
|
})
|
|
2356
2844
|
);
|
|
2357
|
-
startDeviceAuth(
|
|
2845
|
+
startDeviceAuth(import_config4.config.TOOLPILOT_API_URL).then(async () => {
|
|
2358
2846
|
logger9.info("Sign-in complete \u2014 adding all tools to running server");
|
|
2359
2847
|
try {
|
|
2360
2848
|
await addToolsToServer(server);
|
|
@@ -2371,7 +2859,10 @@ Open the URL, sign in, and confirm the code shown. All 14 tools will appear auto
|
|
|
2371
2859
|
logger9.info(authenticated ? "ToolCairn MCP ready" : "ToolCairn MCP ready (awaiting sign-in)");
|
|
2372
2860
|
}
|
|
2373
2861
|
main().catch((error) => {
|
|
2374
|
-
|
|
2862
|
+
(0, import_errors11.createMcpLogger)({ name: "@toolcairn/mcp-server" }).error(
|
|
2863
|
+
{ err: error },
|
|
2864
|
+
"Failed to start MCP server"
|
|
2865
|
+
);
|
|
2375
2866
|
process.exit(1);
|
|
2376
2867
|
});
|
|
2377
2868
|
//# sourceMappingURL=index.js.map
|