@nbiish/cognitive-tools-mcp 0.7.1 → 0.7.3

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.
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+
6
+ // Create the MCP server
7
+ const server = new McpServer({
8
+ name: "gikendaasowin-aabajichiganan",
9
+ // Version reflects novel tools and enhanced guidance
10
+ version: "0.6.2",
11
+ description: "ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Gikendaasowin Aabajichiganan - (Cognitive Tools v0.6.2): SOTA internal reasoning suite for LLM agents. Features advanced deliberation (`think`), rapid checks (`quick_think`), explicit complexity assessment, context synthesis (`synthesize`), confidence gauging, planning, CoT, and reflection. Designed to maximize reliability, traceability, and performance on complex cognitive tasks, pushing beyond current research."
12
+ });
13
+
14
+ // --- Core Cognitive Deliberation Tools ---
15
+
16
+ server.tool(
17
+ "think",
18
+ // Main Description: For High Cognitive Load situations.
19
+ "MANDATORY Cognitive Hub for **High Complexity/Uncertainty/Consequence/Novelty**. Use for deep analysis, planning, verification, risk assessment, self-correction, and integrating complex outputs (CoT, Plans, Critiques, Syntheses, Low Confidence Gauges). Logs detailed reasoning.",
20
+ {
21
+ // Parameter Description: Must analyze inputs including novel tool outputs.
22
+ thought: z.string().describe("Your **detailed** internal monologue for complex situations. MUST explicitly analyze prior steps/generated text (CoT, Plans, Critiques, Synthesized summaries, Confidence justifications). Structure: ## Analysis, ## Plan, ## Verification, ## Risk Assessment, ## Self-Correction. Ensure depth and clear linkage.")
23
+ },
24
+ async ({ thought }) => {
25
+ if (!thought || typeof thought !== 'string' || thought.trim().length === 0) { throw new Error('Invalid thought: Must be non-empty.'); }
26
+ console.error(`[CognitiveToolsServer] Think Tool Logged: ${thought.substring(0, 100)}...`);
27
+ return { content: [{ type: "text" as const, text: `Deep Thought Logged: ${thought}` }] };
28
+ }
29
+ );
30
+
31
+ server.tool(
32
+ "quick_think",
33
+ // Main Description: For Low Cognitive Load situations. Explicitly contrasted with 'think'.
34
+ "Cognitive Checkpoint for **Low Complexity/Uncertainty/Consequence**. Use ONLY for simple confirmations, acknowledgements, minor step decisions, or sanity checks where deep analysis is clearly unnecessary. Logs brief thought.",
35
+ {
36
+ brief_thought: z.string().describe("Your **concise** thought for simple situations (e.g., 'Acknowledged.', 'Proceeding with planned step X.', 'API call successful, extracting data.'). DO NOT use for analyzing complex outputs or making significant plans.")
37
+ },
38
+ async ({ brief_thought }) => {
39
+ if (!brief_thought || typeof brief_thought !== 'string' || brief_thought.trim().length === 0) { throw new Error('Invalid brief_thought: Must be non-empty.'); }
40
+ console.error(`[CognitiveToolsServer] QuickThink Tool Logged: ${brief_thought.substring(0, 100)}...`);
41
+ return { content: [{ type: "text" as const, text: `Quick Thought Logged: ${brief_thought}` }] };
42
+ }
43
+ );
44
+
45
+ // --- Novel Meta-Cognitive & Context Management Tools ---
46
+
47
+ server.tool(
48
+ "assess_cuc_n_mode",
49
+ // Main Description: Forces explicit decision between think/quick_think.
50
+ "**Mandatory Pre-Thought Assessment.** Guides the LLM to explicitly evaluate the upcoming cognitive step's complexity, uncertainty, consequence, and novelty, and *commit* to using either `think` or `quick_think` next. Enhances deliberate cognitive resource allocation.",
51
+ {
52
+ // Parameter Description: LLM provides its assessment and chosen mode.
53
+ assessment_and_choice: z.string().describe("Input your assessment: 1) Briefly describe the situation/next step. 2) Rate Complexity (Low/Med/High), Uncertainty (L/M/H), Consequence (L/M/H), Novelty (L/M/H). 3) State your choice: 'Selected Mode: think' or 'Selected Mode: quick_think'. *You* (LLM) make this assessment *before* calling.")
54
+ },
55
+ async ({ assessment_and_choice }) => {
56
+ if (!assessment_and_choice || typeof assessment_and_choice !== 'string' || (!assessment_and_choice.includes("Selected Mode: think") && !assessment_and_choice.includes("Selected Mode: quick_think"))) {
57
+ throw new Error('Invalid assessment: Must include complexity/uncertainty/consequence/novelty ratings and explicit mode selection ("Selected Mode: think" or "Selected Mode: quick_think").');
58
+ }
59
+ console.error(`[CognitiveToolsServer] AssessComplexity Tool Signaled: ${assessment_and_choice.substring(0, 150)}...`);
60
+ // Output confirms the assessment was made and which mode was selected.
61
+ const mode = assessment_and_choice.includes("Selected Mode: think") ? "think" : "quick_think";
62
+ return { content: [{ type: "text" as const, text: `Complexity Assessment Completed. Selected Next Mode: ${mode}. Assessment: ${assessment_and_choice}` }] };
63
+ }
64
+ );
65
+
66
+ server.tool(
67
+ "synthesize_prior_reasoning",
68
+ // Main Description: Manages context window and focuses reasoning.
69
+ "Context Management Tool. Guides the LLM to **generate a concise summary text** of preceding lengthy reasoning chains (multiple `think` logs, CoT outputs). Used to manage context limits and refocus attention before major subsequent `think` steps.",
70
+ {
71
+ // Parameter Description: LLM generates the summary internally first.
72
+ context_to_summarize_description: z.string().describe("Briefly describe the span of reasoning you are summarizing (e.g., 'Summary of planning phase', 'Key takeaways from debugging CoT'). *You* (LLM) must now *internally generate the concise summary text* before calling this tool. This signals the summary is ready.")
73
+ },
74
+ async ({ context_to_summarize_description }) => {
75
+ if (!context_to_summarize_description || typeof context_to_summarize_description !== 'string' || context_to_summarize_description.trim().length === 0) { throw new Error('Invalid context description: Must be non-empty.'); }
76
+ console.error(`[CognitiveToolsServer] SynthesizeReasoning Tool Signaled for: ${context_to_summarize_description}...`);
77
+ // Output confirms context and implies summary text is available internally
78
+ return { content: [{ type: "text" as const, text: `Synthesis internally generated for context: '${context_to_summarize_description}'. Ready for 'think' analysis.` }] };
79
+ }
80
+ );
81
+
82
+ server.tool(
83
+ "gauge_confidence",
84
+ // Main Description: Explicit meta-cognition about certainty.
85
+ "Meta-Cognitive Checkpoint. Guides the LLM to explicitly **state its confidence level (High/Medium/Low) and justification** regarding a specific plan, analysis, conclusion, or proposed action *before* proceeding. Low confidence may trigger Reflection or deeper Thinking.",
86
+ {
87
+ // Parameter Description: LLM provides its confidence assessment.
88
+ assessment_and_confidence: z.string().describe("Input the item being assessed (e.g., 'Confidence in current plan', 'Confidence in generated code correctness'). Then state: 1) Confidence Level (High/Medium/Low). 2) Brief Justification for this level. *You* (LLM) make this assessment *before* calling.")
89
+ },
90
+ async ({ assessment_and_confidence }) => {
91
+ const confidenceRegex = /Confidence Level: (High|Medium|Low)/i;
92
+ if (!assessment_and_confidence || typeof assessment_and_confidence !== 'string' || !confidenceRegex.test(assessment_and_confidence)) {
93
+ throw new Error('Invalid confidence assessment: Must include "Confidence Level: High/Medium/Low" and justification.');
94
+ }
95
+ const match = assessment_and_confidence.match(confidenceRegex);
96
+ const level = match ? match[1] : "Unknown";
97
+ console.error(`[CognitiveToolsServer] GaugeConfidence Tool Signaled: Level ${level}`);
98
+ // Output confirms assessment and level
99
+ return { content: [{ type: "text" as const, text: `Confidence Gauge Completed. Level: ${level}. Assessment: ${assessment_and_confidence}` }] };
100
+ }
101
+ );
102
+
103
+ // --- Supporting Cognitive Strategy Tools (Enhanced Descriptions) ---
104
+
105
+ server.tool(
106
+ "plan_and_solve",
107
+ // Main Description: Highlights role in structuring complex tasks and managing agentic workflows.
108
+ "Guides the LLM to **generate a structured, multi-step plan text** for a complex objective. Outlines necessary phases, potential sub-tasks, and anticipated tool usage, improving manageability of multi-step agentic workflows. The generated plan MUST be validated and detailed via `think`, and can optionally be passed to `reflection` for critique.",
109
+ {
110
+ // Parameter Description: Instructs LLM on plan generation.
111
+ task_objective: z.string().describe("Input the high-level objective. *You* (the LLM) must now *internally generate the structured plan text* before calling this tool. This signals the plan text is ready for analysis/critique.")
112
+ },
113
+ // Implementation: Signals Planning was performed.
114
+ async ({ task_objective }) => {
115
+ if (!task_objective || typeof task_objective !== 'string' || task_objective.trim().length === 0) {
116
+ throw new Error('Invalid task objective: Must be a non-empty string.');
117
+ }
118
+ console.error(`[CognitiveToolsServer] PlanAndSolve Tool Signaled for: ${task_objective.substring(0, 100)}...`);
119
+ return { content: [{ type: "text" as const, text: `Planning generation signaled for objective: ${task_objective}. Ready for 'think' analysis.` }] };
120
+ }
121
+ );
122
+
123
+ server.tool(
124
+ "chain_of_thought",
125
+ // Main Description: Emphasizes generating text for later analysis.
126
+ "Guides the LLM to **generate detailed, step-by-step reasoning text**. Used for complex logic or explainability. The *generated CoT text* MUST then be analyzed in a subsequent `think` call.",
127
+ {
128
+ // Parameter Description: Focus on the input problem.
129
+ problem_statement: z.string().describe("Input the problem requiring detailed step-by-step reasoning. *You* (the LLM) must now *internally generate the full CoT text* before calling this tool. This signals that CoT text is ready for analysis in the next `think` step.")
130
+ },
131
+ // Implementation: Signals CoT was performed for the given problem.
132
+ async ({ problem_statement }) => {
133
+ if (!problem_statement || typeof problem_statement !== 'string' || problem_statement.trim().length === 0) {
134
+ throw new Error('Invalid problem statement: Must be a non-empty string.');
135
+ }
136
+ console.error(`[CognitiveToolsServer] ChainOfThought Tool Signaled for: ${problem_statement.substring(0, 100)}...`);
137
+ return { content: [{ type: "text" as const, text: `Chain of Thought internally generated for problem: ${problem_statement}. Ready for 'think' analysis.` }] };
138
+ }
139
+ );
140
+
141
+ server.tool(
142
+ "chain_of_draft",
143
+ // Main Description: Positions for efficient exploration and hypothesis generation.
144
+ "Guides the LLM to **generate concise, iterative reasoning draft texts** ('thought-sketches'). Useful for efficiently exploring multiple solution paths, brainstorming hypotheses, or outlining approaches when full CoT verbosity is premature. Drafts MUST be analyzed comparatively via `think`.",
145
+ {
146
+ // Parameter Description: Instructs LLM on draft generation.
147
+ problem_statement: z.string().describe("Input the problem or question for exploration. *You* (the LLM) must now *internally generate brief, iterative draft texts* (key steps, pros/cons, core ideas) for potential approaches *before* calling this tool.")
148
+ },
149
+ // Implementation: Signals Drafting was performed.
150
+ async ({ problem_statement }) => {
151
+ if (!problem_statement || typeof problem_statement !== 'string' || problem_statement.trim().length === 0) {
152
+ throw new Error('Invalid problem statement: Must be a non-empty string.');
153
+ }
154
+ console.error(`[CognitiveToolsServer] ChainOfDraft Tool Signaled for: ${problem_statement.substring(0, 100)}...`);
155
+ return { content: [{ type: "text" as const, text: `Chain of Draft generation signaled for problem: ${problem_statement}. Ready for 'think' analysis.` }] };
156
+ }
157
+ );
158
+
159
+ server.tool(
160
+ "reflection",
161
+ // Main Description: Explicitly mentions taking prior text as input for critique.
162
+ "Guides the LLM to perform critical self-evaluation on **previously generated text** (reasoning, plans, code concepts). Essential for iterative refinement and improving accuracy. The *generated critique text* MUST be analyzed via `think`.",
163
+ {
164
+ // Parameter Description: Input is the text to be critiqued.
165
+ input_reasoning_or_plan: z.string().describe("Input the **exact text** (e.g., from a prior `think` log, or internally generated plan/CoT/code concept) that *you* (the LLM) must now *internally generate a critique for*. Your critique should identify flaws and suggest improvements.")
166
+ },
167
+ // Implementation: Signals Reflection was performed.
168
+ async ({ input_reasoning_or_plan }) => {
169
+ if (!input_reasoning_or_plan || typeof input_reasoning_or_plan !== 'string' || input_reasoning_or_plan.trim().length === 0) {
170
+ throw new Error('Invalid input reasoning/plan: Must be a non-empty string.');
171
+ }
172
+ console.error(`[CognitiveToolsServer] Reflection Tool Signaled for analysis.`);
173
+ return { content: [{ type: "text" as const, text: `Reflection internally generated for input text: '${input_reasoning_or_plan.substring(0, 100)}...'. Ready for 'think' analysis.` }] };
174
+ }
175
+ );
176
+
177
+
178
+ // --- Server Lifecycle and Error Handling ---
179
+
180
+ process.on('SIGINT', async () => {
181
+ console.error('[CognitiveToolsServer] Received SIGINT, shutting down.');
182
+ await server.close();
183
+ process.exit(0);
184
+ });
185
+
186
+ process.on('SIGTERM', async () => {
187
+ console.error('[CognitiveToolsServer] Received SIGTERM, shutting down.');
188
+ await server.close();
189
+ process.exit(0);
190
+ });
191
+
192
+ process.on('uncaughtException', (error) => {
193
+ console.error('[CognitiveToolsServer] Uncaught exception:', error);
194
+ // Depending on severity, you might want to gracefully shutdown or just log
195
+ });
196
+
197
+ process.on('unhandledRejection', (reason, promise) => {
198
+ console.error('[CognitiveToolsServer] Unhandled promise rejection:', reason);
199
+ // Depending on severity, you might want to gracefully shutdown or just log
200
+ });
201
+
202
+ // Start the server
203
+ async function main() {
204
+ try {
205
+ const transport = new StdioServerTransport();
206
+ await server.connect(transport);
207
+ console.error('ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Gikendaasowin Aabajichiganan - (Cognitive Tools v0.6.2) MCP Server running on stdio');
208
+ }
209
+ catch (error) {
210
+ console.error('[CognitiveToolsServer] Fatal error during startup:', error);
211
+ process.exit(1);
212
+ }
213
+ }
214
+
215
+ // Execute the main function to start the server
216
+ main();
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+
6
+ // Create the MCP server
7
+ const server = new McpServer({
8
+ name: "gikendaasowin-aabajichiganan-mcp",
9
+ // Version aligned with System Prompt v0.7.2
10
+ version: "0.7.2",
11
+ description: "ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Gikendaasowin Aabajichiganan - (Cognitive Tools v0.7.2): SOTA internal reasoning suite aligned with AI Pair Programmer Prompt v0.7.2. Enforces mandatory structured deliberation via `think` after explicit assessment (`assess_complexity...`). Includes meta-cognition (`gauge_confidence`), context synthesis, proactive planning, CoT, reflection, and tool awareness."
12
+ });
13
+
14
+ // --- Core Cognitive Deliberation Tools ---
15
+
16
+ server.tool(
17
+ "think",
18
+ // Main Description: Matches v0.7.2 prompt's emphasis on the central hub role.
19
+ "MANDATORY Cognitive Hub for **Medium/High CUC-N** situations or inherently complex tasks (analysis, planning, refinement). Use for deep analysis, planning, verification, risk assessment, self-correction, and integrating outputs from other tools/actions. Logs detailed reasoning.",
20
+ {
21
+ // Parameter Description: Matches the mandatory structured sections required by prompt v0.7.2.
22
+ thought: z.string().describe("Your **detailed** internal monologue. MUST explicitly analyze prior steps & generated text (CoT, Plan, Critique, Summary, Confidence Justification, etc.). Structure MANDATORY: ## Analysis, ## Plan, ## Verification, ## Anticipated Challenges Analysis & Contingency, ## Risk Assessment, ## Lookahead, ## Self-Correction & Learning.")
23
+ },
24
+ async ({ thought }) => {
25
+ if (!thought || typeof thought !== 'string' || thought.trim().length === 0) { throw new Error('Invalid thought: Must be non-empty, structured reasoning.'); }
26
+ console.error(`[CognitiveToolsServer v0.7.2] Think Tool Logged: ${thought.substring(0, 100)}...`);
27
+ return { content: [{ type: "text" as const, text: `Deep Thought (structured analysis/plan/etc.) logged successfully.` }] };
28
+ }
29
+ );
30
+
31
+ server.tool(
32
+ "quick_think",
33
+ // Main Description: Matches v0.7.2 prompt's strict conditions.
34
+ "Cognitive Checkpoint ONLY for situations explicitly assessed as **strictly Low CUC-N AND simple task nature** (e.g., confirmation, acknowledgement). Use sparingly. Logs brief thought.",
35
+ {
36
+ // Parameter Description: Simple input for brief thoughts.
37
+ brief_thought: z.string().describe("Your **concise** thought for strictly simple, low CUC-N situations confirmed by prior assessment (e.g., 'Acknowledged.', 'Proceeding as planned.', 'External tool call successful.').")
38
+ },
39
+ async ({ brief_thought }) => {
40
+ if (!brief_thought || typeof brief_thought !== 'string' || brief_thought.trim().length === 0) { throw new Error('Invalid brief_thought: Must be non-empty.'); }
41
+ console.error(`[CognitiveToolsServer v0.7.2] QuickThink Tool Logged: ${brief_thought.substring(0, 100)}...`);
42
+ return { content: [{ type: "text" as const, text: `Quick Thought logged successfully.` }] };
43
+ }
44
+ );
45
+
46
+ // --- Mandatory Meta-Cognitive & Context Management Tools ---
47
+
48
+ server.tool(
49
+ "assess_complexity_and_select_thought_mode",
50
+ // Main Description: Matches v0.7.2 prompt's mandatory first step.
51
+ "**Mandatory Pre-Deliberation Assessment.** Must be called BEFORE every `think` or `quick_think`. Evaluates CUC-N, recommends strategy, commits to next thought mode.",
52
+ {
53
+ // Parameter Description: Matches the 4 required components from prompt v0.7.2.
54
+ assessment_and_choice: z.string().describe("Input your assessment *before* calling. MUST include: 1) Situation/Next Step Description. 2) CUC-N Ratings: Complexity(L/M/H), Uncertainty(L/M/H), Consequence(L/M/H), Novelty(L/M/H). 3) Recommended Initial Strategy (e.g., 'Start `think` analysis'). 4) Explicit Mode Selection: 'Selected Mode: think' or 'Selected Mode: quick_think'.")
55
+ },
56
+ async ({ assessment_and_choice }) => {
57
+ const requiredPhrases = ["Complexity", "Uncertainty", "Consequence", "Novelty", "Recommended Initial Strategy", "Selected Mode:"];
58
+ const hasRequiredPhrases = requiredPhrases.every(phrase => assessment_and_choice.includes(phrase));
59
+ const hasModeSelection = assessment_and_choice.includes("Selected Mode: think") || assessment_and_choice.includes("Selected Mode: quick_think");
60
+ if (!assessment_and_choice || typeof assessment_and_choice !== 'string' || !hasRequiredPhrases || !hasModeSelection) { throw new Error('Invalid assessment: String must include CUC-N ratings, Recommended Initial Strategy, and explicit Selected Mode ("think" or "quick_think").'); }
61
+ console.error(`[CognitiveToolsServer v0.7.2] AssessComplexity Tool Signaled: ${assessment_and_choice.substring(0, 150)}...`);
62
+ const mode = assessment_and_choice.includes("Selected Mode: think") ? "think" : "quick_think";
63
+ // Output confirms assessment passed validation and guides the immediate next step (think/quick_think call).
64
+ return { content: [{ type: "text" as const, text: `Cognitive Assessment Completed. Proceeding with selected mode: ${mode}. Full Assessment: ${assessment_and_choice}` }] };
65
+ }
66
+ );
67
+
68
+ server.tool(
69
+ "synthesize_prior_reasoning",
70
+ // Main Description: Aligned with prompt's goal of structured summary to feed into mandatory 'think'.
71
+ "Context Management Tool. Guides internal generation of a **structured summary text** (focusing on **`Key Decisions Made`** and **`Open Questions/Uncertainties`**) for long reasoning chains. Output text MUST be analyzed via mandatory `think` immediately after.",
72
+ {
73
+ // Parameter Description: Reminds LLM of the required internal summary structure.
74
+ context_to_summarize_description: z.string().describe("Describe the reasoning span being summarized. *You* (LLM) must now *internally generate the structured summary text* before calling. This signals the summary is ready for the mandatory post-assessment `think` analysis.")
75
+ },
76
+ async ({ context_to_summarize_description }) => {
77
+ if (!context_to_summarize_description || typeof context_to_summarize_description !== 'string' || context_to_summarize_description.trim().length === 0) { throw new Error('Invalid context description: Must be non-empty.'); }
78
+ console.error(`[CognitiveToolsServer v0.7.2] SynthesizeReasoning Tool Signaled for: ${context_to_summarize_description}...`);
79
+ // Output implies structured summary is ready for analysis via the mandatory next assessment/think steps.
80
+ return { content: [{ type: "text" as const, text: `Structured synthesis internally generated for context: '${context_to_summarize_description}'. Ready for mandatory post-assessment 'think' analysis.` }] };
81
+ }
82
+ );
83
+
84
+ server.tool(
85
+ "gauge_confidence",
86
+ // Main Description: Aligned with prompt's active confidence management feeding into mandatory 'think'.
87
+ "Meta-Cognitive Checkpoint. Guides internal stating of **confidence (High/Medium/Low) and justification**. Output MUST be analyzed in the mandatory `think` step immediately after; Low/Medium confidence requires specific action planning in that `think` step.",
88
+ {
89
+ // Parameter Description: Matches prompt requirements.
90
+ assessment_and_confidence: z.string().describe("Input item being assessed. *Internally determine and state*: 1) Confidence Level (High/Medium/Low). 2) Justification. Call this tool *after* making the assessment.")
91
+ },
92
+ async ({ assessment_and_confidence }) => {
93
+ const confidenceRegex = /Confidence Level: (High|Medium|Low)/i;
94
+ if (!assessment_and_confidence || typeof assessment_and_confidence !== 'string' || !confidenceRegex.test(assessment_and_confidence)) { throw new Error('Invalid confidence assessment: String must include "Confidence Level: High/Medium/Low" and justification.'); }
95
+ const match = assessment_and_confidence.match(confidenceRegex);
96
+ const level = match ? match[1] : "Unknown";
97
+ console.error(`[CognitiveToolsServer v0.7.2] GaugeConfidence Tool Signaled: Level ${level}`);
98
+ // Output confirms level and prepares for mandatory analysis via assessment/think.
99
+ return { content: [{ type: "text" as const, text: `Confidence Gauge Completed. Level: ${level}. Assessment Text: ${assessment_and_confidence}. Ready for mandatory post-assessment 'think' analysis (action required if Low/Medium).` }] };
100
+ }
101
+ );
102
+
103
+ // --- Supporting Cognitive Strategy Tools (Trigger Mandatory 'Think' Analysis After) ---
104
+
105
+ server.tool(
106
+ "plan_and_solve",
107
+ // Main Description: Aligned with proactive planning including risks and tool awareness.
108
+ "Guides internal generation of **structured plan text** (incl. **`Anticipated Challenges/Risks`** and potential **other tool needs**). Generated text MUST be analyzed via mandatory `think` immediately after.",
109
+ {
110
+ // Parameter Description: Reminds LLM of required internal generation content.
111
+ task_objective: z.string().describe("Input the objective. *You* (LLM) must now *internally generate the structured plan text (incl. Risks/Challenges, potential tool needs)* before calling. Signals plan text is ready for mandatory post-assessment `think` analysis.")
112
+ },
113
+ async ({ task_objective }) => {
114
+ if (!task_objective || typeof task_objective !== 'string' || task_objective.trim().length === 0) { throw new Error('Invalid task objective.'); }
115
+ console.error(`[CognitiveToolsServer v0.7.2] PlanAndSolve Tool Signaled for: ${task_objective.substring(0, 100)}...`);
116
+ // Output implies plan text *with risks and potential tool needs* is ready for mandatory analysis via assessment/think.
117
+ return { content: [{ type: "text" as const, text: `Structured plan (incl. Risks/Challenges, potential tool needs) internally generated for objective: ${task_objective}. Ready for mandatory post-assessment 'think' analysis.` }] };
118
+ }
119
+ );
120
+
121
+ server.tool(
122
+ "chain_of_thought",
123
+ // Main Description: Refined to explicitly mention potential for other tools within the reasoning.
124
+ "Guides internal generation of **detailed, step-by-step reasoning text (CoT)**. CoT steps might identify needs for **other tools**. Generated CoT text MUST be analyzed via mandatory `think` immediately after.",
125
+ {
126
+ // Parameter Description: Explicitly guides internal generation to consider tool needs.
127
+ problem_statement: z.string().describe("Input the specific problem requiring detailed CoT. *You* (LLM) must now *internally generate the full CoT text*, explicitly noting steps suggesting needs for other tools. Call this tool *after* generating the text.")
128
+ },
129
+ async ({ problem_statement }) => {
130
+ if (!problem_statement || typeof problem_statement !== 'string' || problem_statement.trim().length === 0) { throw new Error('Invalid problem statement.'); }
131
+ console.error(`[CognitiveToolsServer v0.7.2] ChainOfThought Tool Signaled for: ${problem_statement.substring(0, 100)}...`);
132
+ // Output implies CoT text *potentially identifying tool needs* is ready for mandatory analysis via assessment/think.
133
+ return { content: [{ type: "text" as const, text: `Detailed CoT (potentially identifying needs for other tools) internally generated for problem: ${problem_statement}. Ready for mandatory post-assessment 'think' analysis.` }] };
134
+ }
135
+ );
136
+
137
+ server.tool(
138
+ "chain_of_draft",
139
+ // Main Description: Positions for efficient exploration, results analyzed by mandatory 'think'.
140
+ "Guides internal generation of **concise, iterative reasoning draft texts** ('thought-sketches') for exploring options. Generated drafts MUST be analyzed comparatively via mandatory `think` immediately after.",
141
+ {
142
+ // Parameter Description: Instructs LLM on internal draft generation.
143
+ problem_statement: z.string().describe("Input problem for exploration. *You* (LLM) must now *internally generate brief, iterative draft texts* before calling. Signals drafts are ready for mandatory post-assessment `think` analysis.")
144
+ },
145
+ async ({ problem_statement }) => {
146
+ if (!problem_statement || typeof problem_statement !== 'string' || problem_statement.trim().length === 0) { throw new Error('Invalid problem statement.'); }
147
+ console.error(`[CognitiveToolsServer v0.7.2] ChainOfDraft Tool Signaled for: ${problem_statement.substring(0, 100)}...`);
148
+ // Output implies draft texts are ready for mandatory comparative analysis via assessment/think.
149
+ return { content: [{ type: "text" as const, text: `Reasoning drafts internally generated for problem: ${problem_statement}. Ready for mandatory post-assessment 'think' analysis.` }] };
150
+ }
151
+ );
152
+
153
+ server.tool(
154
+ "reflection",
155
+ // Main Description: Explicitly mentions taking prior text as input for critique, results analyzed by mandatory 'think'.
156
+ "Guides internal critical self-evaluation on **previously generated text** (reasoning, plans, code concepts). Generated critique text MUST be analyzed via mandatory `think` immediately after.",
157
+ {
158
+ // Parameter Description: Input is the specific text to be critiqued internally.
159
+ input_reasoning_or_plan: z.string().describe("Input the **exact text** to be critiqued. *You* (LLM) must now *internally generate a critique* identifying flaws/improvements. Call this tool *after* generating the critique.")
160
+ },
161
+ async ({ input_reasoning_or_plan }) => {
162
+ if (!input_reasoning_or_plan || typeof input_reasoning_or_plan !== 'string' || input_reasoning_or_plan.trim().length === 0) { throw new Error('Invalid input reasoning/plan.'); }
163
+ console.error(`[CognitiveToolsServer v0.7.2] Reflection Tool Signaled for analysis.`);
164
+ // Output implies critique text is ready for mandatory analysis via assessment/think.
165
+ return { content: [{ type: "text" as const, text: `Reflection critique internally generated for input text: '${input_reasoning_or_plan.substring(0, 100)}...'. Ready for mandatory post-assessment 'think' analysis.` }] };
166
+ }
167
+ );
168
+
169
+ // --- Server Lifecycle and Error Handling ---
170
+
171
+ process.on('SIGINT', async () => {
172
+ console.error('\n[CognitiveToolsServer v0.7.2] Received SIGINT, shutting down gracefully.');
173
+ await server.close();
174
+ process.exit(0);
175
+ });
176
+
177
+ process.on('SIGTERM', async () => {
178
+ console.error('\n[CognitiveToolsServer v0.7.2] Received SIGTERM, shutting down gracefully.');
179
+ await server.close();
180
+ process.exit(0);
181
+ });
182
+
183
+ process.on('uncaughtException', (error) => {
184
+ console.error('[CognitiveToolsServer v0.7.2] FATAL: Uncaught Exception:', error);
185
+ server.close().catch(err => console.error('[CognitiveToolsServer v0.7.2] Error during shutdown on uncaughtException:', err)).finally(() => {
186
+ process.exit(1); // Exit on fatal error
187
+ });
188
+ });
189
+
190
+ process.on('unhandledRejection', (reason, promise) => {
191
+ console.error('[CognitiveToolsServer v0.7.2] FATAL: Unhandled Promise Rejection:', reason);
192
+ server.close().catch(err => console.error('[CognitiveToolsServer v0.7.2] Error during shutdown on unhandledRejection:', err)).finally(() => {
193
+ process.exit(1); // Exit on fatal error
194
+ });
195
+ });
196
+
197
+ // Start the server
198
+ async function main() {
199
+ try {
200
+ const transport = new StdioServerTransport();
201
+ await server.connect(transport);
202
+ console.error('ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Gikendaasowin Aabajichiganan - (Cognitive Tools v0.7.2) MCP Server running on stdio');
203
+ }
204
+ catch (error) {
205
+ console.error('[CognitiveToolsServer v0.7.2] Fatal error during startup:', error);
206
+ process.exit(1);
207
+ }
208
+ }
209
+
210
+ // Execute the main function to start the server
211
+ main();