deepthinking-mcp 2.5.4 → 2.5.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/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';
@@ -442,7 +442,7 @@ Phase 3 Modes (v2.1+):
442
442
  Actions:
443
443
  - add_thought: Add a new thought to the session (default)
444
444
  - summarize: Generate a summary of the session
445
- - export: Export session in various formats (markdown, latex, json, html, jupyter)
445
+ - export: Export session in various formats (markdown, latex, json, html, jupyter, mermaid, dot, ascii)
446
446
  - switch_mode: Change reasoning mode mid-session
447
447
  - get_session: Retrieve session information
448
448
  - recommend_mode: Get intelligent mode recommendations based on problem characteristics
@@ -709,6 +709,99 @@ Choose the mode that best fits your problem type, or use recommend_mode to get i
709
709
  },
710
710
  description: "Temporal causal/enabling relations"
711
711
  },
712
+ // Game theory properties (Phase 3, v2.2)
713
+ players: {
714
+ type: "array",
715
+ items: {
716
+ type: "object",
717
+ properties: {
718
+ id: { type: "string" },
719
+ name: { type: "string" },
720
+ role: { type: "string" },
721
+ isRational: { type: "boolean" },
722
+ availableStrategies: {
723
+ type: "array",
724
+ items: { type: "string" }
725
+ }
726
+ },
727
+ required: ["id", "name", "isRational", "availableStrategies"]
728
+ },
729
+ description: "Players in the game"
730
+ },
731
+ strategies: {
732
+ type: "array",
733
+ items: {
734
+ type: "object",
735
+ properties: {
736
+ id: { type: "string" },
737
+ playerId: { type: "string" },
738
+ name: { type: "string" },
739
+ description: { type: "string" },
740
+ isPure: { type: "boolean" },
741
+ probability: { type: "number", minimum: 0, maximum: 1 }
742
+ },
743
+ required: ["id", "playerId", "name", "description", "isPure"]
744
+ },
745
+ description: "Available strategies"
746
+ },
747
+ payoffMatrix: {
748
+ type: "object",
749
+ properties: {
750
+ players: {
751
+ type: "array",
752
+ items: { type: "string" }
753
+ },
754
+ dimensions: {
755
+ type: "array",
756
+ items: { type: "number" }
757
+ },
758
+ payoffs: {
759
+ type: "array",
760
+ items: {
761
+ type: "object",
762
+ properties: {
763
+ strategyProfile: {
764
+ type: "array",
765
+ items: { type: "string" }
766
+ },
767
+ payoffs: {
768
+ type: "array",
769
+ items: { type: "number" }
770
+ }
771
+ },
772
+ required: ["strategyProfile", "payoffs"]
773
+ }
774
+ }
775
+ },
776
+ required: ["players", "dimensions", "payoffs"],
777
+ description: "Payoff matrix for the game"
778
+ },
779
+ // Evidential reasoning properties (Phase 3, v2.3)
780
+ frameOfDiscernment: {
781
+ type: "array",
782
+ items: { type: "string" },
783
+ description: "Frame of discernment (set of all possible hypotheses)"
784
+ },
785
+ beliefMasses: {
786
+ type: "array",
787
+ items: {
788
+ type: "object",
789
+ properties: {
790
+ hypothesisSet: {
791
+ type: "array",
792
+ items: { type: "string" }
793
+ },
794
+ mass: {
795
+ type: "number",
796
+ minimum: 0,
797
+ maximum: 1
798
+ },
799
+ justification: { type: "string" }
800
+ },
801
+ required: ["hypothesisSet", "mass", "justification"]
802
+ },
803
+ description: "Belief mass assignments (Dempster-Shafer)"
804
+ },
712
805
  action: {
713
806
  type: "string",
714
807
  enum: ["add_thought", "summarize", "export", "switch_mode", "get_session", "recommend_mode"],
@@ -1201,6 +1294,187 @@ function createLogger(config) {
1201
1294
  return new Logger(config);
1202
1295
  }
1203
1296
 
1297
+ // src/config/index.ts
1298
+ var defaultConfig = {
1299
+ maxThoughtsInMemory: parseInt(process.env.MCP_MAX_THOUGHTS || "1000", 10),
1300
+ compressionThreshold: parseInt(process.env.MCP_COMPRESSION_THRESHOLD || "500", 10),
1301
+ maxContentLength: parseInt(process.env.MCP_MAX_CONTENT_LENGTH || "10000", 10),
1302
+ validationTolerance: parseFloat(process.env.MCP_VALIDATION_TOLERANCE || "0.01"),
1303
+ maxActiveSessions: parseInt(process.env.MCP_MAX_SESSIONS || "100", 10),
1304
+ sessionTimeoutMs: parseInt(process.env.MCP_SESSION_TIMEOUT_MS || "0", 10),
1305
+ enableValidationCache: process.env.MCP_ENABLE_VALIDATION_CACHE !== "false",
1306
+ validationCacheMaxSize: parseInt(process.env.MCP_VALIDATION_CACHE_SIZE || "1000", 10),
1307
+ enablePersistence: process.env.MCP_ENABLE_PERSISTENCE === "true",
1308
+ persistenceDir: process.env.MCP_PERSISTENCE_DIR || "./.deepthinking-sessions",
1309
+ logLevel: process.env.MCP_LOG_LEVEL || "info",
1310
+ enablePerformanceMetrics: process.env.MCP_ENABLE_PERF_METRICS === "true"
1311
+ };
1312
+ var activeConfig = { ...defaultConfig };
1313
+ function getConfig() {
1314
+ return Object.freeze({ ...activeConfig });
1315
+ }
1316
+ function validateConfig(config) {
1317
+ if (config.maxThoughtsInMemory < 1) {
1318
+ throw new Error("maxThoughtsInMemory must be at least 1");
1319
+ }
1320
+ if (config.compressionThreshold < 0) {
1321
+ throw new Error("compressionThreshold must be non-negative");
1322
+ }
1323
+ if (config.maxContentLength < 1) {
1324
+ throw new Error("maxContentLength must be at least 1");
1325
+ }
1326
+ if (config.validationTolerance < 0 || config.validationTolerance > 1) {
1327
+ throw new Error("validationTolerance must be between 0 and 1");
1328
+ }
1329
+ if (config.maxActiveSessions < 1) {
1330
+ throw new Error("maxActiveSessions must be at least 1");
1331
+ }
1332
+ if (config.sessionTimeoutMs < 0) {
1333
+ throw new Error("sessionTimeoutMs must be non-negative");
1334
+ }
1335
+ if (config.validationCacheMaxSize < 0) {
1336
+ throw new Error("validationCacheMaxSize must be non-negative");
1337
+ }
1338
+ if (!["debug", "info", "warn", "error"].includes(config.logLevel)) {
1339
+ throw new Error("logLevel must be one of: debug, info, warn, error");
1340
+ }
1341
+ }
1342
+ validateConfig(activeConfig);
1343
+ var ValidationCache = class {
1344
+ cache;
1345
+ maxSize;
1346
+ hits = 0;
1347
+ misses = 0;
1348
+ constructor(maxSize) {
1349
+ const config = getConfig();
1350
+ this.maxSize = maxSize || config.validationCacheMaxSize;
1351
+ this.cache = /* @__PURE__ */ new Map();
1352
+ }
1353
+ /**
1354
+ * Generate a cache key from thought content
1355
+ *
1356
+ * Uses SHA-256 hash of JSON-serialized content for reliable cache keys
1357
+ *
1358
+ * @param content - Content to hash
1359
+ * @returns Cache key
1360
+ */
1361
+ generateKey(content) {
1362
+ const json = JSON.stringify(content);
1363
+ return createHash("sha256").update(json).digest("hex");
1364
+ }
1365
+ /**
1366
+ * Get validation result from cache
1367
+ *
1368
+ * @param content - Content to look up
1369
+ * @returns Cached result or undefined if not found
1370
+ */
1371
+ get(content) {
1372
+ const key = this.generateKey(content);
1373
+ const entry = this.cache.get(key);
1374
+ if (entry) {
1375
+ this.hits++;
1376
+ entry.hitCount++;
1377
+ this.cache.delete(key);
1378
+ this.cache.set(key, entry);
1379
+ return entry;
1380
+ }
1381
+ this.misses++;
1382
+ return void 0;
1383
+ }
1384
+ /**
1385
+ * Store validation result in cache
1386
+ *
1387
+ * @param content - Content that was validated
1388
+ * @param result - Validation result to cache
1389
+ */
1390
+ set(content, result) {
1391
+ const key = this.generateKey(content);
1392
+ if (this.cache.size >= this.maxSize) {
1393
+ const firstKey = this.cache.keys().next().value;
1394
+ if (firstKey !== void 0) {
1395
+ this.cache.delete(firstKey);
1396
+ }
1397
+ }
1398
+ const entry = {
1399
+ result,
1400
+ timestamp: Date.now(),
1401
+ hitCount: 0
1402
+ };
1403
+ this.cache.set(key, entry);
1404
+ }
1405
+ /**
1406
+ * Check if content is in cache
1407
+ *
1408
+ * @param content - Content to check
1409
+ * @returns true if cached
1410
+ */
1411
+ has(content) {
1412
+ const key = this.generateKey(content);
1413
+ return this.cache.has(key);
1414
+ }
1415
+ /**
1416
+ * Clear all cached validation results
1417
+ */
1418
+ clear() {
1419
+ this.cache.clear();
1420
+ this.hits = 0;
1421
+ this.misses = 0;
1422
+ }
1423
+ /**
1424
+ * Get cache statistics
1425
+ */
1426
+ getStats() {
1427
+ const total = this.hits + this.misses;
1428
+ return {
1429
+ size: this.cache.size,
1430
+ maxSize: this.maxSize,
1431
+ hits: this.hits,
1432
+ misses: this.misses,
1433
+ hitRate: total > 0 ? this.hits / total : 0
1434
+ };
1435
+ }
1436
+ /**
1437
+ * Resize the cache
1438
+ *
1439
+ * @param newSize - New maximum cache size
1440
+ */
1441
+ resize(newSize) {
1442
+ this.maxSize = newSize;
1443
+ if (this.cache.size > newSize) {
1444
+ const keysToDelete = this.cache.size - newSize;
1445
+ const keys = Array.from(this.cache.keys());
1446
+ for (let i = 0; i < keysToDelete; i++) {
1447
+ this.cache.delete(keys[i]);
1448
+ }
1449
+ }
1450
+ }
1451
+ /**
1452
+ * Get entries sorted by hit count (most used first)
1453
+ */
1454
+ getTopEntries(limit = 10) {
1455
+ const entries = Array.from(this.cache.entries()).map(([key, entry]) => ({ key, entry })).sort((a, b) => b.entry.hitCount - a.entry.hitCount);
1456
+ return entries.slice(0, limit);
1457
+ }
1458
+ /**
1459
+ * Remove entries older than a certain age
1460
+ *
1461
+ * @param maxAgeMs - Maximum age in milliseconds
1462
+ * @returns Number of entries removed
1463
+ */
1464
+ evictOld(maxAgeMs) {
1465
+ const now = Date.now();
1466
+ let removed = 0;
1467
+ for (const [key, entry] of this.cache.entries()) {
1468
+ if (now - entry.timestamp > maxAgeMs) {
1469
+ this.cache.delete(key);
1470
+ removed++;
1471
+ }
1472
+ }
1473
+ return removed;
1474
+ }
1475
+ };
1476
+ var validationCache = new ValidationCache();
1477
+
1204
1478
  // src/session/manager.ts
1205
1479
  var DEFAULT_CONFIG2 = {
1206
1480
  modeConfig: {
@@ -1543,7 +1817,14 @@ var SessionManager = class {
1543
1817
  revisionCount: 0,
1544
1818
  timeSpent: 0,
1545
1819
  dependencyDepth: 0,
1546
- customMetrics: /* @__PURE__ */ new Map()
1820
+ customMetrics: /* @__PURE__ */ new Map(),
1821
+ cacheStats: {
1822
+ hits: 0,
1823
+ misses: 0,
1824
+ hitRate: 0,
1825
+ size: 0,
1826
+ maxSize: 0
1827
+ }
1547
1828
  };
1548
1829
  }
1549
1830
  /**
@@ -1558,6 +1839,8 @@ var SessionManager = class {
1558
1839
  updateMetrics(session, thought) {
1559
1840
  const metrics = session.metrics;
1560
1841
  metrics.totalThoughts = session.thoughts.length;
1842
+ const thoughtType = thought.type || "unknown";
1843
+ metrics.thoughtsByType[thoughtType] = (metrics.thoughtsByType[thoughtType] || 0) + 1;
1561
1844
  if (thought.isRevision) {
1562
1845
  metrics.revisionCount++;
1563
1846
  }
@@ -1638,6 +1921,22 @@ var SessionManager = class {
1638
1921
  metrics.customMetrics.set("decisions", thought.decisions.length);
1639
1922
  }
1640
1923
  }
1924
+ this.updateCacheStats(session);
1925
+ }
1926
+ /**
1927
+ * Update validation cache statistics in session metrics
1928
+ *
1929
+ * @param session - Session to update
1930
+ */
1931
+ updateCacheStats(session) {
1932
+ const cacheStats = validationCache.getStats();
1933
+ session.metrics.cacheStats = {
1934
+ hits: cacheStats.hits,
1935
+ misses: cacheStats.misses,
1936
+ hitRate: cacheStats.hitRate,
1937
+ size: cacheStats.size,
1938
+ maxSize: cacheStats.maxSize
1939
+ };
1641
1940
  }
1642
1941
  };
1643
1942
 
@@ -2085,6 +2384,52 @@ Bayes Factor: ${thought.bayesFactor.toFixed(2)}
2085
2384
  }
