methods

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopePrivate = "private"
	ScopeShared  = "shared"

	ServerTypeStdio = "stdio"

	// ModeConcurrent allows multiple JSON-RPC requests to be in flight on the
	// method server at the same time. Responses are correlated by id. This is
	// the default.
	ModeConcurrent = "concurrent"
	// ModeSerial lets only one JSON-RPC request be in flight on the method
	// server at a time. Useful for method servers that are not re-entrant.
	ModeSerial = "serial"
)

Variables

View Source
var (
	ErrMethodNotFound = errors.New("method not found")
	ErrPermission     = errors.New("method not visible to caller")
	ErrMethodDraining = errors.New("method temporarily unavailable")
	ErrMethodLeased   = errors.New("method exclusively leased")
)

Functions

func MCPToolName

func MCPToolName(methodName string) string

func NormalizeAndValidate

func NormalizeAndValidate(reg *Registration, spaceName string) error

Types

type Entry

type Entry struct {
	MethodDefinition
	SpaceID   string
	SpaceName string
	OwnerID   string
	Owner     string
	Server    ServerConfig
	// contains filtered or unexported fields
}

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code" msgpack:"code"`
	Message string `json:"message" msgpack:"message"`
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc" msgpack:"jsonrpc"`
	Method  string          `json:"method" msgpack:"method"`
	Params  json.RawMessage `json:"params,omitempty" msgpack:"params,omitempty"`
	ID      any             `json:"id,omitempty" msgpack:"id,omitempty"`
	// SpaceID optionally pins the call to one space (e.g. the member held
	// via an exclusive pool lease). A knot-specific extension to JSON-RPC
	// 2.0; ignored by the wire protocol, honoured by /api/methods/call.
	SpaceID string `json:"space_id,omitempty" msgpack:"space_id,omitempty"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc" msgpack:"jsonrpc"`
	Result  any           `json:"result,omitempty" msgpack:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty" msgpack:"error,omitempty"`
	ID      any           `json:"id,omitempty" msgpack:"id,omitempty"`
}

type MethodDefinition

type MethodDefinition struct {
	Name         string         `json:"name" toml:"name" msgpack:"name"`
	LocalName    string         `json:"local_name" toml:"local_name" msgpack:"local_name"`
	Description  string         `json:"description" toml:"description" msgpack:"description"`
	Keywords     []string       `json:"keywords,omitempty" toml:"keywords" msgpack:"keywords,omitempty"`
	Scope        string         `json:"scope,omitempty" toml:"scope" msgpack:"scope,omitempty"`
	Groups       []string       `json:"groups,omitempty" toml:"groups" msgpack:"groups,omitempty"`
	MCPTool      bool           `json:"mcp_tool" toml:"mcp_tool" msgpack:"mcp_tool"`
	Events       []string       `json:"events,omitempty" toml:"events,omitempty" msgpack:"events,omitempty"`
	EventSinks   []string       `json:"event_sinks,omitempty" toml:"event_sinks,omitempty" msgpack:"event_sinks,omitempty"`
	ParamsSchema map[string]any `json:"params_schema,omitempty" toml:"params_schema" msgpack:"params_schema,omitempty"`
	ResultSchema map[string]any `json:"result_schema,omitempty" toml:"result_schema" msgpack:"result_schema,omitempty"`
}

type MethodInfo

type MethodInfo struct {
	Name          string         `json:"name" msgpack:"name"`
	LocalName     string         `json:"local_name" msgpack:"local_name"`
	Description   string         `json:"description" msgpack:"description"`
	Keywords      []string       `json:"keywords,omitempty" msgpack:"keywords,omitempty"`
	Scope         string         `json:"scope" msgpack:"scope"`
	Groups        []string       `json:"groups,omitempty" msgpack:"groups,omitempty"`
	MCPTool       bool           `json:"mcp_tool" msgpack:"mcp_tool"`
	Events        []string       `json:"events,omitempty" msgpack:"events,omitempty"`
	EventSinks    []string       `json:"event_sinks,omitempty" msgpack:"event_sinks,omitempty"`
	ParamsSchema  map[string]any `json:"params_schema,omitempty" msgpack:"params_schema,omitempty"`
	ResultSchema  map[string]any `json:"result_schema,omitempty" msgpack:"result_schema,omitempty"`
	OwnerID       string         `json:"owner_id" msgpack:"owner_id"`
	Owner         string         `json:"owner" msgpack:"owner"`
	ProviderCount int            `json:"provider_count" msgpack:"provider_count"`
}

