Documentation
¶
Overview ¶
Package thinking implements the criticalthinking MCP tool's data model and per-session state. It has no MCP SDK dependencies; main.go is the adapter that bridges this package to the SDK.
Index ¶
- Constants
- type HistorySnapshot
- type SequentialThinkingServer
- func (s *SequentialThinkingServer) HistoryLength() int
- func (s *SequentialThinkingServer) LastAccessed() time.Time
- func (s *SequentialThinkingServer) ProcessThought(td ThoughtData) (ToolResult, error)
- func (s *SequentialThinkingServer) SessionConfidence() float64
- func (s *SequentialThinkingServer) Snapshot() HistorySnapshot
- type ThoughtData
- type ThoughtResponse
- type ToolResult
Constants ¶
const ToolDescription = `` /* 4507-byte string literal not displayed */
ToolDescription is the verbatim description string registered on the criticalthinking MCP tool. Every agent calling the tool reads this — it is the prompt-engineering contract for thinking out loud + critical self- examination on top of sequential thinking.
Treat changes here as protocol changes: bump the package version and document in the README migration notes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HistorySnapshot ¶
type HistorySnapshot struct {
Thoughts []ThoughtData `json:"thoughts"`
Branches map[string][]ThoughtData `json:"branches,omitempty"`
}
HistorySnapshot returns a deep copy of the trunk + branch thought history, safe to marshal and ship to a resource consumer. Branches are keyed by id.
type SequentialThinkingServer ¶
type SequentialThinkingServer struct {
// contains filtered or unexported fields
}
SequentialThinkingServer holds the per-session state for one client of the criticalthinking tool. Construct exactly one per session: in HTTP mode this happens inside the StreamableHTTP factory closure; in stdio mode there is one global instance for the process.
The factory-closure pattern is the cross-session isolation invariant. There is intentionally no map keyed by session-id anywhere — the closure scope is the only addressable path to a session's state.
func NewServer ¶
func NewServer() *SequentialThinkingServer
NewServer returns an empty SequentialThinkingServer.
func (*SequentialThinkingServer) HistoryLength ¶
func (s *SequentialThinkingServer) HistoryLength() int
HistoryLength returns the number of thoughts in the trunk + branches (a single append-only log).
func (*SequentialThinkingServer) LastAccessed ¶
func (s *SequentialThinkingServer) LastAccessed() time.Time
LastAccessed returns the time of the last successful ProcessThought call. Used by the HTTP idle-timeout cleanup goroutine in main.go.
func (*SequentialThinkingServer) ProcessThought ¶
func (s *SequentialThinkingServer) ProcessThought(td ThoughtData) (ToolResult, error)
ProcessThought validates input, mutates state, and returns either a transcript+structured response or an error result. The Go-level error return is reserved for unrecoverable internal faults (currently never returned); validation failures produce IsError=true results.
func (*SequentialThinkingServer) SessionConfidence ¶
func (s *SequentialThinkingServer) SessionConfidence() float64
SessionConfidence returns the running mean confidence over trunk thoughts. Returns 0 when no trunk thoughts have been recorded.
func (*SequentialThinkingServer) Snapshot ¶
func (s *SequentialThinkingServer) Snapshot() HistorySnapshot
Snapshot returns the current state for the thinking://current resource. The returned slices and map are safe to mutate without affecting the server.
type ThoughtData ¶
type ThoughtData struct {
Thought string `json:"thought"`
ThoughtNumber int `json:"thoughtNumber"`
TotalThoughts int `json:"totalThoughts"`
NextThoughtNeeded *bool `json:"nextThoughtNeeded"`
IsRevision *bool `json:"isRevision,omitempty"`
RevisesThought *int `json:"revisesThought,omitempty"`
BranchFromThought *int `json:"branchFromThought,omitempty"`
BranchID string `json:"branchId,omitempty"`
NeedsMoreThoughts *bool `json:"needsMoreThoughts,omitempty"`
Confidence float64 `json:"confidence"`
Assumptions []string `json:"assumptions"`
Critique string `json:"critique"`
CounterArgument string `json:"counterArgument"`
NextStepRationale string `json:"nextStepRationale,omitempty"`
}
ThoughtData is the input to one criticalthinking tool call.
Sent fields whose omission cannot be distinguished from their zero value (NextThoughtNeeded, IsRevision, RevisesThought, BranchFromThought, NeedsMoreThoughts) use pointer types so the validator can detect "not sent".
func (ThoughtData) Validate ¶
func (td ThoughtData) Validate() error
Validate enforces every wire-format rule for ThoughtData except those that require knowing the current session state (RevisesThought / BranchFromThought range checks). Those run separately in SequentialThinkingServer.ProcessThought.
Returns the first error encountered; callers that want all errors should extend this with a multi-error type later.
type ThoughtResponse ¶
type ThoughtResponse struct {
ThoughtNumber int `json:"thoughtNumber"`
TotalThoughts int `json:"totalThoughts"`
NextThoughtNeeded bool `json:"nextThoughtNeeded"`
Branches []string `json:"branches"`
ThoughtHistoryLength int `json:"thoughtHistoryLength"`
SessionConfidence float64 `json:"sessionConfidence"`
BranchConfidences map[string]float64 `json:"branchConfidences,omitempty"`
}
ThoughtResponse is the structuredContent of a criticalthinking tool call.
type ToolResult ¶
type ToolResult struct {
Text string // the thinking-out-loud transcript (or error JSON when IsError)
StructuredJSON string // JSON-encoded ThoughtResponse, "" when IsError
IsError bool
}
ToolResult is the package-internal return type from ProcessThought. main.go adapts it into a *mcp.CallToolResult — keeping mcp imports out of this package preserves its testability.