@j0hanz/cortex-mcp 1.3.0 → 1.5.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.
Files changed (100) hide show
  1. package/dist/engine/config.d.ts +5 -5
  2. package/dist/engine/config.js +14 -5
  3. package/dist/engine/context.d.ts +0 -2
  4. package/dist/engine/context.js +0 -4
  5. package/dist/engine/events.d.ts +1 -2
  6. package/dist/engine/events.js +2 -4
  7. package/dist/engine/heuristics.d.ts +4 -0
  8. package/dist/engine/heuristics.js +65 -0
  9. package/dist/engine/reasoner.d.ts +7 -2
  10. package/dist/engine/reasoner.js +41 -103
  11. package/dist/engine/session-store.d.ts +6 -2
  12. package/dist/engine/session-store.js +78 -27
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.js +0 -1
  15. package/dist/lib/concurrency.d.ts +5 -0
  16. package/dist/lib/concurrency.js +17 -0
  17. package/dist/lib/errors.d.ts +23 -8
  18. package/dist/lib/errors.js +47 -6
  19. package/dist/lib/formatting.d.ts +13 -1
  20. package/dist/lib/formatting.js +18 -1
  21. package/dist/lib/prompt-contracts.d.ts +6 -0
  22. package/dist/lib/prompt-contracts.js +35 -0
  23. package/dist/lib/text.d.ts +0 -1
  24. package/dist/lib/text.js +0 -1
  25. package/dist/lib/tool-contracts.d.ts +15 -0
  26. package/dist/lib/tool-contracts.js +93 -0
  27. package/dist/lib/tool-response.d.ts +4 -1
  28. package/dist/lib/tool-response.js +3 -1
  29. package/dist/lib/types.d.ts +18 -1
  30. package/dist/lib/types.js +8 -2
  31. package/dist/lib/validators.d.ts +7 -2
  32. package/dist/lib/validators.js +30 -8
  33. package/dist/prompts/index.d.ts +0 -1
  34. package/dist/prompts/index.js +171 -74
  35. package/dist/prompts/templates.d.ts +2 -0
  36. package/dist/prompts/templates.js +106 -0
  37. package/dist/resources/index.d.ts +0 -1
  38. package/dist/resources/index.js +40 -63
  39. package/dist/resources/instructions.d.ts +1 -0
  40. package/dist/resources/instructions.js +103 -0
  41. package/dist/resources/tool-catalog.d.ts +1 -0
  42. package/dist/resources/tool-catalog.js +20 -0
  43. package/dist/resources/tool-info.d.ts +2 -0
  44. package/dist/resources/tool-info.js +35 -0
  45. package/dist/resources/workflows.d.ts +1 -0
  46. package/dist/resources/workflows.js +61 -0
  47. package/dist/schemas/inputs.d.ts +7 -2
  48. package/dist/schemas/inputs.js +39 -4
  49. package/dist/schemas/outputs.d.ts +32 -26
  50. package/dist/schemas/outputs.js +17 -14
  51. package/dist/server.d.ts +0 -1
  52. package/dist/server.js +1 -4
  53. package/dist/tools/index.d.ts +0 -1
  54. package/dist/tools/index.js +0 -1
  55. package/dist/tools/reasoning-think.d.ts +0 -1
  56. package/dist/tools/reasoning-think.js +211 -118
  57. package/package.json +9 -10
  58. package/dist/engine/config.d.ts.map +0 -1
  59. package/dist/engine/config.js.map +0 -1
  60. package/dist/engine/context.d.ts.map +0 -1
  61. package/dist/engine/context.js.map +0 -1
  62. package/dist/engine/events.d.ts.map +0 -1
  63. package/dist/engine/events.js.map +0 -1
  64. package/dist/engine/reasoner.d.ts.map +0 -1
  65. package/dist/engine/reasoner.js.map +0 -1
  66. package/dist/engine/session-store.d.ts.map +0 -1
  67. package/dist/engine/session-store.js.map +0 -1
  68. package/dist/index.d.ts.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/instructions.md +0 -148
  71. package/dist/lib/errors.d.ts.map +0 -1
  72. package/dist/lib/errors.js.map +0 -1
  73. package/dist/lib/formatting.d.ts.map +0 -1
  74. package/dist/lib/formatting.js.map +0 -1
  75. package/dist/lib/instructions.d.ts +0 -5
  76. package/dist/lib/instructions.d.ts.map +0 -1
  77. package/dist/lib/instructions.js +0 -30
  78. package/dist/lib/instructions.js.map +0 -1
  79. package/dist/lib/text.d.ts.map +0 -1
  80. package/dist/lib/text.js.map +0 -1
  81. package/dist/lib/tool-response.d.ts.map +0 -1
  82. package/dist/lib/tool-response.js.map +0 -1
  83. package/dist/lib/types.d.ts.map +0 -1
  84. package/dist/lib/types.js.map +0 -1
  85. package/dist/lib/validators.d.ts.map +0 -1
  86. package/dist/lib/validators.js.map +0 -1
  87. package/dist/prompts/index.d.ts.map +0 -1
  88. package/dist/prompts/index.js.map +0 -1
  89. package/dist/resources/index.d.ts.map +0 -1
  90. package/dist/resources/index.js.map +0 -1
  91. package/dist/schemas/inputs.d.ts.map +0 -1
  92. package/dist/schemas/inputs.js.map +0 -1
  93. package/dist/schemas/outputs.d.ts.map +0 -1
  94. package/dist/schemas/outputs.js.map +0 -1
  95. package/dist/server.d.ts.map +0 -1
  96. package/dist/server.js.map +0 -1
  97. package/dist/tools/index.d.ts.map +0 -1
  98. package/dist/tools/index.js.map +0 -1
  99. package/dist/tools/reasoning-think.d.ts.map +0 -1
  100. package/dist/tools/reasoning-think.js.map +0 -1
