tools

package
v0.0.0-...-f2e3cbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tools builds MCP tool registrations from a snapshot of the Taskfile state held by the orchestrator. It is responsible for translating Taskfile tasks into MCP-shaped tools, naming them in a way that satisfies the MCP spec, and producing a plan/diff that the orchestrator can apply to the live MCP registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(old, desired map[string]RegisteredTool) (stale, added []string)

Diff compares the old registered tool set against the desired set and returns the names of tools to remove and tools to add (or re-add due to changes).

func Equal

func Equal(a, b *RegisteredTool) bool

Equal reports whether two registered tools are equivalent by comparing Name, Description, and the cached InputSchema bytes captured when the tool was created.

func RootPrefix

func RootPrefix(workdir string, totalRoots int) string

RootPrefix returns the tool name prefix for a root identified by its working directory. When there is only one root the prefix is empty; with multiple roots it is derived from the root directory's basename.

func SanitizeRootPrefix

func SanitizeRootPrefix(name string) string

SanitizeRootPrefix converts a root name or directory basename into a valid MCP tool name prefix component.

func SanitizeToolName

func SanitizeToolName(taskName string) string

SanitizeToolName converts a candidate tool name into an MCP-valid name. It preserves Task namespace semantics by replacing colons with underscores, strips wildcard (*) segments, replaces any remaining unsupported characters with underscores, and caps the final name at the MCP-recommended length.

Types

type Plan

type Plan struct {
	Tools    map[string]RegisteredTool
	Handlers map[string]mcp.ToolHandler
}

Plan is the desired tool registration state computed from a snapshot. Tools and Handlers are keyed by tool name and always have matching keys.

func BuildPlan

func BuildPlan(snap StateSnapshot, logger *slog.Logger) Plan

BuildPlan computes the desired tool registration state from a snapshot without accessing or mutating the orchestrator. logger receives diagnostics for plan-level decisions such as colliding tool names; passing a nil logger panics.

type RegisteredTool

type RegisteredTool struct {
	mcp.Tool
	// contains filtered or unexported fields
}

RegisteredTool wraps an mcp.Tool with its serialized InputSchema bytes so equality checks can compare schemas as raw bytes without re-marshalling on every diff. The mcp.Tool is embedded so callers can continue to access Name, Description, and InputSchema directly.

func CreateToolForTask

func CreateToolForTask(tf *ast.Taskfile, prefix, taskName string, taskDef *ast.Task) *RegisteredTool

CreateToolForTask creates an MCP tool definition for a given task. The tool name is sanitized for MCP compatibility; the description references the original Taskfile task name for clarity. The prefix parameter is used in multi-root mode to namespace tool names. The taskfile is taken by value rather than via *Root so the planner can run on a snapshot without touching live, mutable server state.

type RootSnapshot

type RootSnapshot struct {
	Workdir  string
	Taskfile *ast.Taskfile
}

RootSnapshot is an immutable per-root view captured under lock so the planner can run without holding the orchestrator mutex and without dereferencing a live root that another goroutine may mutate. The taskfile pointer is captured by value: even if the live root's taskfile is later swapped out, this snapshot keeps observing the AST that was current at snapshot time.

type StateSnapshot

type StateSnapshot struct {
	Generation uint64
	Roots      map[string]RootSnapshot
}

StateSnapshot captures the inputs needed by BuildPlan, frozen at a specific generation supplied by the orchestrator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL