toolkit

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package toolkit holds what every sysml-mcp tool group shares: the annotations a tool declares about itself and the coordinate conventions tool arguments use, so the groups agree without importing one another.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mutating

func Mutating(title string, idempotent bool) *mcp.ToolAnnotations

Mutating annotates a tool that changes server state or files on disk; idempotent says whether repeating a call with the same arguments changes nothing further.

func ReadOnly

func ReadOnly(title string) *mcp.ToolAnnotations

ReadOnly annotates a tool that inspects the model or the workspace and changes nothing; title is what a client shows for it.

func Under

func Under(root, path string) bool

Under reports whether path lies under root (or is root), both absolute and clean. It judges the spelling only: follow symlinks first where they matter.

func WriteFile

func WriteFile(root *os.Root, name string, content []byte, created os.FileMode) error

WriteFile replaces name, relative to root, with content atomically: a temporary file beside it is renamed over it. An existing file keeps its mode, a new one gets created.

Types

type NameRole

type NameRole int

NameRole is what a tool reads from a path's name, which a symlink must then agree with its target about: a link spelled `.kerml` to a `.sysml` file would otherwise be read as the wrong language.

const (
	// NameIgnored reads nothing from the name.
	NameIgnored NameRole = iota
	// NameLanguage reads the notation language (SysML or KerML) from the name.
	NameLanguage
	// NameFormat reads the model format and, for notation, the language.
	NameFormat
)

type Option

type Option func(*options)

Option adjusts one resolution.

func Exempt

func Exempt(dirs ...string) Option

Exempt lets a path pass when, symlinks followed, it lies under one of dirs (likewise followed), wherever they are: the library roots an installed project is read from, which live outside a workspace.

func NameMeans

func NameMeans(role NameRole) Option

NameMeans refuses a symlink whose name means another format or language than its target's for the role.

type Position

type Position struct {
	Line   int `json:"line" jsonschema:"1-based line number"`
	Column int `json:"column" jsonschema:"1-based column number, counted in characters"`
}

Position is a place in a document as an editor shows it: 1-based line and column, the column counted in characters. Tool arguments use it rather than the protocol's 0-based UTF-16 positions, which agents get wrong.

func FromProtocol

func FromProtocol(pos protocol.Position, lineText string) Position

FromProtocol converts a protocol position on lineText to a 1-based Position.

func (Position) ToProtocol

func (p Position) ToProtocol(lineText string) protocol.Position

ToProtocol converts p to the protocol's 0-based position; lineText is the text of the line, needed because the protocol counts columns in UTF-16 units.

type Resolved

type Resolved struct {
	// Path is the path as spelled, absolute and clean: a relative path joined
	// to the root. It names the document to a tool and an index.
	Path string
	// Real is Path with its symlinks followed, the file an operation reaches;
	// for a path not yet on disk, the resolved nearest existing ancestor with
	// the rest of the path appended.
	Real string
}

Resolved is a path Root.Resolve accepted.

type Root

type Root struct {
	// Dir is the root as the server was given it, made absolute and clean.
	Dir string
	// Real is Dir with its symlinks resolved.
	Real string
}

Root is the workspace folder every file a tool touches must lie under. A path is judged twice: as spelled, against Dir, and with its symlinks followed, against Real, so neither `..` nor a link planted under the root reaches a file outside it.

func NewRoot

func NewRoot(dir string) (Root, error)

NewRoot makes the root of dir, which must exist: a relative dir is taken from the working directory.

func (Root) Resolve

func (r Root) Resolve(path string, opts ...Option) (Resolved, error)

Resolve turns a tool's path argument into the file it names, which must lie under the root: as spelled, so `..` and an absolute path elsewhere are refused, and once the symlinks on the way are followed, so a link out of the root is refused too, a dangling one by where it points. A path that does not exist yet is checked through its nearest existing ancestor. A relative path is taken from the root.

func (Root) Target

func (r Root) Target(path string) (string, error)

Target is the file a write to path reaches, relative to Real: path with its symlinks resolved, re-checked now since a link may have been repointed since.

func (Root) WriteFile

func (r Root) WriteFile(path string, content []byte) (replaced bool, err error)

WriteFile replaces the regular file path names with content through an os.Root at Real, so a link repointed out of the root cannot carry the write outside it.

Jump to

Keyboard shortcuts

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