@@ -0,0 +1,103 @@
1
+ import { getPromptContracts } from '../lib/prompt-contracts.js';
2
+ import { getToolContracts } from '../lib/tool-contracts.js';
3
+ import { getSharedConstraints } from './tool-info.js';
4
+ function formatParam(p) {
5
+ const req = p.required ? 'required' : 'optional';
6
+ const desc = p.constraints
7
+ ? ` (${p.type}, ${req}; ${p.constraints})`
8
+ : ` (${p.type}, ${req})`;
9
+ return `- \`${p.name}\`${desc}`;
10
+ }
11
+ function formatPrompt(p) {
12
+ return `- \`${p.name}\`: ${p.description}`;
13
+ }
14
+ export function buildServerInstructions() {
15
+ const toolContracts = getToolContracts();
16
+ const promptContracts = getPromptContracts();
17
+ const toolSections = [...toolContracts]
18
+ .sort((a, b) => a.name.localeCompare(b.name))
19
+ .map((c) => {
20
+ const params = c.params.map(formatParam).join('\n');
21
+ return `### \`${c.name}\`\n- Purpose: ${c.purpose}\n- Model: \`${c.model}\`\n- Parameters:\n${params}`;
22
+ });
23
+ const promptList = promptContracts
24
+ .filter((p) => p.name !== 'get-help')
25
+ .sort((a, b) => a.name.localeCompare(b.name))
26
+ .map(formatPrompt)
27
+ .join('\n');
28
+ const sharedConstraints = getSharedConstraints()
29
+ .map((c) => `- ${c}`)
30
+ .join('\n');
31
+ return `# CORTEX-MCP INSTRUCTIONS
32
+
33
+ These instructions are available as a resource (internal://instructions) or prompt (get-help). Load them when unsure about tool usage.
34
+
35
+ ---
36
+
37
+ ## CORE CAPABILITY
38
+
39
+ - Domain: Multi-level reasoning engine that decomposes queries into structured thought chains at configurable depth levels (basic, normal, high).
40
+ - Primary Resources: Reasoning sessions (in-memory, 30-minute TTL), thought chains, progress notifications.
41
+ - Tools: \`reasoning_think\` (WRITE — creates/extends sessions with LLM-authored thoughts).
42
+
43
+ ---
44
+
45
+ ## PROMPTS
46
+
47
+ - \`get-help\`: Returns these instructions for quick recall.
48
+ ${promptList}
49
+
50
+ > **Guided templates:** Each \`reasoning.<level>\` prompt embeds a level-specific few-shot example showing the expected \`thought\` depth and step count. Only the template for the requested level is injected — the other two are omitted to keep prompts lean.
51
+
52
+ ---
53
+
54
+ ## RESOURCES & RESOURCE LINKS
55
+
56
+ - \`internal://instructions\`: This document.
57
+ - \`reasoning://sessions\`: List all active reasoning sessions with metadata (JSON).
58
+ - \`reasoning://sessions/{sessionId}\`: Inspect a specific session's thoughts and metadata (JSON). Supports auto-completion on \`sessionId\`.
59
+ - \`file:///cortex/sessions/{sessionId}/trace.md\`: Full Markdown trace of a session. Supports auto-completion on \`sessionId\`.
60
+ - \`file:///cortex/sessions/{sessionId}/{thoughtName}.md\`: Markdown content of a single thought (e.g., \`Thought-1.md\`). Supports auto-completion on \`sessionId\` and \`thoughtName\`.
61
+ - The server supports \`resources/subscribe\` for real-time change notifications on individual resources.
62
+ - Subscribe to \`reasoning://sessions/{sessionId}\` to receive \`notifications/resources/updated\` when thoughts are added, revised, or status changes.
63
+ - Subscribe to \`reasoning://sessions\` to receive aggregate updates as session content and statuses evolve.
64
+ - Use subscriptions to monitor session progress without polling.
65
+
66
+ ---
67
+
68
+ ## PROGRESS & TASKS
69
+
70
+ - Include \`_meta.progressToken\` in requests to receive \`notifications/progress\` updates during reasoning.
71
+ - Task-augmented tool calls are supported for \`reasoning_think\`:
72
+ - \`execution.taskSupport: "optional"\` — invoke normally or as a task.
73
+ - Send \`tools/call\` with \`task\` to get a task id.
74
+ - Poll \`tasks/get\` and fetch results via \`tasks/result\`.
75
+ - Use \`tasks/cancel\` to abort a running task.
76
+ - For \`high\` level, progress is emitted every 2 steps to reduce noise; \`basic\` and \`normal\` emit after every step.
77
+ - Use \`runMode: "run_to_completion"\` with \`thought\` + \`thoughts[]\` to execute multiple reasoning steps in one request.
78
+
79
+ ---
80
+
81
+ ## TOOL CONTRACTS
82
+
83
+ ${toolSections.join('\n\n')}
84
+
85
+ ---
86
+
87
+ ## SHARED CONSTRAINTS
88
+
89
+ ${sharedConstraints}
90
+
91
+ ---
92
+
93
+ ## ERROR HANDLING STRATEGY
94
+
95
+ - \`E_SESSION_NOT_FOUND\`: Session expired or never existed. Call \`reasoning://sessions\` to list active sessions, or start a new session without \`sessionId\`.
96
+ - \`E_INVALID_THOUGHT_COUNT\`: \`targetThoughts\` is outside the level range. Check ranges: basic (3–5), normal (6–10), high (15–25).
97
+ - \`E_INSUFFICIENT_THOUGHTS\`: In \`run_to_completion\`, the request did not provide enough thought inputs for planned remaining steps.
98
+ - \`E_INVALID_RUN_MODE_ARGS\`: Invalid \`runMode\` argument combination (for example, missing \`targetThoughts\` when starting a new run-to-completion session).
99
+ - \`E_ABORTED\`: Reasoning was cancelled via abort signal or task cancellation. Retry with a new request if needed.
100
+ - \`E_SERVER_BUSY\`: Too many concurrent task-mode reasoning calls (default cap: 32). Retry after a short delay, or use normal (non-task) invocation.
101
+ - \`E_REASONING\`: Unexpected engine error. Check the error \`message\` field for details and retry.
102
+ `;
103
+ }
@@ -0,0 +1 @@
1
+ export declare function buildToolCatalog(): string;
@@ -0,0 +1,20 @@
1
+ import { buildCoreContextPack } from './tool-info.js';
2
+ const CATALOG_GUIDE = `# Tool Catalog Details
3
+ ## Optional Parameters
4
+ - \`observation\`: What facts are known at this step? Use with \`hypothesis\` and \`evaluation\` as an alternative to \`thought\`.
5
+ - \`hypothesis\`: What is the proposed idea or next logical leap?
6
+ - \`evaluation\`: Critique the hypothesis. Are there flaws?
7
+ - \`step_summary\`: A 1-sentence summary of the conclusion reached in this step. Accumulates in the \`summary\` field for contextual guidance.
8
+ - \`is_conclusion\`: Set to true to end the session early with a final answer.
9
+ - \`rollback_to_step\`: Roll back to a thought index (0-based). All thoughts after this index are discarded.
10
+
11
+ ## Cross-Tool Data Flow
12
+ \`\`\`
13
+ reasoning_think -> result.sessionId -> reasoning_think.sessionId
14
+ reasoning_think -> result.sessionId -> reasoning://sessions/{sessionId}
15
+ reasoning_think -> result.sessionId -> file:///cortex/sessions/{sessionId}/trace.md
16
+ \`\`\`
17
+ `;
18
+ export function buildToolCatalog() {
19
+ return `${buildCoreContextPack()}\n\n${CATALOG_GUIDE}`;
20
+ }
@@ -0,0 +1,2 @@
1
+ export declare function buildCoreContextPack(): string;
2
+ export declare function getSharedConstraints(): string[];
@@ -0,0 +1,35 @@
1
+ import { getToolContracts } from '../lib/tool-contracts.js';
2
+ function toEntry(contract) {
3
+ return {
4
+ name: contract.name,
5
+ model: contract.model,
6
+ timeout: contract.timeoutMs > 0
7
+ ? `${Math.round(contract.timeoutMs / 1_000)}s`
8
+ : 'N/A',
9
+ maxOutputTokens: contract.maxOutputTokens > 0 ? String(contract.maxOutputTokens) : 'N/A',
10
+ purpose: contract.purpose,
11
+ };
12
+ }
13
+ const ENTRIES = Object.fromEntries(getToolContracts().map((contract) => [contract.name, toEntry(contract)]));
14
+ export function buildCoreContextPack() {
15
+ const names = Object.keys(ENTRIES).sort((a, b) => a.localeCompare(b));
16
+ const rows = names.map((name) => {
17
+ const e = ENTRIES[name];
18
+ return e
19
+ ? `| \`${e.name}\` | ${e.model} | ${e.timeout} | ${e.maxOutputTokens} | ${e.purpose} |`
20
+ : '';
21
+ });
22
+ return `# Core Context Pack\n\n| Tool | Model | Timeout | Max Output Tokens | Purpose |\n|------|-------|---------|-------------------|---------|\n${rows.join('\n')}`;
23
+ }
24
+ export function getSharedConstraints() {
25
+ return [
26
+ 'Sessions are in-memory — all data is lost on process restart.',
27
+ 'Session TTL: 30 minutes from last update. Expired sessions cannot be recovered.',
28
+ 'Maximum query length: 10,000 characters.',
29
+ 'Token budget enforcement is approximate (character-based proxy, not true tokenization).',
30
+ 'stdio transport only — no HTTP endpoint available.',
31
+ 'Every thought in the trace contains LLM-authored reasoning content provided via the `thought` parameter.',
32
+ "targetThoughts must be an integer within the level's min/max range.",
33
+ 'Session store limits are configurable via CORTEX_SESSION_TTL_MS, CORTEX_MAX_SESSIONS, and CORTEX_MAX_TOTAL_TOKENS.',
34
+ ];
35
+ }
@@ -0,0 +1 @@
1
+ export declare function buildWorkflowGuide(): string;
@@ -0,0 +1,61 @@
1
+ import { getToolContracts } from '../lib/tool-contracts.js';
2
+ import { getSharedConstraints } from './tool-info.js';
3
+ function buildToolReference() {
4
+ return [...getToolContracts()]
5
+ .sort((a, b) => a.name.localeCompare(b.name))
6
+ .map((c) => `### \`${c.name}\`\n- Purpose: ${c.purpose}\n- Output: \`${c.outputShape}\``)
7
+ .join('\n\n');
8
+ }
9
+ export function buildWorkflowGuide() {
10
+ return `# THE "GOLDEN PATH" WORKFLOWS (CRITICAL)
11
+
12
+ ### WORKFLOW A: Sequential Reasoning (Most Common)
13
+
14
+ 1. Call \`reasoning_think\` with \`{ query: "...", level: "basic", thought: "Your detailed reasoning for step 1..." }\`.
15
+ 2. Read the response — note the \`sessionId\` and \`remainingThoughts\` fields.
16
+ 3. **You MUST continue**: Call again with \`{ sessionId: "<from response>", thought: "Your next reasoning step..." }\`.
17
+ 4. Repeat step 3 until the response shows \`status: "completed"\` or \`remainingThoughts: 0\`.
18
+ NOTE: The \`summary\` field contains the exact continuation call you should make next.
19
+
20
+ ### WORKFLOW B: Multi-Turn Reasoning (Session Continuation)
21
+
22
+ 1. Call \`reasoning_think\` with \`{ query: "initial question", level: "normal", thought: "Your first reasoning step..." }\` — note the returned \`sessionId\`.
23
+ 2. Call \`reasoning_think\` with \`{ sessionId: "<id>", thought: "Your next reasoning step..." }\` (optional: add \`query\` for follow-up context).
24
+ 3. Repeat until \`status: "completed"\` or \`remainingThoughts: 0\`, then read \`reasoning://sessions/{sessionId}\` for the full chain.
25
+ NOTE: The \`level\` parameter is optional when continuing; if provided and mismatched, the session level is used.
26
+
27
+ ### WORKFLOW C: Controlled Depth Reasoning
28
+
29
+ 1. Call \`reasoning_think\` with \`{ query: "...", level: "normal", targetThoughts: 8, thought: "Your reasoning..." }\` to set the session's planned step count.
30
+ 2. Repeat calls with the returned \`sessionId\` and your next \`thought\` until \`result.totalThoughts\` is reached.
31
+ NOTE: \`targetThoughts\` must fall within the level range (basic: 3–5, normal: 6–10, high: 15–25). Out-of-range values return \`E_INVALID_THOUGHT_COUNT\`.
32
+
33
+ ### WORKFLOW D: Async Task Execution
34
+
35
+ 1. Call \`reasoning_think\` as a task (send \`tools/call\` with \`task\` field) for long-running \`high\`-level reasoning.
36
+ 2. Poll \`tasks/get\` until status is \`completed\` or \`failed\`.
37
+ 3. Retrieve the result via \`tasks/result\`.
38
+ 4. Use \`tasks/cancel\` to abort if needed.
39
+
40
+ ### WORKFLOW E: Batched Run-To-Completion
41
+
42
+ 1. Start a new session with explicit \`targetThoughts\` and \`runMode: "run_to_completion"\`.
43
+ 2. Provide one \`thought\` plus additional \`thoughts[]\` entries to cover the planned step count.
44
+ 3. The server consumes thought inputs in order until completion, token budget exhaustion, or cancellation.
45
+
46
+ ### WORKFLOW F: Structured Reasoning (Observation/Hypothesis/Evaluation)
47
+
48
+ 1. Call \`reasoning_think\` with \`{ query: "...", level: "normal", observation: "facts...", hypothesis: "idea...", evaluation: "critique..." }\`.
49
+ 2. The server formats these into a structured thought and stores it in the session trace.
50
+ 3. Continue with \`sessionId\` using either \`thought\` or structured fields for subsequent steps.
51
+ 4. Use \`is_conclusion: true\` to end early, or \`rollback_to_step\` to discard and redo from a specific step.
52
+
53
+ ## Shared Constraints
54
+ ${getSharedConstraints()
55
+ .map((c) => `- ${c}`)
56
+ .join('\n')}
57
+
58
+ ## Tool Reference
59
+ ${buildToolReference()}
60
+ `;
61
+ }
@@ -12,8 +12,13 @@ export declare const ReasoningThinkInputSchema: z.ZodObject<{
12
12
  step: "step";
13
13
  run_to_completion: "run_to_completion";
14
14
  }>>;
15
- thought: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
15
+ thought: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
16
16
  thoughts: z.ZodOptional<z.ZodArray<z.ZodString>>;
17
+ is_conclusion: z.ZodOptional<z.ZodBoolean>;
18
+ rollback_to_step: z.ZodOptional<z.ZodNumber>;
19
+ step_summary: z.ZodOptional<z.ZodString>;
20
+ observation: z.ZodOptional<z.ZodString>;
21
+ hypothesis: z.ZodOptional<z.ZodString>;
22
+ evaluation: z.ZodOptional<z.ZodString>;
17
23
  }, z.core.$strict>;
18
24
  export type ReasoningThinkInput = z.infer<typeof ReasoningThinkInputSchema>;
19
- //# sourceMappingURL=inputs.d.ts.map
@@ -1,10 +1,11 @@
1
1
  import { z } from 'zod';
2
+ import { getLevelDescriptionString } from '../engine/config.js';
3
+ import { REASONING_LEVELS } from '../lib/types.js';
2
4
  import { getTargetThoughtsError } from '../lib/validators.js';
3
5
  const RUN_MODE_VALUES = ['step', 'run_to_completion'];
4
6
  const DEFAULT_RUN_MODE = 'step';
5
- const LEVEL_VALUES = ['basic', 'normal', 'high'];
7
+ const LEVEL_SCHEMA = z.enum(REASONING_LEVELS);
6
8
  const QUERY_TEXT_SCHEMA = z.string().min(1).max(10000);
7
- const LEVEL_SCHEMA = z.enum(LEVEL_VALUES);
8
9
  const THOUGHT_TEXT_SCHEMA = z.string().min(1).max(100000);
9
10
  const THOUGHT_BATCH_SCHEMA = z.array(THOUGHT_TEXT_SCHEMA).min(1).max(25);
10
11
  function addCustomIssue(ctx, path, message) {
@@ -17,11 +18,12 @@ function addCustomIssue(ctx, path, message) {
17
18
  export const ReasoningThinkInputSchema = z
18
19
  .strictObject({
19
20
  query: QUERY_TEXT_SCHEMA.optional().describe('The question or problem to reason about'),
20
- level: LEVEL_SCHEMA.optional().describe('Reasoning depth level (required for new sessions, optional for continuing)'),
21
+ level: LEVEL_SCHEMA.optional().describe(`Reasoning depth level (required for new sessions, optional for continuing). ${getLevelDescriptionString()}.`),
21
22
  targetThoughts: z
22
23
  .number()
23
24
  .int()
24
25
  .min(1)
26
+ .max(25)
25
27
  .optional()
26
28
  .describe('Optional explicit thought count. Must fit the level range: basic 3–5, normal 6–10, high 15–25.'),
27
29
  sessionId: z
@@ -36,6 +38,7 @@ export const ReasoningThinkInputSchema = z
36
38
  .describe('Execution mode (default: "step"). "step" appends a single thought per call. "run_to_completion" consumes all supplied thought inputs in one request.'),
37
39
  thought: z
38
40
  .union([THOUGHT_TEXT_SCHEMA, THOUGHT_BATCH_SCHEMA])
41
+ .optional()
39
42
  .describe('Your full reasoning content for this step. ' +
40
43
  'The server stores this text verbatim as the thought in the session trace. ' +
41
44
  'Write your complete analysis, observations, and conclusions here — this is what appears in trace.md. ' +
@@ -45,6 +48,32 @@ export const ReasoningThinkInputSchema = z
45
48
  .max(25)
46
49
  .optional()
47
50
  .describe('(Deprecated) Optional additional thought inputs. Use "thought" as an array instead.'),
51
+ is_conclusion: z
52
+ .boolean()
53
+ .optional()
54
+ .describe('Set to true if you have arrived at the final answer and wish to end the reasoning session early.'),
55
+ rollback_to_step: z
56
+ .number()
57
+ .int()
58
+ .min(0)
59
+ .optional()
60
+ .describe('Set to a thought index (0-based) to rollback to. All thoughts after this index will be discarded.'),
61
+ step_summary: z
62
+ .string()
63
+ .optional()
64
+ .describe('A 1-sentence summary of the conclusion reached in this specific step.'),
65
+ observation: z
66
+ .string()
67
+ .optional()
68
+ .describe('What facts are known at this step?'),
69
+ hypothesis: z
70
+ .string()
71
+ .optional()
72
+ .describe('What is the proposed idea or next logical leap?'),
73
+ evaluation: z
74
+ .string()
75
+ .optional()
76
+ .describe('Critique the hypothesis. Are there flaws?'),
48
77
  })
49
78
  .superRefine((data, ctx) => {
50
79
  const runMode = data.runMode ?? DEFAULT_RUN_MODE;
@@ -65,6 +94,13 @@ export const ReasoningThinkInputSchema = z
65
94
  if (runMode === 'step' && data.thoughts !== undefined) {
66
95
  addCustomIssue(ctx, ['thoughts'], 'thoughts is only allowed when runMode is "run_to_completion"');
67
96
  }
97
+ const hasThought = data.thought !== undefined;
98
+ const hasStructured = data.observation !== undefined &&
99
+ data.hypothesis !== undefined &&
100
+ data.evaluation !== undefined;
101
+ if (!hasThought && !hasStructured && data.rollback_to_step === undefined) {
102
+ addCustomIssue(ctx, ['thought'], 'Either "thought" or structured fields ("observation", "hypothesis", "evaluation") are required, unless rolling back.');
103
+ }
68
104
  if (data.targetThoughts === undefined || data.level === undefined) {
69
105
  return;
70
106
  }
@@ -73,4 +109,3 @@ export const ReasoningThinkInputSchema = z
73
109
  addCustomIssue(ctx, ['targetThoughts'], error);
74
110
  }
75
111
  });
76
- //# sourceMappingURL=inputs.js.map
@@ -1,12 +1,4 @@
1
1
  import { z } from 'zod';
2
- export declare const DefaultOutputSchema: z.ZodObject<{
3
- ok: z.ZodBoolean;
4
- result: z.ZodOptional<z.ZodUnknown>;
5
- error: z.ZodOptional<z.ZodObject<{
6
- code: z.ZodString;
7
- message: z.ZodString;
8
- }, z.core.$strict>>;
9
- }, z.core.$strict>;
10
2
  declare const ReasoningThinkSuccessSchema: z.ZodObject<{
11
3
  ok: z.ZodLiteral<true>;
12
4
  result: z.ZodObject<{
@@ -25,6 +17,7 @@ declare const ReasoningThinkSuccessSchema: z.ZodObject<{
25
17
  index: z.ZodNumber;
26
18
  content: z.ZodString;
27
19
  revision: z.ZodNumber;
20
+ stepSummary: z.ZodOptional<z.ZodString>;
28
21
  }, z.core.$strict>>;
29
22
  generatedThoughts: z.ZodNumber;
30
23
  requestedThoughts: z.ZodNumber;
@@ -39,9 +32,13 @@ declare const ReasoningThinkSuccessSchema: z.ZodObject<{
39
32
  summary: z.ZodString;
40
33
  }, z.core.$strict>;
41
34
  }, z.core.$strict>;
42
- export declare const ReasoningThinkResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
43
- ok: z.ZodLiteral<true>;
44
- result: z.ZodObject<{
35
+ /**
36
+ * Tool-facing output schema kept as a strict object so SDK tooling
37
+ * can advertise outputSchema via tools/list.
38
+ */
39
+ export declare const ReasoningThinkToolOutputSchema: z.ZodObject<{
40
+ ok: z.ZodBoolean;
41
+ result: z.ZodOptional<z.ZodObject<{
45
42
  sessionId: z.ZodString;
46
43
  level: z.ZodEnum<{
47
44
  basic: "basic";
@@ -57,6 +54,7 @@ export declare const ReasoningThinkResultSchema: z.ZodDiscriminatedUnion<[z.ZodO
57
54
  index: z.ZodNumber;
58
55
  content: z.ZodString;
59
56
  revision: z.ZodNumber;
57
+ stepSummary: z.ZodOptional<z.ZodString>;
60
58
  }, z.core.$strict>>;
61
59
  generatedThoughts: z.ZodNumber;
62
60
  requestedThoughts: z.ZodNumber;
@@ -69,21 +67,28 @@ export declare const ReasoningThinkResultSchema: z.ZodDiscriminatedUnion<[z.ZodO
69
67
  updatedAt: z.ZodNumber;
70
68
  remainingThoughts: z.ZodNumber;
71
69
  summary: z.ZodString;
72
- }, z.core.$strict>;
70
+ }, z.core.$strict>>;
71
+ error: z.ZodOptional<z.ZodObject<{
72
+ code: z.ZodString;
73
+ message: z.ZodString;
74
+ }, z.core.$strict>>;
75
+ }, z.core.$strict>;
76
+ export type ReasoningThinkSuccess = z.infer<typeof ReasoningThinkSuccessSchema>;
77
+ /** Generic ok/error envelope — useful for contract tests and external validators. */
78
+ export declare const DefaultOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
79
+ ok: z.ZodLiteral<true>;
80
+ result: z.ZodUnknown;
73
81
  }, z.core.$strict>, z.ZodObject<{
74
82
  ok: z.ZodLiteral<false>;
75
83
  error: z.ZodObject<{
76
84
  code: z.ZodString;
77
85
  message: z.ZodString;
78
86
  }, z.core.$strict>;
79
- }, z.core.$strict>], "ok">;
80
- /**
81
- * Tool-facing output schema kept as a strict object so SDK tooling
82
- * can advertise outputSchema via tools/list.
83
- */
84
- export declare const ReasoningThinkToolOutputSchema: z.ZodObject<{
85
- ok: z.ZodBoolean;
86
- result: z.ZodOptional<z.ZodObject<{
87
+ }, z.core.$strict>]>;
88
+ /** Full discriminated union for the reasoning_think tool result. */
89
+ export declare const ReasoningThinkResultSchema: z.ZodUnion<readonly [z.ZodObject<{
90
+ ok: z.ZodLiteral<true>;
91
+ result: z.ZodObject<{
87
92
  sessionId: z.ZodString;
88
93
  level: z.ZodEnum<{
89
94
  basic: "basic";
@@ -99,6 +104,7 @@ export declare const ReasoningThinkToolOutputSchema: z.ZodObject<{
99
104
  index: z.ZodNumber;
100
105
  content: z.ZodString;
101
106
  revision: z.ZodNumber;
107
+ stepSummary: z.ZodOptional<z.ZodString>;
102
108
  }, z.core.$strict>>;
103
109
  generatedThoughts: z.ZodNumber;
104
110
  requestedThoughts: z.ZodNumber;
@@ -111,12 +117,12 @@ export declare const ReasoningThinkToolOutputSchema: z.ZodObject<{
111
117
  updatedAt: z.ZodNumber;
112
118
  remainingThoughts: z.ZodNumber;
113
119
  summary: z.ZodString;
114
- }, z.core.$strict>>;
115
- error: z.ZodOptional<z.ZodObject<{
120
+ }, z.core.$strict>;
121
+ }, z.core.$strict>, z.ZodObject<{
122
+ ok: z.ZodLiteral<false>;
123
+ error: z.ZodObject<{
116
124
  code: z.ZodString;
117
125
  message: z.ZodString;
118
- }, z.core.$strict>>;
119
- }, z.core.$strict>;
120
- export type ReasoningThinkSuccess = z.infer<typeof ReasoningThinkSuccessSchema>;
126
+ }, z.core.$strict>;
127
+ }, z.core.$strict>]>;
121
128
  export {};
122
- //# sourceMappingURL=outputs.d.ts.map
@@ -1,28 +1,26 @@
1
1
  import { z } from 'zod';
2
+ import { REASONING_LEVELS, SESSION_STATUSES } from '../lib/types.js';
2
3
  const ErrorInfoSchema = z.strictObject({
3
4
  code: z.string(),
4
5
  message: z.string(),
5
6
  });
6
7
  const MISSING_RESULT_PATH = ['result'];
7
8
  const MISSING_ERROR_PATH = ['error'];
8
- const LEVEL_VALUES = ['basic', 'normal', 'high'];
9
- const STATUS_VALUES = ['active', 'completed', 'cancelled'];
10
9
  const ThoughtSchema = z.strictObject({
11
10
  index: z.number(),
12
11
  content: z.string(),
13
12
  revision: z.number(),
14
- });
15
- export const DefaultOutputSchema = z.strictObject({
16
- ok: z.boolean(),
17
- result: z.unknown().optional(),
18
- error: ErrorInfoSchema.optional(),
13
+ stepSummary: z
14
+ .string()
15
+ .optional()
16
+ .describe('A 1-sentence summary of the conclusion reached in this step, if provided.'),
19
17
  });
20
18
  const ReasoningThinkSuccessSchema = z.strictObject({
21
19
  ok: z.literal(true),
22
20
  result: z.strictObject({
23
21
  sessionId: z.string(),
24
- level: z.enum(LEVEL_VALUES),
25
- status: z.enum(STATUS_VALUES),
22
+ level: z.enum(REASONING_LEVELS),
23
+ status: z.enum(SESSION_STATUSES),
26
24
  thoughts: z.array(ThoughtSchema),
27
25
  generatedThoughts: z.number(),
28
26
  requestedThoughts: z.number(),
@@ -49,10 +47,6 @@ const ReasoningThinkErrorSchema = z.strictObject({
49
47
  ok: z.literal(false),
50
48
  error: ErrorInfoSchema,
51
49
  });
52
- export const ReasoningThinkResultSchema = z.discriminatedUnion('ok', [
53
- ReasoningThinkSuccessSchema,
54
- ReasoningThinkErrorSchema,
55
- ]);
56
50
  function getMissingFieldIssue(data) {
57
51
  if (data.ok && data.result === undefined) {
58
52
  return {
@@ -88,4 +82,13 @@ export const ReasoningThinkToolOutputSchema = z
88
82
  });
89
83
  }
90
84
  });
91
- //# sourceMappingURL=outputs.js.map
85
+ /** Generic ok/error envelope — useful for contract tests and external validators. */
86
+ export const DefaultOutputSchema = z.union([
87
+ z.strictObject({ ok: z.literal(true), result: z.unknown() }),
88
+ z.strictObject({ ok: z.literal(false), error: ErrorInfoSchema }),
89
+ ]);
90
+ /** Full discriminated union for the reasoning_think tool result. */
91
+ export const ReasoningThinkResultSchema = z.union([
92
+ ReasoningThinkSuccessSchema,
93
+ ReasoningThinkErrorSchema,
94
+ ]);
package/dist/server.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  export declare function createServer(): McpServer;
3
- //# sourceMappingURL=server.d.ts.map
package/dist/server.js CHANGED
@@ -4,7 +4,6 @@ import { InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental/tasks'
4
4
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
5
  import { engineEvents } from './engine/events.js';
6
6
  import { getErrorMessage } from './lib/errors.js';
7
- import { loadInstructions } from './lib/instructions.js';
8
7
  import { registerAllTools } from './tools/index.js';
9
8
  import { registerAllPrompts } from './prompts/index.js';
10
9
  import { registerAllResources } from './resources/index.js';
@@ -147,7 +146,6 @@ function installCloseCleanup(server, cleanup) {
147
146
  };
148
147
  }
149
148
  export function createServer() {
150
- const instructions = loadInstructions();
151
149
  const version = loadVersion();
152
150
  const taskStore = new InMemoryTaskStore();
153
151
  const localIcon = getLocalIconData();
@@ -180,7 +178,7 @@ export function createServer() {
180
178
  },
181
179
  },
182
180
  taskStore,
183
- ...(instructions ? { instructions } : {}),
181
+ instructions: 'Multi-level reasoning MCP server. Use reasoning_think to decompose queries into sequential thought steps at basic (3–5), normal (6–10), or high (15–25) depth. Full usage guide: read internal://instructions or invoke get-help.',
184
182
  });
185
183
  registerAllTools(server, iconMeta);
186
184
  registerAllPrompts(server, iconMeta);
@@ -189,4 +187,3 @@ export function createServer() {
189
187
  installCloseCleanup(server, detachEngineHandlers);
190
188
  return server;
191
189
  }
192
- //# sourceMappingURL=server.js.map
@@ -1,4 +1,3 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { IconMeta } from '../lib/types.js';
3
3
  export declare function registerAllTools(server: McpServer, iconMeta?: IconMeta): void;
4
- //# sourceMappingURL=index.d.ts.map
@@ -5,4 +5,3 @@ export function registerAllTools(server, iconMeta) {
5
5
  registerTool(server, iconMeta);
6
6
  }
7
7
  }
8
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,3 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { IconMeta } from '../lib/types.js';
3
3
  export declare function registerReasoningThinkTool(server: McpServer, iconMeta?: IconMeta): void;
4
- //# sourceMappingURL=reasoning-think.d.ts.map