from dataclasses import dataclass, field
from dedalus_mcp import MCPServer, tool
@dataclass
class ThinkingState:
thoughts: list[dict] = field(default_factory=list)
branches: dict[str, list[dict]] = field(default_factory=dict)
state = ThinkingState()
@tool(description="""Step-by-step reasoning with revision support.
Use when:
- Breaking down complex problems
- Planning that might need course correction
- Analysis where the full scope isn't clear initially
You can revise previous thoughts, branch into alternatives, or extend
beyond your initial estimate.""")
def think(
thought: str,
thought_number: int,
total_thoughts: int,
next_thought_needed: bool,
is_revision: bool = False,
revises_thought: int | None = None,
branch_id: str | None = None,
) -> dict:
entry = {
"number": thought_number,
"thought": thought,
"is_revision": is_revision,
"revises": revises_thought,
}
if branch_id:
state.branches.setdefault(branch_id, []).append(entry)
else:
state.thoughts.append(entry)
return {
"thought_number": thought_number,
"total_thoughts": total_thoughts,
"next_thought_needed": next_thought_needed,
"history_length": len(state.thoughts),
"branches": list(state.branches.keys()),
}
server = MCPServer("reasoning")
server.collect(think)