get_thought_stats
Retrieves summary statistics about recorded thoughts, including counts and aggregated data.
Instructions
Get statistics about recorded thoughts
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/think.ts:115-148 (handler)The actual handler function for the get_thought_stats tool. It computes statistics (totalThoughts, averageLength, oldestThought, newestThought) from the in-memory thoughts array and returns them as JSON.
// Register get_thought_stats command server.tool( "get_thought_stats", "Get statistics about recorded thoughts", async () => { const totalThoughts = thoughts.length; let statsData; // Renamed to avoid conflict with exported interface if (totalThoughts === 0) { statsData = { totalThoughts: 0, averageLength: 0, oldestThought: null, newestThought: null }; } else { const averageLength = thoughts.reduce((acc, thought) => acc + thought.content.length, 0) / totalThoughts; statsData = { totalThoughts, averageLength: parseFloat(averageLength.toFixed(2)), oldestThought: thoughts[0].timestamp, newestThought: thoughts[thoughts.length - 1].timestamp }; } return { content: [{ type: "text", text: JSON.stringify(statsData, null, 2) }] }; } ); - src/mcp/think.ts:115-148 (registration)Registration of the get_thought_stats tool via server.tool() call inside registerThinkTool(). The tool is registered with description 'Get statistics about recorded thoughts' and no required input schema.
// Register get_thought_stats command server.tool( "get_thought_stats", "Get statistics about recorded thoughts", async () => { const totalThoughts = thoughts.length; let statsData; // Renamed to avoid conflict with exported interface if (totalThoughts === 0) { statsData = { totalThoughts: 0, averageLength: 0, oldestThought: null, newestThought: null }; } else { const averageLength = thoughts.reduce((acc, thought) => acc + thought.content.length, 0) / totalThoughts; statsData = { totalThoughts, averageLength: parseFloat(averageLength.toFixed(2)), oldestThought: thoughts[0].timestamp, newestThought: thoughts[thoughts.length - 1].timestamp }; } return { content: [{ type: "text", text: JSON.stringify(statsData, null, 2) }] }; } ); - src/mcp/think.ts:11-17 (schema)ThoughtStats interface defining the shape of the return value: totalThoughts (number), averageLength (number), oldestThought (string|null), newestThought (string|null).
export interface ThoughtStats { [key: string]: number | string | null; totalThoughts: number; averageLength: number; oldestThought: string | null; newestThought: string | null; } - src/mcp/think.ts:38-59 (helper)getThoughtStats() method on ThinkToolInternalLogic class - a helper that computes the same stats, used by the exported class but separate from the closure-based handler in registerThinkTool().
getThoughtStats(): ThoughtStats { const totalThoughts = this.thoughts.length; if (totalThoughts === 0) { return { totalThoughts: 0, averageLength: 0, oldestThought: null, newestThought: null }; } const averageLength = this.thoughts.reduce((acc, thought) => acc + thought.content.length, 0) / totalThoughts; return { totalThoughts, averageLength: parseFloat(averageLength.toFixed(2)), // Keep formatted oldestThought: this.thoughts[0].timestamp, newestThought: this.thoughts[this.thoughts.length - 1].timestamp }; } - src/index.ts:10-10 (registration)Import of registerThinkTool from './mcp/think.js' in the main entry point.
import { registerThinkTool } from "./mcp/think.js";