@nbiish/cognitive-tools-mcp 0.9.29 → 0.9.30
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/build/index.js +87 -92
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* -----------------------------------------------------------------------------
|
|
4
|
-
* Gikendaasowin Aabajichiganan - Core
|
|
4
|
+
* Gikendaasowin Aabajichiganan - Core Cognitive Tools MCP Server (v1.2 - Generalized)
|
|
5
5
|
*
|
|
6
|
-
* Description: Provides a
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Description: Provides a streamlined suite of cognitive tools for an AI agent,
|
|
7
|
+
* inspired by research on improving LLM reasoning (like Anthropic's 'think' tool)
|
|
8
|
+
* applicable across domains (coding, research, planning, etc.).
|
|
9
|
+
* Focuses on assessment (`assess_cuc_n_mode`) and a central deliberation
|
|
10
|
+
* hub (`think`) used especially after receiving information/results.
|
|
11
|
+
* `quick_think` is for trivial steps. CoT/CoD reasoning styles occur within `think`.
|
|
12
|
+
* Returns Markdown.
|
|
10
13
|
*
|
|
11
14
|
* Key Principles:
|
|
12
|
-
* 1. **
|
|
13
|
-
*
|
|
14
|
-
* 2. **
|
|
15
|
-
*
|
|
16
|
-
* 3. **
|
|
17
|
-
* 4. **
|
|
18
|
-
* 5. **
|
|
15
|
+
* 1. **Structured Deliberation:** Tools guide assessment (`assess_cuc_n_mode`) and
|
|
16
|
+
* thinking/analysis (`think`, `quick_think`).
|
|
17
|
+
* 2. **Centralized Analysis (`think`):** The `think` tool is the hub for analysis (results, errors),
|
|
18
|
+
* planning, reflection, policy checks, and reasoning (CoT/CoD). **Crucially used after info/results.**
|
|
19
|
+
* 3. **CUC-N Assessment:** `assess_cuc_n_mode` guides initial cognitive depth choice.
|
|
20
|
+
* 4. **Iterative Loop:** Assess -> [Action/Tool] -> Analyze Result/State (`think`) -> Plan (`think`) -> [Execute].
|
|
21
|
+
* 5. **Traceability & Reliability:** Tool inputs logged; structured thinking enhances reliability across tasks.
|
|
22
|
+
* 6. **Markdown Output:** Tool results formatted as Markdown.
|
|
19
23
|
*
|
|
20
24
|
* Protocol: Model Context Protocol (MCP) over stdio.
|
|
21
25
|
* -----------------------------------------------------------------------------
|
|
@@ -25,122 +29,107 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
25
29
|
import { z } from "zod";
|
|
26
30
|
// --- Server Definition ---
|
|
27
31
|
const serverInfo = {
|
|
28
|
-
name: "gikendaasowin-aabajichiganan-mcp
|
|
29
|
-
version: "
|
|
30
|
-
description: `ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Core
|
|
32
|
+
name: "gikendaasowin-aabajichiganan-mcp",
|
|
33
|
+
version: "1.2.0", // Incremented version
|
|
34
|
+
description: `ᑭᑫᓐᑖᓱᐎᓐ ᐋᐸᒋᒋᑲᓇᓐ - Core Cognitive Tools (Generalized v1.2): Focuses on Assess/Think loop, using 'think' for post-result/state analysis across domains (code, research, etc.) to improve reliability. CoT/CoD integrated into 'think'. Returns Markdown.`
|
|
31
35
|
};
|
|
32
36
|
const server = new McpServer(serverInfo);
|
|
33
37
|
// --- Logging Helpers ---
|
|
38
|
+
// [Keep existing logToolCall, logToolResult, logToolError functions]
|
|
34
39
|
/**
|
|
35
|
-
* Logs an incoming
|
|
36
|
-
* @param toolName The name of the
|
|
40
|
+
* Logs an incoming tool call to stderr.
|
|
41
|
+
* @param toolName The name of the tool being called.
|
|
37
42
|
* @param details Optional additional details about the call.
|
|
38
43
|
*/
|
|
39
44
|
function logToolCall(toolName, details) {
|
|
40
45
|
const timestamp = new Date().toISOString();
|
|
41
|
-
console.error(`[${timestamp}] [MCP Server
|
|
46
|
+
console.error(`[${timestamp}] [MCP Server] > Tool Call: ${toolName}${details ? ` - ${details}` : ''}`);
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
|
-
* Logs the result (success or failure) of
|
|
45
|
-
* @param toolName The name of the
|
|
49
|
+
* Logs the result (success or failure) of a tool execution to stderr.
|
|
50
|
+
* @param toolName The name of the tool executed.
|
|
46
51
|
* @param success Whether the execution was successful.
|
|
47
52
|
* @param resultDetails Optional details about the result.
|
|
48
53
|
*/
|
|
49
54
|
function logToolResult(toolName, success, resultDetails) {
|
|
50
55
|
const timestamp = new Date().toISOString();
|
|
51
|
-
console.error(`[${timestamp}] [MCP Server
|
|
56
|
+
console.error(`[${timestamp}] [MCP Server] < Tool Result: ${toolName} - ${success ? 'Success' : 'Failure'}${resultDetails ? ` - ${resultDetails}` : ''}`);
|
|
52
57
|
}
|
|
53
58
|
/**
|
|
54
|
-
* Logs an error during
|
|
55
|
-
*
|
|
56
|
-
* @param toolName The name of the internal tool where the error occurred.
|
|
59
|
+
* Logs an error during tool execution and formats a standard error response for the LLM.
|
|
60
|
+
* @param toolName The name of the tool where the error occurred.
|
|
57
61
|
* @param error The error object or message.
|
|
58
62
|
* @returns An object matching the required MCP tool result structure containing the error message.
|
|
59
63
|
*/
|
|
60
64
|
function logToolError(toolName, error) {
|
|
61
65
|
const timestamp = new Date().toISOString();
|
|
62
66
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
63
|
-
console.error(`[${timestamp}] [MCP Server
|
|
64
|
-
logToolResult(toolName, false, errorMessage); // Log failure result
|
|
65
|
-
// Return a structured error message
|
|
67
|
+
console.error(`[${timestamp}] [MCP Server] ! Tool Error: ${toolName} - ${errorMessage}`);
|
|
68
|
+
logToolResult(toolName, false, errorMessage); // Log failure result as well
|
|
69
|
+
// Return a structured error message suitable for the LLM
|
|
66
70
|
return {
|
|
67
71
|
content: [{
|
|
68
72
|
type: "text",
|
|
69
|
-
|
|
70
|
-
text: `INTERNAL Tool Execution Failed:\nTool: ${toolName}\nError: ${errorMessage}\n\n**Action Required: Immediately use the 'think' tool to analyze this failure (Observe, Orient, Decide, Reason...) before proceeding.**`
|
|
73
|
+
text: `Error executing tool '${toolName}': ${errorMessage}. Use the 'think' tool to analyze this error, check context, and plan the next step.` // Enhanced suggestion
|
|
71
74
|
}]
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
|
-
// --- Core
|
|
77
|
+
// --- Core Cognitive Deliberation & Refinement Tools ---
|
|
75
78
|
/**
|
|
76
|
-
* Tool: assess_cuc_n_mode
|
|
77
|
-
* Purpose:
|
|
78
|
-
* Workflow: Call
|
|
79
|
-
* Output: Returns the assessment text formatted as Markdown
|
|
79
|
+
* Tool: assess_cuc_n_mode
|
|
80
|
+
* Purpose: Initial assessment of task characteristics to guide cognitive strategy selection.
|
|
81
|
+
* Workflow: Call BEFORE starting complex tasks or significantly changing strategy.
|
|
82
|
+
* Output: Returns the full assessment text formatted as Markdown.
|
|
80
83
|
*/
|
|
81
|
-
server.tool("assess_cuc_n_mode", "**
|
|
82
|
-
assessment_and_choice: z.string().
|
|
83
|
-
.includes("Selected Mode:", { message: "Assessment MUST include 'Selected Mode: think' or 'Selected Mode: quick_think'." }) // Enforce selection presence
|
|
84
|
-
.describe("Your internal structured CUC-N assessment (Situation, Ratings, Rationale, Strategy) concluding with the MANDATORY 'Selected Mode: think' or 'Selected Mode: quick_think' line. This dictates the next internal tool call.")
|
|
84
|
+
server.tool("assess_cuc_n_mode", "**Initial Assessment.** Evaluates task Complexity, Uncertainty, Consequence, Novelty (CUC-N) to guide cognitive strategy. Call before complex tasks (coding, research, multi-step plans). Based on assessment, explicitly select and state whether the next step requires the detailed `think` tool (for analysis, planning, complex results) or the minimal `quick_think` tool (for trivial steps only).", {
|
|
85
|
+
assessment_and_choice: z.string().describe("Your structured assessment including: 1) Situation/Task Description, 2) CUC-N Ratings (Low/Medium/High for each), 3) Rationale, 4) Recommended Cognitive Strategy (e.g., 'Requires careful step-by-step planning'), 5) Explicit Mode Selection ('Selected Mode: think' or 'Selected Mode: quick_think').")
|
|
85
86
|
}, async ({ assessment_and_choice }) => {
|
|
86
87
|
const toolName = 'assess_cuc_n_mode';
|
|
87
88
|
logToolCall(toolName);
|
|
88
89
|
try {
|
|
89
|
-
// Zod validation now handles non-empty and presence of "Selected Mode:"
|
|
90
90
|
const modeRegex = /Selected Mode: (think|quick_think)/i;
|
|
91
91
|
const modeMatch = assessment_and_choice.match(modeRegex);
|
|
92
|
-
|
|
92
|
+
const selectedMode = modeMatch ? modeMatch[1].toLowerCase() : "unknown";
|
|
93
|
+
if (assessment_and_choice.trim().length === 0) {
|
|
94
|
+
throw new Error('Invalid assessment_and_choice: Must be a non-empty string.');
|
|
95
|
+
}
|
|
93
96
|
if (!modeMatch) {
|
|
94
|
-
throw new Error(
|
|
97
|
+
throw new Error('Invalid assessment: String must include explicit "Selected Mode: think" or "Selected Mode: quick_think".');
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.error(`[${new Date().toISOString()}] [MCP Server - INTERNAL] - ${toolName} Input:\n${assessment_and_choice}`);
|
|
99
|
-
// Return the assessment text as a log/confirmation
|
|
99
|
+
logToolResult(toolName, true, `Selected mode (extracted): ${selectedMode}`);
|
|
100
|
+
console.error(`[${new Date().toISOString()}] [MCP Server] - ${toolName} Input:\n${assessment_and_choice}`);
|
|
100
101
|
return {
|
|
101
102
|
content: [{
|
|
102
103
|
type: "text",
|
|
103
|
-
|
|
104
|
-
text: `Internal CUC-N Assessment Logged. Mandatory Next Step: ${selectedMode}\n---\nAssessment Details:\n${assessment_and_choice}`
|
|
104
|
+
text: assessment_and_choice
|
|
105
105
|
}]
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
catch (error) {
|
|
109
|
-
// Catch Zod errors or other exceptions
|
|
110
109
|
return logToolError(toolName, error);
|
|
111
110
|
}
|
|
112
111
|
});
|
|
113
112
|
/**
|
|
114
|
-
* Tool: think
|
|
115
|
-
* Purpose: The **
|
|
116
|
-
* Workflow: Use
|
|
117
|
-
* Output: Returns the structured thought text itself as
|
|
113
|
+
* Tool: think
|
|
114
|
+
* Purpose: The **CENTRAL HUB** for structured reasoning, analysis, and planning across all complex tasks.
|
|
115
|
+
* Workflow: Use this tool to **stop and think** *after* receiving information (tool results, calculations, user input, file content) or *before* taking a complex action (generating code, calling critical tools, formulating multi-part answers). Analyze inputs/results, check goals/policies/constraints, verify state, plan next steps, brainstorm, and perform detailed reasoning (CoT/CoD). Essential for reliability, error handling, and managing sequential tasks.
|
|
116
|
+
* Output: Returns the structured thought text itself, formatted as Markdown.
|
|
118
117
|
*/
|
|
119
|
-
server.tool("think", "**
|
|
120
|
-
thought: z.string().
|
|
121
|
-
// Enforce presence of key OODReAct sections for structure
|
|
122
|
-
.includes("## Observe:", { message: "Thought MUST include '## Observe:' section." })
|
|
123
|
-
.includes("## Orient:", { message: "Thought MUST include '## Orient:' section." })
|
|
124
|
-
.includes("## Decide:", { message: "Thought MUST include '## Decide:' section." })
|
|
125
|
-
.includes("## Reason:", { message: "Thought MUST include '## Reason:' section where CoT/CoD happens." })
|
|
126
|
-
// Add more checks as needed (Act, Verification, etc.) if strict enforcement is desired
|
|
127
|
-
// .includes("## Act:", "Thought MUST include '## Act:' section.")
|
|
128
|
-
// .includes("## Verification:", "Thought MUST include '## Verification:' section.")
|
|
129
|
-
// .includes("## Risk & Contingency:", "Thought MUST include '## Risk & Contingency:' section.")
|
|
130
|
-
// .includes("## Learning & Adaptation:", "Thought MUST include '## Learning & Adaptation:' section.")
|
|
131
|
-
.describe("Your **detailed internal monologue** STRICTLY following the OODReAct structure. Cover analysis (Observe), context (Orient), next step (Decide), detailed rationale/CoT/CoD (Reason), execution plan (Act), success checks (Verification), risks (Risk), and learning (Learning). This is purely for internal reasoning.")
|
|
118
|
+
server.tool("think", "**Central Hub for Analysis, Planning & Reasoning.** Use this tool to **stop and think**, especially *after* receiving information (tool results, errors, data) or before complex actions (coding, critical decisions). Analyze inputs/results, check goals/policies, verify information, plan next steps, and perform detailed reasoning (CoT/CoD) as needed. Crucial for reliability in coding, research, planning, and error recovery. Structure thought using clear headings (see prompt examples).", {
|
|
119
|
+
thought: z.string().describe("Your **structured** internal deliberation. MUST follow prompt guidance (Observe, Orient, Decide, Reason, Act, etc.). Include analysis of information/results, context/goal/policy checks, planning, and rationale (CoT/CoD). Crucial for complex tasks.")
|
|
132
120
|
}, async ({ thought }) => {
|
|
133
121
|
const toolName = 'think';
|
|
134
122
|
logToolCall(toolName);
|
|
135
123
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
124
|
+
if (thought.trim().length === 0) {
|
|
125
|
+
throw new Error('Invalid thought: Must be a non-empty string containing substantive reasoning, following the prompted structure.');
|
|
126
|
+
}
|
|
127
|
+
logToolResult(toolName, true, `Thought logged (length: ${thought.length})`);
|
|
128
|
+
console.error(`[${new Date().toISOString()}] [MCP Server] - ${toolName} Input:\n${thought}`);
|
|
140
129
|
return {
|
|
141
130
|
content: [{
|
|
142
131
|
type: "text",
|
|
143
|
-
text:
|
|
132
|
+
text: thought
|
|
144
133
|
}]
|
|
145
134
|
};
|
|
146
135
|
}
|
|
@@ -149,27 +138,30 @@ server.tool("think", "**INTERNAL Use Only. Mandatory Central Hub for Reasoning.*
|
|
|
149
138
|
}
|
|
150
139
|
});
|
|
151
140
|
/**
|
|
152
|
-
* Tool: quick_think
|
|
153
|
-
* Purpose:
|
|
154
|
-
* Workflow: Use
|
|
155
|
-
* Output: Returns the brief thought text as
|
|
141
|
+
* Tool: quick_think
|
|
142
|
+
* Purpose: A minimal cognitive step for trivial actions or confirmations.
|
|
143
|
+
* Workflow: Use ONLY for acknowledging *trivial* successes, simple variable passing, or confirming *immediately obvious* next steps where NO analysis, planning, policy check, or complex reasoning (handled by `think`) is needed. Use sparingly; prefer `think` for analyzing any tool output, error, or planning non-trivial actions.
|
|
144
|
+
* Output: Returns the brief thought text, formatted as Markdown.
|
|
156
145
|
*/
|
|
157
|
-
server.tool("quick_think", "**
|
|
158
|
-
brief_thought: z.string().
|
|
159
|
-
.max(200, "Brief thought should be concise (max 200 chars). Use 'think' for detail.") // Add max length
|
|
160
|
-
.describe("Your **concise internal** confirmation for a verified trivial step (e.g., 'Acknowledged trivial success: file read OK.'). Use ONLY when full deliberation via 'think' is explicitly unnecessary per assessment.")
|
|
146
|
+
server.tool("quick_think", "**Minimal Cognitive Step (Use Sparingly!).** Use ONLY for acknowledging *trivial* successes or confirming *obvious* next steps where NO analysis, planning, or policy check is needed (e.g., 'Action X succeeded, proceeding to Y'). All substantive analysis, error handling, planning, and reasoning (CoT/CoD) belongs in the `think` tool. Prefer `think` after most tool calls or before complex actions.", {
|
|
147
|
+
brief_thought: z.string().describe("Your **extremely concise** confirmation or trivial thought (e.g., 'Tool success, continue', 'Passing ID to next step'). Must be non-empty but very short. Do NOT use for analysis or planning.")
|
|
161
148
|
}, async ({ brief_thought }) => {
|
|
162
149
|
const toolName = 'quick_think';
|
|
163
150
|
logToolCall(toolName);
|
|
164
151
|
try {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
//
|
|
152
|
+
if (brief_thought.trim().length === 0) {
|
|
153
|
+
throw new Error('Invalid brief_thought: Must be a non-empty string.');
|
|
154
|
+
}
|
|
155
|
+
// Optional: Add a length check if you want to enforce brevity strictly
|
|
156
|
+
// if (brief_thought.length > 100) { // Example limit
|
|
157
|
+
// throw new Error('Invalid brief_thought: Input is too long for quick_think. Use think tool for detailed reasoning.');
|
|
158
|
+
// }
|
|
159
|
+
logToolResult(toolName, true, `Logged: ${brief_thought.substring(0, 80)}...`);
|
|
160
|
+
console.error(`[${new Date().toISOString()}] [MCP Server] - ${toolName} Input:\n${brief_thought}`);
|
|
169
161
|
return {
|
|
170
162
|
content: [{
|
|
171
163
|
type: "text",
|
|
172
|
-
text:
|
|
164
|
+
text: brief_thought
|
|
173
165
|
}]
|
|
174
166
|
};
|
|
175
167
|
}
|
|
@@ -177,19 +169,20 @@ server.tool("quick_think", "**INTERNAL Use Only. Trivial Confirmation Checkpoint
|
|
|
177
169
|
return logToolError(toolName, error);
|
|
178
170
|
}
|
|
179
171
|
});
|
|
180
|
-
// --- Server Lifecycle and Error Handling ---
|
|
172
|
+
// --- Server Lifecycle and Error Handling ---
|
|
173
|
+
// [Keep existing shutdown, process event handlers, main function]
|
|
181
174
|
/**
|
|
182
175
|
* Gracefully shuts down the server.
|
|
183
176
|
*/
|
|
184
177
|
async function shutdown() {
|
|
185
|
-
console.error('\n[MCP Server
|
|
178
|
+
console.error('\n[MCP Server] Shutting down gracefully...');
|
|
186
179
|
try {
|
|
187
180
|
await server.close();
|
|
188
|
-
console.error('[MCP Server
|
|
181
|
+
console.error('[MCP Server] Server closed.');
|
|
189
182
|
process.exit(0);
|
|
190
183
|
}
|
|
191
184
|
catch (err) {
|
|
192
|
-
console.error('[MCP Server
|
|
185
|
+
console.error('[MCP Server] Error during shutdown:', err);
|
|
193
186
|
process.exit(1);
|
|
194
187
|
}
|
|
195
188
|
}
|
|
@@ -197,17 +190,19 @@ process.on('SIGINT', shutdown);
|
|
|
197
190
|
process.on('SIGTERM', shutdown);
|
|
198
191
|
process.on('uncaughtException', (error, origin) => {
|
|
199
192
|
const timestamp = new Date().toISOString();
|
|
200
|
-
console.error(`[${timestamp}] [MCP Server
|
|
193
|
+
console.error(`[${timestamp}] [MCP Server] FATAL: Uncaught Exception at: ${origin}`, error);
|
|
194
|
+
// Attempt graceful shutdown, but exit quickly if it fails
|
|
201
195
|
shutdown().catch(() => process.exit(1));
|
|
202
196
|
});
|
|
203
197
|
process.on('unhandledRejection', (reason, promise) => {
|
|
204
198
|
const timestamp = new Date().toISOString();
|
|
205
|
-
console.error(`[${timestamp}] [MCP Server
|
|
199
|
+
console.error(`[${timestamp}] [MCP Server] FATAL: Unhandled Promise Rejection:`, reason);
|
|
200
|
+
// Attempt graceful shutdown, but exit quickly if it fails
|
|
206
201
|
shutdown().catch(() => process.exit(1));
|
|
207
202
|
});
|
|
208
203
|
// --- Start the Server ---
|
|
209
204
|
/**
|
|
210
|
-
* Initializes and starts the MCP server
|
|
205
|
+
* Initializes and starts the MCP server.
|
|
211
206
|
*/
|
|
212
207
|
async function main() {
|
|
213
208
|
try {
|
|
@@ -217,12 +212,12 @@ async function main() {
|
|
|
217
212
|
console.error(border);
|
|
218
213
|
console.error(` ${serverInfo.description}`);
|
|
219
214
|
console.error(` Version: ${serverInfo.version}`);
|
|
220
|
-
console.error(' Status: Running on stdio, awaiting
|
|
215
|
+
console.error(' Status: Running on stdio, awaiting MCP requests...');
|
|
221
216
|
console.error(border);
|
|
222
217
|
}
|
|
223
218
|
catch (error) {
|
|
224
219
|
const timestamp = new Date().toISOString();
|
|
225
|
-
console.error(`[${timestamp}] [MCP Server
|
|
220
|
+
console.error(`[${timestamp}] [MCP Server] Fatal error during startup:`, error);
|
|
226
221
|
process.exit(1);
|
|
227
222
|
}
|
|
228
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nbiish/cognitive-tools-mcp",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.30",
|
|
4
4
|
"description": "Cognitive Tools MCP: SOTA reasoning suite focused on iterative refinement and tool integration for AI Pair Programming. Enables structured, iterative problem-solving through Chain of Draft methodology, with tools for draft generation, analysis, and refinement. Features advanced deliberation (`think`), rapid checks (`quick_think`), mandatory complexity assessment & thought mode selection (`assess_cuc_n_mode`), context synthesis, confidence gauging, proactive planning, explicit reasoning (CoT), and reflection with content return. Alternative package name for gikendaasowin-aabajichiganan-mcp.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|