type Registration

type Registration struct {
	Server  ServerConfig       `json:"server" toml:"server" msgpack:"server"`
	Methods []MethodDefinition `json:"methods" toml:"methods" msgpack:"methods"`
}

func LoadRawTOML

func LoadRawTOML(data []byte) (*Registration, error)

LoadRawTOML decodes TOML bytes into a Registration without running normalization or validation. Callers (typically the agent) forward the decoded struct to the knot server, which validates it during registration.

func LoadRawTOMLFile

func LoadRawTOMLFile(path string) (*Registration, error)

func LoadTOML

func LoadTOML(data []byte, spaceName string) (*Registration, error)

func LoadTOMLFile

func LoadTOMLFile(path string, spaceName string) (*Registration, error)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func DefaultRegistry

func DefaultRegistry() *Registry

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the total number of registered method entries across all spaces and names. Each duplicate exact-match registration counts once. Useful for debug/diagnostic logging; not part of the discovery surface.

func (*Registry) Done

func (r *Registry) Done(entry *Entry)

func (*Registry) Drain

func (r *Registry) Drain(spaceID string)

func (*Registry) InFlightForSpace

func (r *Registry) InFlightForSpace(spaceID string) int

func (*Registry) List

func (r *Registry) List(user *model.User) []MethodInfo

func (*Registry) Pick

func (r *Registry) Pick(methodName string, user *model.User) (*Entry, string, error)

func (*Registry) PickForSpace added in v0.36.0

func (r *Registry) PickForSpace(methodName, spaceID string, user *model.User) (*Entry, string, error)

PickForSpace selects the entry for methodName registered by the given space, visibility-checked for the caller. It bypasses lease and drain exclusion: the caller explicitly targets this space, which is how the holder of an exclusive pool lease reaches its member. At most one entry can match, so no load balancing is involved.

func (*Registry) Register

func (r *Registry) Register(space *model.Space, owner *model.User, reg *Registration) error

func (*Registry) SetDrainChecker

func (r *Registry) SetDrainChecker(fn func(spaceID string) bool)

SetDrainChecker installs a callback that Register consults to determine whether a space should be draining even if no prior entries exist (e.g. after an unregister/register churn cycle). The PoolService sets this so drain state survives method server restarts.

func (*Registry) SetLeaseChecker added in v0.36.0

func (r *Registry) SetLeaseChecker(fn func(spaceID string) bool)

SetLeaseChecker installs a callback that Pick and List consult to determine whether a space is exclusively leased (a pool member checked out via a lease). Leased entries are excluded from shared routing for everyone; the lease holder reaches its space through PickForSpace, which deliberately bypasses the check. The PoolService sets this.

func (*Registry) Undrain

func (r *Registry) Undrain(spaceID string)

func (*Registry) UnregisterSpace

func (r *Registry) UnregisterSpace(spaceID string)

type ServerConfig

type ServerConfig struct {
	Type    string   `json:"type" toml:"type" msgpack:"type"`
	Command string   `json:"command" toml:"command" msgpack:"command"`
	Args    []string `json:"args,omitempty" toml:"args" msgpack:"args,omitempty"`
	Timeout int      `json:"timeout,omitempty" toml:"timeout" msgpack:"timeout,omitempty"`
	Mode    string   `json:"mode,omitempty" toml:"mode" msgpack:"mode,omitempty"`
}

Jump to

Keyboard shortcuts

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