deepthinking-mcp 2.5.4 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +266 -14
- package/dist/index.js.map +1 -1
- package/package.json +80 -80
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
-
import { randomUUID } from 'crypto';
|
|
5
|
+
import { randomUUID, createHash } from 'crypto';
|
|
6
6
|
import { readFileSync } from 'fs';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { dirname, join } from 'path';
|
|
@@ -1201,6 +1201,187 @@ function createLogger(config) {
|
|
|
1201
1201
|
return new Logger(config);
|
|
1202
1202
|
}
|
|
1203
1203
|
|
|
1204
|
+
// src/config/index.ts
|
|
1205
|
+
var defaultConfig = {
|
|
1206
|
+
maxThoughtsInMemory: parseInt(process.env.MCP_MAX_THOUGHTS || "1000", 10),
|
|
1207
|
+
compressionThreshold: parseInt(process.env.MCP_COMPRESSION_THRESHOLD || "500", 10),
|
|
1208
|
+
maxContentLength: parseInt(process.env.MCP_MAX_CONTENT_LENGTH || "10000", 10),
|
|
1209
|
+
validationTolerance: parseFloat(process.env.MCP_VALIDATION_TOLERANCE || "0.01"),
|
|
1210
|
+
maxActiveSessions: parseInt(process.env.MCP_MAX_SESSIONS || "100", 10),
|
|
1211
|
+
sessionTimeoutMs: parseInt(process.env.MCP_SESSION_TIMEOUT_MS || "0", 10),
|
|
1212
|
+
enableValidationCache: process.env.MCP_ENABLE_VALIDATION_CACHE !== "false",
|
|
1213
|
+
validationCacheMaxSize: parseInt(process.env.MCP_VALIDATION_CACHE_SIZE || "1000", 10),
|
|
1214
|
+
enablePersistence: process.env.MCP_ENABLE_PERSISTENCE === "true",
|
|
1215
|
+
persistenceDir: process.env.MCP_PERSISTENCE_DIR || "./.deepthinking-sessions",
|
|
1216
|
+
logLevel: process.env.MCP_LOG_LEVEL || "info",
|
|
1217
|
+
enablePerformanceMetrics: process.env.MCP_ENABLE_PERF_METRICS === "true"
|
|
1218
|
+
};
|
|
1219
|
+
var activeConfig = { ...defaultConfig };
|
|
1220
|
+
function getConfig() {
|
|
1221
|
+
return Object.freeze({ ...activeConfig });
|
|
1222
|
+
}
|
|
1223
|
+
function validateConfig(config) {
|
|
1224
|
+
if (config.maxThoughtsInMemory < 1) {
|
|
1225
|
+
throw new Error("maxThoughtsInMemory must be at least 1");
|
|
1226
|
+
}
|
|
1227
|
+
if (config.compressionThreshold < 0) {
|
|
1228
|
+
throw new Error("compressionThreshold must be non-negative");
|
|
1229
|
+
}
|
|
1230
|
+
if (config.maxContentLength < 1) {
|
|
1231
|
+
throw new Error("maxContentLength must be at least 1");
|
|
1232
|
+
}
|
|
1233
|
+
if (config.validationTolerance < 0 || config.validationTolerance > 1) {
|
|
1234
|
+
throw new Error("validationTolerance must be between 0 and 1");
|
|
1235
|
+
}
|
|
1236
|
+
if (config.maxActiveSessions < 1) {
|
|
1237
|
+
throw new Error("maxActiveSessions must be at least 1");
|
|
1238
|
+
}
|
|
1239
|
+
if (config.sessionTimeoutMs < 0) {
|
|
1240
|
+
throw new Error("sessionTimeoutMs must be non-negative");
|
|
1241
|
+
}
|
|
1242
|
+
if (config.validationCacheMaxSize < 0) {
|
|
1243
|
+
throw new Error("validationCacheMaxSize must be non-negative");
|
|
1244
|
+
}
|
|
1245
|
+
if (!["debug", "info", "warn", "error"].includes(config.logLevel)) {
|
|
1246
|
+
throw new Error("logLevel must be one of: debug, info, warn, error");
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
validateConfig(activeConfig);
|
|
1250
|
+
var ValidationCache = class {
|
|
1251
|
+
cache;
|
|
1252
|
+
maxSize;
|
|
1253
|
+
hits = 0;
|
|
1254
|
+
misses = 0;
|
|
1255
|
+
constructor(maxSize) {
|
|
1256
|
+
const config = getConfig();
|
|
1257
|
+
this.maxSize = maxSize || config.validationCacheMaxSize;
|
|
1258
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Generate a cache key from thought content
|
|
1262
|
+
*
|
|
1263
|
+
* Uses SHA-256 hash of JSON-serialized content for reliable cache keys
|
|
1264
|
+
*
|
|
1265
|
+
* @param content - Content to hash
|
|
1266
|
+
* @returns Cache key
|
|
1267
|
+
*/
|
|
1268
|
+
generateKey(content) {
|
|
1269
|
+
const json = JSON.stringify(content);
|
|
1270
|
+
return createHash("sha256").update(json).digest("hex");
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Get validation result from cache
|
|
1274
|
+
*
|
|
1275
|
+
* @param content - Content to look up
|
|
1276
|
+
* @returns Cached result or undefined if not found
|
|
1277
|
+
*/
|
|
1278
|
+
get(content) {
|
|
1279
|
+
const key = this.generateKey(content);
|
|
1280
|
+
const entry = this.cache.get(key);
|
|
1281
|
+
if (entry) {
|
|
1282
|
+
this.hits++;
|
|
1283
|
+
entry.hitCount++;
|
|
1284
|
+
this.cache.delete(key);
|
|
1285
|
+
this.cache.set(key, entry);
|
|
1286
|
+
return entry;
|
|
1287
|
+
}
|
|
1288
|
+
this.misses++;
|
|
1289
|
+
return void 0;
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Store validation result in cache
|
|
1293
|
+
*
|
|
1294
|
+
* @param content - Content that was validated
|
|
1295
|
+
* @param result - Validation result to cache
|
|
1296
|
+
*/
|
|
1297
|
+
set(content, result) {
|
|
1298
|
+
const key = this.generateKey(content);
|
|
1299
|
+
if (this.cache.size >= this.maxSize) {
|
|
1300
|
+
const firstKey = this.cache.keys().next().value;
|
|
1301
|
+
if (firstKey !== void 0) {
|
|
1302
|
+
this.cache.delete(firstKey);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
const entry = {
|
|
1306
|
+
result,
|
|
1307
|
+
timestamp: Date.now(),
|
|
1308
|
+
hitCount: 0
|
|
1309
|
+
};
|
|
1310
|
+
this.cache.set(key, entry);
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Check if content is in cache
|
|
1314
|
+
*
|
|
1315
|
+
* @param content - Content to check
|
|
1316
|
+
* @returns true if cached
|
|
1317
|
+
*/
|
|
1318
|
+
has(content) {
|
|
1319
|
+
const key = this.generateKey(content);
|
|
1320
|
+
return this.cache.has(key);
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Clear all cached validation results
|
|
1324
|
+
*/
|
|
1325
|
+
clear() {
|
|
1326
|
+
this.cache.clear();
|
|
1327
|
+
this.hits = 0;
|
|
1328
|
+
this.misses = 0;
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Get cache statistics
|
|
1332
|
+
*/
|
|
1333
|
+
getStats() {
|
|
1334
|
+
const total = this.hits + this.misses;
|
|
1335
|
+
return {
|
|
1336
|
+
size: this.cache.size,
|
|
1337
|
+
maxSize: this.maxSize,
|
|
1338
|
+
hits: this.hits,
|
|
1339
|
+
misses: this.misses,
|
|
1340
|
+
hitRate: total > 0 ? this.hits / total : 0
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Resize the cache
|
|
1345
|
+
*
|
|
1346
|
+
* @param newSize - New maximum cache size
|
|
1347
|
+
*/
|
|
1348
|
+
resize(newSize) {
|
|
1349
|
+
this.maxSize = newSize;
|
|
1350
|
+
if (this.cache.size > newSize) {
|
|
1351
|
+
const keysToDelete = this.cache.size - newSize;
|
|
1352
|
+
const keys = Array.from(this.cache.keys());
|
|
1353
|
+
for (let i = 0; i < keysToDelete; i++) {
|
|
1354
|
+
this.cache.delete(keys[i]);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Get entries sorted by hit count (most used first)
|
|
1360
|
+
*/
|
|
1361
|
+
getTopEntries(limit = 10) {
|
|
1362
|
+
const entries = Array.from(this.cache.entries()).map(([key, entry]) => ({ key, entry })).sort((a, b) => b.entry.hitCount - a.entry.hitCount);
|
|
1363
|
+
return entries.slice(0, limit);
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Remove entries older than a certain age
|
|
1367
|
+
*
|
|
1368
|
+
* @param maxAgeMs - Maximum age in milliseconds
|
|
1369
|
+
* @returns Number of entries removed
|
|
1370
|
+
*/
|
|
1371
|
+
evictOld(maxAgeMs) {
|
|
1372
|
+
const now = Date.now();
|
|
1373
|
+
let removed = 0;
|
|
1374
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
1375
|
+
if (now - entry.timestamp > maxAgeMs) {
|
|
1376
|
+
this.cache.delete(key);
|
|
1377
|
+
removed++;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
return removed;
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
var validationCache = new ValidationCache();
|
|
1384
|
+
|
|
1204
1385
|
// src/session/manager.ts
|
|
1205
1386
|
var DEFAULT_CONFIG2 = {
|
|
1206
1387
|
modeConfig: {
|
|
@@ -1543,7 +1724,14 @@ var SessionManager = class {
|
|
|
1543
1724
|
revisionCount: 0,
|
|
1544
1725
|
timeSpent: 0,
|
|
1545
1726
|
dependencyDepth: 0,
|
|
1546
|
-
customMetrics: /* @__PURE__ */ new Map()
|
|
1727
|
+
customMetrics: /* @__PURE__ */ new Map(),
|
|
1728
|
+
cacheStats: {
|
|
1729
|
+
hits: 0,
|
|
1730
|
+
misses: 0,
|
|
1731
|
+
hitRate: 0,
|
|
1732
|
+
size: 0,
|
|
1733
|
+
maxSize: 0
|
|
1734
|
+
}
|
|
1547
1735
|
};
|
|
1548
1736
|
}
|
|
1549
1737
|
/**
|
|
@@ -1558,6 +1746,8 @@ var SessionManager = class {
|
|
|
1558
1746
|
updateMetrics(session, thought) {
|
|
1559
1747
|
const metrics = session.metrics;
|
|
1560
1748
|
metrics.totalThoughts = session.thoughts.length;
|
|
1749
|
+
const thoughtType = thought.type || "unknown";
|
|
1750
|
+
metrics.thoughtsByType[thoughtType] = (metrics.thoughtsByType[thoughtType] || 0) + 1;
|
|
1561
1751
|
if (thought.isRevision) {
|
|
1562
1752
|
metrics.revisionCount++;
|
|
1563
1753
|
}
|
|
@@ -1638,6 +1828,22 @@ var SessionManager = class {
|
|
|
1638
1828
|
metrics.customMetrics.set("decisions", thought.decisions.length);
|
|
1639
1829
|
}
|
|
1640
1830
|
}
|
|
1831
|
+
this.updateCacheStats(session);
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Update validation cache statistics in session metrics
|
|
1835
|
+
*
|
|
1836
|
+
* @param session - Session to update
|
|
1837
|
+
*/
|
|
1838
|
+
updateCacheStats(session) {
|
|
1839
|
+
const cacheStats = validationCache.getStats();
|
|
1840
|
+
session.metrics.cacheStats = {
|
|
1841
|
+
hits: cacheStats.hits,
|
|
1842
|
+
misses: cacheStats.misses,
|
|
1843
|
+
hitRate: cacheStats.hitRate,
|
|
1844
|
+
size: cacheStats.size,
|
|
1845
|
+
maxSize: cacheStats.maxSize
|
|
1846
|
+
};
|
|
1641
1847
|
}
|
|
1642
1848
|
};
|
|
1643
1849
|
|
|
@@ -2085,6 +2291,52 @@ Bayes Factor: ${thought.bayesFactor.toFixed(2)}
|
|
|
2085
2291
|
}
|
|
2086
2292
|
};
|
|
2087
2293
|
|
|
2294
|
+
// src/utils/type-guards.ts
|
|
2295
|
+
var VALID_THOUGHT_TYPES = [
|
|
2296
|
+
"problem_definition",
|
|
2297
|
+
"constraints",
|
|
2298
|
+
"model",
|
|
2299
|
+
"proof",
|
|
2300
|
+
"implementation",
|
|
2301
|
+
"axiom_definition",
|
|
2302
|
+
"theorem_statement",
|
|
2303
|
+
"proof_construction",
|
|
2304
|
+
"lemma_derivation",
|
|
2305
|
+
"corollary",
|
|
2306
|
+
"counterexample",
|
|
2307
|
+
"algebraic_manipulation",
|
|
2308
|
+
"symbolic_computation",
|
|
2309
|
+
"numerical_analysis",
|
|
2310
|
+
"symmetry_analysis",
|
|
2311
|
+
"gauge_theory",
|
|
2312
|
+
"field_equations",
|
|
2313
|
+
"lagrangian",
|
|
2314
|
+
"hamiltonian",
|
|
2315
|
+
"conservation_law",
|
|
2316
|
+
"dimensional_analysis",
|
|
2317
|
+
"tensor_formulation",
|
|
2318
|
+
"differential_geometry",
|
|
2319
|
+
"decomposition",
|
|
2320
|
+
"synthesis",
|
|
2321
|
+
"abstraction",
|
|
2322
|
+
"analogy",
|
|
2323
|
+
"metacognition"
|
|
2324
|
+
];
|
|
2325
|
+
function isExtendedThoughtType(value) {
|
|
2326
|
+
return typeof value === "string" && VALID_THOUGHT_TYPES.includes(value);
|
|
2327
|
+
}
|
|
2328
|
+
function toExtendedThoughtType(value, fallback) {
|
|
2329
|
+
if (isExtendedThoughtType(value)) {
|
|
2330
|
+
return value;
|
|
2331
|
+
}
|
|
2332
|
+
if (fallback !== void 0) {
|
|
2333
|
+
return fallback;
|
|
2334
|
+
}
|
|
2335
|
+
throw new Error(
|
|
2336
|
+
`Invalid ExtendedThoughtType: ${value}. Must be one of: ${VALID_THOUGHT_TYPES.join(", ")}`
|
|
2337
|
+
);
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2088
2340
|
// src/index.ts
|
|
2089
2341
|
var __filename2 = fileURLToPath(import.meta.url);
|
|
2090
2342
|
var __dirname2 = dirname(__filename2);
|
|
@@ -2351,7 +2603,7 @@ function createThought(input, sessionId) {
|
|
|
2351
2603
|
return {
|
|
2352
2604
|
...baseThought,
|
|
2353
2605
|
mode: "mathematics" /* MATHEMATICS */,
|
|
2354
|
-
thoughtType: input.thoughtType,
|
|
2606
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "model"),
|
|
2355
2607
|
mathematicalModel: input.mathematicalModel,
|
|
2356
2608
|
proofStrategy: input.proofStrategy,
|
|
2357
2609
|
dependencies: input.dependencies || [],
|
|
@@ -2362,7 +2614,7 @@ function createThought(input, sessionId) {
|
|
|
2362
2614
|
return {
|
|
2363
2615
|
...baseThought,
|
|
2364
2616
|
mode: "physics" /* PHYSICS */,
|
|
2365
|
-
thoughtType: input.thoughtType,
|
|
2617
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "model"),
|
|
2366
2618
|
tensorProperties: input.tensorProperties,
|
|
2367
2619
|
physicalInterpretation: input.physicalInterpretation,
|
|
2368
2620
|
dependencies: input.dependencies || [],
|
|
@@ -2373,7 +2625,7 @@ function createThought(input, sessionId) {
|
|
|
2373
2625
|
return {
|
|
2374
2626
|
...baseThought,
|
|
2375
2627
|
mode: "abductive" /* ABDUCTIVE */,
|
|
2376
|
-
thoughtType: input.thoughtType,
|
|
2628
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
|
|
2377
2629
|
observations: input.observations || [],
|
|
2378
2630
|
hypotheses: input.hypotheses || [],
|
|
2379
2631
|
evaluationCriteria: input.evaluationCriteria,
|
|
@@ -2384,7 +2636,7 @@ function createThought(input, sessionId) {
|
|
|
2384
2636
|
return {
|
|
2385
2637
|
...baseThought,
|
|
2386
2638
|
mode: "causal" /* CAUSAL */,
|
|
2387
|
-
thoughtType: input.thoughtType,
|
|
2639
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
|
|
2388
2640
|
causalGraph: input.causalGraph,
|
|
2389
2641
|
interventions: input.interventions || [],
|
|
2390
2642
|
mechanisms: input.mechanisms || [],
|
|
@@ -2394,7 +2646,7 @@ function createThought(input, sessionId) {
|
|
|
2394
2646
|
return {
|
|
2395
2647
|
...baseThought,
|
|
2396
2648
|
mode: "bayesian" /* BAYESIAN */,
|
|
2397
|
-
thoughtType: input.thoughtType,
|
|
2649
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
|
|
2398
2650
|
hypothesis: input.hypothesis,
|
|
2399
2651
|
prior: input.prior,
|
|
2400
2652
|
likelihood: input.likelihood,
|
|
@@ -2406,7 +2658,7 @@ function createThought(input, sessionId) {
|
|
|
2406
2658
|
return {
|
|
2407
2659
|
...baseThought,
|
|
2408
2660
|
mode: "counterfactual" /* COUNTERFACTUAL */,
|
|
2409
|
-
thoughtType: input.thoughtType,
|
|
2661
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
|
|
2410
2662
|
actual: input.actual,
|
|
2411
2663
|
counterfactuals: input.counterfactuals || [],
|
|
2412
2664
|
comparison: input.comparison,
|
|
@@ -2417,7 +2669,7 @@ function createThought(input, sessionId) {
|
|
|
2417
2669
|
return {
|
|
2418
2670
|
...baseThought,
|
|
2419
2671
|
mode: "analogical" /* ANALOGICAL */,
|
|
2420
|
-
thoughtType: input.thoughtType,
|
|
2672
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "analogy"),
|
|
2421
2673
|
sourceDomain: input.sourceDomain,
|
|
2422
2674
|
targetDomain: input.targetDomain,
|
|
2423
2675
|
mapping: input.mapping || [],
|
|
@@ -2430,7 +2682,7 @@ function createThought(input, sessionId) {
|
|
|
2430
2682
|
return {
|
|
2431
2683
|
...baseThought,
|
|
2432
2684
|
mode: "temporal" /* TEMPORAL */,
|
|
2433
|
-
thoughtType: input.thoughtType,
|
|
2685
|
+
thoughtType: input.thoughtType || "event_definition",
|
|
2434
2686
|
timeline: input.timeline,
|
|
2435
2687
|
events: input.events || [],
|
|
2436
2688
|
intervals: input.intervals || [],
|
|
@@ -2441,7 +2693,7 @@ function createThought(input, sessionId) {
|
|
|
2441
2693
|
return {
|
|
2442
2694
|
...baseThought,
|
|
2443
2695
|
mode: "gametheory" /* GAMETHEORY */,
|
|
2444
|
-
thoughtType: input.thoughtType,
|
|
2696
|
+
thoughtType: input.thoughtType || "game_definition",
|
|
2445
2697
|
game: input.game,
|
|
2446
2698
|
players: input.players || [],
|
|
2447
2699
|
strategies: input.strategies || [],
|
|
@@ -2454,7 +2706,7 @@ function createThought(input, sessionId) {
|
|
|
2454
2706
|
return {
|
|
2455
2707
|
...baseThought,
|
|
2456
2708
|
mode: "evidential" /* EVIDENTIAL */,
|
|
2457
|
-
thoughtType: input.thoughtType,
|
|
2709
|
+
thoughtType: input.thoughtType || "hypothesis_definition",
|
|
2458
2710
|
frameOfDiscernment: input.frameOfDiscernment,
|
|
2459
2711
|
hypotheses: input.hypotheses || [],
|
|
2460
2712
|
evidence: input.evidence || [],
|
|
@@ -2468,7 +2720,7 @@ function createThought(input, sessionId) {
|
|
|
2468
2720
|
return {
|
|
2469
2721
|
...baseThought,
|
|
2470
2722
|
mode: "hybrid" /* HYBRID */,
|
|
2471
|
-
thoughtType: input.thoughtType,
|
|
2723
|
+
thoughtType: toExtendedThoughtType(input.thoughtType, "synthesis"),
|
|
2472
2724
|
stage: input.stage,
|
|
2473
2725
|
uncertainty: input.uncertainty,
|
|
2474
2726
|
dependencies: input.dependencies,
|
|
@@ -2476,7 +2728,7 @@ function createThought(input, sessionId) {
|
|
|
2476
2728
|
mathematicalModel: input.mathematicalModel,
|
|
2477
2729
|
tensorProperties: input.tensorProperties,
|
|
2478
2730
|
physicalInterpretation: input.physicalInterpretation,
|
|
2479
|
-
primaryMode: input.mode
|
|
2731
|
+
primaryMode: input.mode || "hybrid" /* HYBRID */,
|
|
2480
2732
|
secondaryFeatures: []
|
|
2481
2733
|
};
|
|
2482
2734
|
}
|