@emmahyde/thinking-patterns
Version:
MCP server combining systematic thinking, mental models, debugging approaches, and stochastic algorithms for comprehensive cognitive pattern support
101 lines (100 loc) • 4.98 kB
JavaScript
import { BaseToolServer } from '../base/BaseToolServer.js';
import { MetacognitiveMonitoringSchema } from '../schemas/index.js';
import { boxed } from '../utils/index.js';
/**
* Metacognitive Monitoring Server using thinking-patterns tools approach
* Extends BaseToolServer for standardized validation and error handling
*/
export class MetacognitiveMonitoringServer extends BaseToolServer {
constructor() {
super(MetacognitiveMonitoringSchema);
}
handle(validInput) {
return this.process(validInput);
}
/**
* Standardized process method for metacognitive monitoring
* @param validInput - Validated metacognitive monitoring data
* @returns Processed metacognitive monitoring result
*/
process(validInput) {
// Format output using boxed utility
const formattedOutput = this.formatMetacognitiveOutput(validInput);
// Log formatted output to console (suppress during tests)
if (process.env.NODE_ENV !== 'test' && process.env.JEST_WORKER_ID === undefined) {
console.error(formattedOutput);
}
return {
task: validInput.task,
monitoringId: validInput.monitoringId,
stage: validInput.stage,
iteration: validInput.iteration,
overallConfidence: validInput.overallConfidence,
knowledgeAssessment: validInput.knowledgeAssessment,
claims: validInput.claims,
reasoningSteps: validInput.reasoningSteps,
uncertaintyAreas: validInput.uncertaintyAreas,
recommendedApproach: validInput.recommendedApproach,
suggestedAssessments: validInput.suggestedAssessments,
previousSteps: validInput.previousSteps,
remainingSteps: validInput.remainingSteps,
toolUsageHistory: validInput.toolUsageHistory,
nextAssessmentNeeded: validInput.nextAssessmentNeeded,
status: 'success',
uncertaintyAreaCount: validInput.uncertaintyAreas.length,
hasKnowledgeAssessment: !!validInput.knowledgeAssessment,
claimCount: validInput.claims?.length ?? 0,
reasoningStepCount: validInput.reasoningSteps?.length ?? 0,
hasSuggestedAssessments: !!validInput.suggestedAssessments && validInput.suggestedAssessments.length > 0,
hasPreviousSteps: !!validInput.previousSteps && validInput.previousSteps.length > 0,
hasRemainingSteps: !!validInput.remainingSteps && validInput.remainingSteps.length > 0,
hasToolUsageHistory: !!validInput.toolUsageHistory && validInput.toolUsageHistory.length > 0,
timestamp: new Date().toISOString(),
};
}
formatMetacognitiveOutput(data) {
const sections = {
'Task': data.task,
'Stage': data.stage.replace('-', ' ').toUpperCase(),
'Monitoring ID': data.monitoringId,
'Iteration': data.iteration.toString(),
'Overall Confidence': `${(data.overallConfidence * 100).toFixed(1)}%`
};
// Knowledge assessment
if (data.knowledgeAssessment) {
const ka = data.knowledgeAssessment;
sections['Knowledge Assessment'] = [
`Domain: ${ka.domain}`,
`Level: ${ka.knowledgeLevel.toUpperCase()}`,
`Confidence: ${(ka.confidenceScore * 100).toFixed(1)}%`,
`Evidence: ${ka.supportingEvidence}`
];
if (ka.knownLimitations.length > 0) {
sections['Known Limitations'] = ka.knownLimitations.map(limitation => `• ${limitation}`);
}
}
// Claims assessment
if (data.claims && data.claims.length > 0) {
sections['Claims Assessment'] = data.claims.map(claim => `• ${claim.claim} (${claim.status.toUpperCase()}, ${(claim.confidenceScore * 100).toFixed(0)}%)`);
}
// Reasoning steps assessment
if (data.reasoningSteps && data.reasoningSteps.length > 0) {
sections['Reasoning Assessment'] = data.reasoningSteps.map(step => {
const validity = (step.logicalValidity * 100).toFixed(0);
const strength = (step.inferenceStrength * 100).toFixed(0);
return `• ${step.step} (Logic: ${validity}%, Inference: ${strength}%)`;
});
}
// Uncertainty areas
if (data.uncertaintyAreas.length > 0) {
sections['Uncertainty Areas'] = data.uncertaintyAreas.map(area => `• ${area}`);
}
// Recommended approach
sections['Recommended Approach'] = data.recommendedApproach;
// Suggested assessments
if (data.suggestedAssessments && data.suggestedAssessments.length > 0) {
sections['Suggested Next Assessments'] = data.suggestedAssessments.map(assessment => `• ${assessment}`);
}
return boxed('🧭 Metacognitive Monitoring', sections);
}
}