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
- func Caller(ctx context.Context) guard.Principal
- func HasScope(p guard.Principal, scope catalog.Scope) bool
- func InsufficientScope(tool string, scope catalog.Scope) *jsonrpc.Error
- func LocalPrincipal() guard.Principal
- func Mutating(title string, idempotent bool) *mcp.ToolAnnotations
- func ReadOnly(title string) *mcp.ToolAnnotations
- func RefusedScope(err error) (catalog.Scope, bool)
- func RequireScope(ctx context.Context, tool string, scope catalog.Scope) error
- func Under(root, path string) bool
- func WriteFile(root *os.Root, name string, content []byte, created os.FileMode) error
- type NameRole
- type Option
- type Position
- type Resolved
- type Root
Constants ¶
const CodeInsufficientScope = -32030
CodeInsufficientScope refuses a tools/call by a principal without the tool's scope: implementation-defined (JSON-RPC 2.0 § 5.1), after RFC 6750 § 3.1's insufficient_scope.
const LocalSource = "local"
LocalSource is the Source of the principal a transport authenticates nobody for; no authenticator uses it, so it collides with no credential's.
const LocalSubject = "local"
LocalSubject is the Subject of that principal.
Variables ¶
This section is empty.
Functions ¶
func Caller ¶ added in v0.13.0
Caller is the principal a tool call is made by: the one the server put in ctx (guard.WithPrincipal), or the local principal when the transport named none.
func HasScope ¶ added in v0.13.0
HasScope reports whether p holds scope (RFC 6749 § 3.3: scopes are case-sensitive strings).
func InsufficientScope ¶ added in v0.13.0
InsufficientScope is the refusal of a call of tool by a principal without scope: a protocol error naming both in its message and its data.
func LocalPrincipal ¶ added in v0.13.0
LocalPrincipal is the one caller of a transport that authenticates nobody: the host over stdio, or a loopback -http client with no token. It holds every scope.
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 RefusedScope ¶ added in v0.13.0
RefusedScope answers the scope a refusal names, and whether err is one.
func RequireScope ¶ added in v0.13.0
RequireScope is nil when the caller of ctx holds scope, else the refusal of tool.
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.
type Option ¶
type Option func(*options)
Option adjusts one resolution.
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 ¶
FromProtocol converts a protocol position on lineText to a 1-based Position.
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 ¶
NewRoot makes the root of dir, which must exist: a relative dir is taken from the working directory.
func (Root) Resolve ¶
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.