2086
2385
  };
2087
2386
 
2387
+ // src/utils/type-guards.ts
2388
+ var VALID_THOUGHT_TYPES = [
2389
+ "problem_definition",
2390
+ "constraints",
2391
+ "model",
2392
+ "proof",
2393
+ "implementation",
2394
+ "axiom_definition",
2395
+ "theorem_statement",
2396
+ "proof_construction",
2397
+ "lemma_derivation",
2398
+ "corollary",
2399
+ "counterexample",
2400
+ "algebraic_manipulation",
2401
+ "symbolic_computation",
2402
+ "numerical_analysis",
2403
+ "symmetry_analysis",
2404
+ "gauge_theory",
2405
+ "field_equations",
2406
+ "lagrangian",
2407
+ "hamiltonian",
2408
+ "conservation_law",
2409
+ "dimensional_analysis",
2410
+ "tensor_formulation",
2411
+ "differential_geometry",
2412
+ "decomposition",
2413
+ "synthesis",
2414
+ "abstraction",
2415
+ "analogy",
2416
+ "metacognition"
2417
+ ];
2418
+ function isExtendedThoughtType(value) {
2419
+ return typeof value === "string" && VALID_THOUGHT_TYPES.includes(value);
2420
+ }
2421
+ function toExtendedThoughtType(value, fallback) {
2422
+ if (isExtendedThoughtType(value)) {
2423
+ return value;
2424
+ }
2425
+ if (fallback !== void 0) {
2426
+ return fallback;
2427
+ }
2428
+ throw new Error(
2429
+ `Invalid ExtendedThoughtType: ${value}. Must be one of: ${VALID_THOUGHT_TYPES.join(", ")}`
2430
+ );
2431
+ }
2432
+
2088
2433
  // src/index.ts
