@emmahyde/thought-patterns
Version:
MCP server combining systematic thinking, mental models, debugging approaches, and stochastic algorithms for comprehensive cognitive pattern support
79 lines (78 loc) • 2.83 kB
JavaScript
import { BaseToolServer } from '../base/BaseToolServer.js';
import { MentalModelSchema } from '../schemas/index.js';
import { boxed } from '../utils/index.js';
/**
* Mental Model Server using clear-thought tools approach
* Extends BaseToolServer for standardized validation and error handling
*/
export class MentalModelServer extends BaseToolServer {
constructor() {
super(MentalModelSchema);
}
handle(validInput) {
return this.process(validInput);
}
/**
* Standardized process method for mental model
* @param validInput - Validated mental model data
* @returns Processed mental model result
*/
process(validInput) {
// Format output using boxed utility
const formattedOutput = this.formatMentalModelOutput(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 {
modelName: validInput.modelName,
problem: validInput.problem,
status: 'success',
hasSteps: (validInput.steps?.length ?? 0) > 0,
hasConclusion: !!validInput.conclusion,
stepCount: validInput.steps?.length ?? 0,
timestamp: new Date().toISOString(),
framework: 'clear-thought-tools'
};
}
// Backward compatibility method for tests
processModel(input) {
try {
const validatedInput = this.validate(input);
const result = this.handle(validatedInput);
const response = this.run(input);
return {
...response,
data: validatedInput // Add the validated input data for test compatibility
};
}
catch (error) {
return {
content: [{
type: "text",
text: JSON.stringify({
error: error instanceof Error ? error.message : String(error),
status: 'failed'
}, null, 2)
}],
isError: true
};
}
}
formatMentalModelOutput(modelData) {
const sections = {
'Model': modelData.modelName,
'Problem': modelData.problem
};
if (modelData.steps && modelData.steps.length > 0) {
sections['Steps'] = modelData.steps.map(step => `• ${step}`);
}
if (modelData.reasoning) {
sections['Reasoning'] = modelData.reasoning;
}
if (modelData.conclusion) {
sections['Conclusion'] = modelData.conclusion;
}
return boxed('🧠 Mental Model', sections);
}
}