xonecas.io
62159
Sy

symb / files

symb / internal / mcptools / todo.go

2.2 KB
1package mcptools
2
3import (
4	"context"
5	"encoding/json"
6	"sync"
7
8	"github.com/xonecas/symb/internal/mcp"
9)
10
11// Scratchpad holds the agent's current plan/notes. It is safe for concurrent
12// access. The content is injected into the LLM context at the tail of the
13// history so the agent's goals stay in the model's recent attention window.
14type Scratchpad struct {
15	mu      sync.RWMutex
16	content string
17}
18
19// Content returns the current scratchpad text.
20func (s *Scratchpad) Content() string {
21	s.mu.RLock()
22	defer s.mu.RUnlock()
23	return s.content
24}
25
26// TodoWriteArgs represents arguments for the TodoWrite tool.
27type TodoWriteArgs struct {
28	Content string `json:"content"`
29}
30
31// NewTodoWriteTool creates the TodoWrite tool definition.
32func NewTodoWriteTool() mcp.Tool {
33	return mcp.Tool{
34		Name:        "TodoWrite",
35		Description: `Write or update your working plan/scratchpad. The content replaces any previous plan and is kept visible at the end of your context window. Use this to track goals, progress, and next steps for tasks with 3+ steps. Rewrite it as you complete steps to stay focused. Skip for simple single-step tasks.`,
36		InputSchema: json.RawMessage(`{
37			"type": "object",
38			"properties": {
39				"content": {"type": "string", "description": "Your current plan, todo list, or working notes. This replaces the previous content entirely."}
40			},
41			"required": ["content"]
42		}`),
43	}
44}
45
46// MakeTodoWriteHandler creates a handler that stores content in the scratchpad.
47func MakeTodoWriteHandler(pad *Scratchpad) mcp.ToolHandler {
48	return func(_ context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
49		var args TodoWriteArgs
50		if err := json.Unmarshal(arguments, &args); err != nil {
51			return &mcp.ToolResult{
52				Content: []mcp.ContentBlock{{Type: "text", Text: "Invalid arguments: " + err.Error()}},
53				IsError: true,
54			}, nil
55		}
56		if args.Content == "" {
57			return &mcp.ToolResult{
58				Content: []mcp.ContentBlock{{Type: "text", Text: "Content cannot be empty"}},
59				IsError: true,
60			}, nil
61		}
62
63		pad.mu.Lock()
64		pad.content = args.Content
65		pad.mu.Unlock()
66
67		return &mcp.ToolResult{
68			Content: []mcp.ContentBlock{{Type: "text", Text: "Plan updated."}},
69		}, nil
70	}
71}