2089
2434
  var __filename2 = fileURLToPath(import.meta.url);
2090
2435
  var __dirname2 = dirname(__filename2);
@@ -2351,7 +2696,7 @@ function createThought(input, sessionId) {
2351
2696
  return {
2352
2697
  ...baseThought,
2353
2698
  mode: "mathematics" /* MATHEMATICS */,
2354
- thoughtType: input.thoughtType,
2699
+ thoughtType: toExtendedThoughtType(input.thoughtType, "model"),
2355
2700
  mathematicalModel: input.mathematicalModel,
2356
2701
  proofStrategy: input.proofStrategy,
2357
2702
  dependencies: input.dependencies || [],
@@ -2362,7 +2707,7 @@ function createThought(input, sessionId) {
2362
2707
  return {
2363
2708
  ...baseThought,
2364
2709
  mode: "physics" /* PHYSICS */,
2365
- thoughtType: input.thoughtType,
2710
+ thoughtType: toExtendedThoughtType(input.thoughtType, "model"),
2366
2711
  tensorProperties: input.tensorProperties,
2367
2712
  physicalInterpretation: input.physicalInterpretation,
2368
2713
  dependencies: input.dependencies || [],
@@ -2373,7 +2718,7 @@ function createThought(input, sessionId) {
2373
2718
  return {
2374
2719
  ...baseThought,
2375
2720
  mode: "abductive" /* ABDUCTIVE */,
2376
- thoughtType: input.thoughtType,
2721
+ thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
2377
2722
  observations: input.observations || [],
2378
2723
  hypotheses: input.hypotheses || [],
2379
2724
  evaluationCriteria: input.evaluationCriteria,
@@ -2384,7 +2729,7 @@ function createThought(input, sessionId) {
2384
2729
  return {
2385
2730
  ...baseThought,
2386
2731
  mode: "causal" /* CAUSAL */,
2387
- thoughtType: input.thoughtType,
2732
+ thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
2388
2733
  causalGraph: input.causalGraph,
2389
2734
  interventions: input.interventions || [],
2390
2735
  mechanisms: input.mechanisms || [],
@@ -2394,7 +2739,7 @@ function createThought(input, sessionId) {
2394
2739
  return {
2395
2740
  ...baseThought,
2396
2741
  mode: "bayesian" /* BAYESIAN */,
2397
- thoughtType: input.thoughtType,
2742
+ thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
2398
2743
  hypothesis: input.hypothesis,
2399
2744
  prior: input.prior,
2400
2745
  likelihood: input.likelihood,
@@ -2406,7 +2751,7 @@ function createThought(input, sessionId) {
2406
2751
  return {
2407
2752
  ...baseThought,
2408
2753
  mode: "counterfactual" /* COUNTERFACTUAL */,
2409
- thoughtType: input.thoughtType,
2754
+ thoughtType: toExtendedThoughtType(input.thoughtType, "problem_definition"),
2410
2755
  actual: input.actual,
2411
2756
  counterfactuals: input.counterfactuals || [],
2412
2757
  comparison: input.comparison,
@@ -2417,7 +2762,7 @@ function createThought(input, sessionId) {
2417
2762
  return {
2418
2763
  ...baseThought,
2419
2764
  mode: "analogical" /* ANALOGICAL */,
2420
- thoughtType: input.thoughtType,
2765
+ thoughtType: toExtendedThoughtType(input.thoughtType, "analogy"),
2421
2766
  sourceDomain: input.sourceDomain,
2422
2767
  targetDomain: input.targetDomain,
2423
2768
  mapping: input.mapping || [],
@@ -2430,7 +2775,7 @@ function createThought(input, sessionId) {
2430
2775
  return {
2431
2776
  ...baseThought,
2432
2777
  mode: "temporal" /* TEMPORAL */,
2433
- thoughtType: input.thoughtType,
2778
+ thoughtType: input.thoughtType || "event_definition",
2434
2779
  timeline: input.timeline,
2435
2780
  events: input.events || [],
2436
2781
  intervals: input.intervals || [],
@@ -2441,7 +2786,7 @@ function createThought(input, sessionId) {
2441
2786
  return {
2442
2787
  ...baseThought,
2443
2788
  mode: "gametheory" /* GAMETHEORY */,
2444
- thoughtType: input.thoughtType,
2789
+ thoughtType: input.thoughtType || "game_definition",
2445
2790
  game: input.game,
2446
2791
  players: input.players || [],
2447
2792
  strategies: input.strategies || [],
@@ -2454,7 +2799,7 @@ function createThought(input, sessionId) {
2454
2799
  return {
2455
2800
  ...baseThought,
2456
2801
  mode: "evidential" /* EVIDENTIAL */,
2457
- thoughtType: input.thoughtType,
2802
+ thoughtType: input.thoughtType || "hypothesis_definition",
2458
2803
  frameOfDiscernment: input.frameOfDiscernment,
2459
2804
  hypotheses: input.hypotheses || [],
2460
2805
  evidence: input.evidence || [],
@@ -2468,7 +2813,7 @@ function createThought(input, sessionId) {
2468
2813
  return {
2469
2814
  ...baseThought,
2470
2815
  mode: "hybrid" /* HYBRID */,
2471
- thoughtType: input.thoughtType,
2816
+ thoughtType: toExtendedThoughtType(input.thoughtType, "synthesis"),
2472
2817
  stage: input.stage,
2473
2818
  uncertainty: input.uncertainty,
2474
2819
  dependencies: input.dependencies,
@@ -2476,7 +2821,7 @@ function createThought(input, sessionId) {
2476
2821
  mathematicalModel: input.mathematicalModel,
2477
2822
  tensorProperties: input.tensorProperties,
2478
2823
  physicalInterpretation: input.physicalInterpretation,
2479
- primaryMode: input.mode,
2824
+ primaryMode: input.mode || "hybrid" /* HYBRID */,
2480
2825
  secondaryFeatures: []
2481
2826
  };
2482
2827
  }