get_thought_stats
Analyze and generate statistics for recorded thoughts, including count and depth distribution. Filter results by specific categories to gain targeted insights into thought patterns.
Instructions
Get statistics about recorded thoughts.
This tool provides statistics about recorded thoughts, such as count and depth distribution. Results can be filtered by category.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Filter to get stats for a specific category |
Implementation Reference
- Primary FastMCP handler for the 'get_thought_stats' tool. Defines input schema using Pydantic Field (optional category filter), calls the core implementation, and returns JSON-formatted stats.@mcp.tool() def get_thought_stats( category: Optional[str] = Field( description="Filter to get stats for a specific category", default=None ), ) -> str: """ Get statistics about recorded thoughts. This tool provides statistics about recorded thoughts, such as count and depth distribution. Results can be filtered by category. """ # Extract actual value if it's a Field object if hasattr(category, "default"): category = category.default result = get_thought_stats_impl(category) return json.dumps(result, indent=2)
- src/mcp_agile_flow/think_tool.py:256-288 (handler)Core implementation of get_thought_stats logic: filters thoughts by category, computes total count, length of longest thought, and its 1-based index.def get_thought_stats(category: Optional[str] = None) -> Dict[str, Any]: """Get statistics about recorded thoughts.""" thoughts = _storage.get_thoughts() if category: thoughts = [t for t in thoughts if t.get("category") == category] if not thoughts: return { "success": True, "message": "No thoughts have been recorded yet", "stats": {"total_thoughts": 0, "longest_thought_length": 0, "longest_thought_index": 0}, } # Find longest thought longest_idx = 0 longest_len = 0 for i, t in enumerate(thoughts): thought_len = len(t["thought"]) if thought_len > longest_len: longest_len = thought_len longest_idx = i + 1 # 1-based indexing return { "success": True, "message": "Retrieved statistics", "stats": { "total_thoughts": len(thoughts), "longest_thought_length": longest_len, "longest_thought_index": longest_idx, }, }
- ThoughtStorage class and global _storage instance used by get_thought_stats to access stored thoughts.class ThoughtStorage: def __init__(self): self._storage_file = None self._thoughts = [] self._init_storage() def _init_storage(self): """Initialize temporary file for thought storage.""" temp = tempfile.NamedTemporaryFile(prefix="mcp_thoughts_", suffix=".tmp", delete=False) self._storage_file = temp.name temp.close() logger.debug(f"Initialized thought storage using temporary file: {self._storage_file}") def add_thought(self, thought: Dict[str, Any]): """Add a thought to storage.""" self._thoughts.append(thought) self._save() def get_thoughts(self) -> List[Dict[str, Any]]: """Get all stored thoughts.""" return self._thoughts def clear_thoughts(self, category: Optional[str] = None): """Clear stored thoughts, optionally by category.""" if category: self._thoughts = [t for t in self._thoughts if t.get("category") != category] else: self._thoughts = [] self._save() def _save(self): """Save thoughts to storage file.""" with open(self._storage_file, "w") as f: json.dump(self._thoughts, f) # Global storage instance
- src/mcp_agile_flow/fastmcp_tools.py:25-25 (registration)Import of the core get_thought_stats implementation for use in the FastMCP tool handler.from .think_tool import get_thought_stats as get_thought_stats_impl
- src/mcp_agile_flow/__init__.py:108-109 (registration)Registration/dispatching of 'get-thought-stats' tool in the package's call_tool function.elif fastmcp_tool_name == "get-thought-stats": result = get_thought_stats()