toolkit

package
v1.131.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package toolkit provides shared types for toolkit implementations and the platform layer. This package has zero internal dependencies to avoid import cycles between pkg/registry (which imports toolkit implementations) and the toolkit implementations themselves.

Index

Constants

View Source
const CaptureRoute = "When a result meets the purpose you stated and the statement is worth " +
	"running again, record it: memory_capture with sources=[\"<the call_id this result returned>\"] " +
	"and a description of what the query answers and any caveats. That is what makes it findable " +
	"by the next person, and what puts it up for promotion to the catalog."

CaptureRoute tells an agent what to do with a query that worked.

Most queries worth reusing never reach an asset: the agent refines a statement, the last one answers the question, the answer goes into chat, and the statement is gone. Every result carries its own call_id, and naming that id in a capture is the one way the platform learns the query answered something (#1321). It deliberately costs a description rather than a checkbox: an agent grading its own query for free would grade every query. It lives here, in the package every toolkit already depends on, because the sentence belongs on every tool whose result is worth reusing: the query tools take it through the platform's description overrides, and the API gateway — which authors its own descriptions and does not import the middleware — appends it directly.

View Source
const ResourceDestinationSchema = `` /* 2134-byte string literal not displayed */

ResourceDestinationSchema is the JSON Schema of the destination as an export tool publishes it, shared so the four export tools describe one capability in one set of words. It is a property value, to be spliced in under the name "resource".

Closed to unknown keys, like the input schemas it sits inside: a misspelled "file_name" is refused by name rather than landing the file at an address nobody asked for.

Variables

This section is empty.

Functions

func AnnotationsToMCP added in v1.101.0

func AnnotationsToMCP(cfg AnnotationConfig) *mcp.ToolAnnotations

AnnotationsToMCP converts an AnnotationConfig into MCP tool annotations, applying only the hints the operator explicitly set.

func ErrorResult added in v1.101.0

func ErrorResult(msg string) *mcp.CallToolResult

ErrorResult builds an MCP tool result carrying an in-band error.

Tool handlers surface failures through CallToolResult.IsError rather than a transport-level JSON-RPC error: a handler that returns a Go error aborts the call, whereas an in-band error lets the model read and react to the message. The message is marshaled as a JSON struct, never formatted into a JSON literal, so it is escaped correctly for any input.

func JSONResult added in v1.101.0

func JSONResult(v any) *mcp.CallToolResult

JSONResult marshals v to indented JSON and returns it as an MCP tool result. A marshal failure is surfaced as an in-band ErrorResult rather than a Go error, matching how tool handlers report failures.

func JSONResultTyped added in v1.101.0

func JSONResultTyped(v any) (*mcp.CallToolResult, any, error)

JSONResultTyped adapts JSONResult to the typed tool-handler return signature (ctx, req, in) (*mcp.CallToolResult, Out, error). The middle structured-output value is unused; handlers that emit structured content build the result directly.

func MarshalResultJSON added in v1.130.0

func MarshalResultJSON(v any) ([]byte, error)

MarshalResultJSON renders v exactly as JSONResult puts it in a tool result's text block. A handler that must size a result before returning it — one holding itself to a budget on what the client receives rather than on what it read (issue #1606) — measures through this, so the budget cannot drift from the encoder the result is actually built with.

Types

type AnnotationConfig added in v1.101.0

type AnnotationConfig struct {
	ReadOnlyHint    *bool `yaml:"read_only_hint"`
	DestructiveHint *bool `yaml:"destructive_hint"`
	IdempotentHint  *bool `yaml:"idempotent_hint"`
	OpenWorldHint   *bool `yaml:"open_world_hint"`
}

AnnotationConfig is the YAML-configurable set of MCP tool annotation hints shared by every toolkit. Each field is a pointer so an unset hint (inherit the tool's built-in default) is distinct from an explicit false.

type ConnectionDetail

type ConnectionDetail struct {
	Name           string
	Description    string
	IsDefault      bool
	CatalogID      string
	OperationCount int
	// Health is optional per-connection reachability, populated by gateway
	// kinds that hold a live upstream session (so an evicted or dead upstream
	// is observable from list_connections instead of only when a downstream
	// tool call fails). Nil for toolkits that do not track reachability.
	Health *ConnectionHealth
}

ConnectionDetail provides information about a single connection within a toolkit.

CatalogID and OperationCount are optional and only populated by toolkits where they have meaning (today: apigateway). They exist on this shared struct so list_connections can surface what's actually bound at runtime rather than only what's stored in the DB. The two disagreed in the past when a config update reached the store but never reached the in-memory toolkit, and the missing fields here made the divergence invisible from the MCP surface.

type ConnectionHealth added in v1.82.0

type ConnectionHealth struct {
	// Reachable is true when the connection has a live session and its most
	// recent forwarded call did not end in an unrecovered transport error.
	Reachable bool
	// LastSuccessUnix is the unix-seconds time of the last successful
	// forwarded call (or the initial connect). Zero when none has succeeded.
	LastSuccessUnix int64
	// LastError is the most recent call or connect failure, empty when healthy.
	LastError string
}

ConnectionHealth is the runtime reachability of a gateway upstream.

Reachability is observed passively from forwarded traffic, not from an active background probe: a transport error or timeout on a forwarded call marks the connection unreachable, and it is cleared by the next successful call (or a re-dial). So an idle connection that saw one transient failure can read unreachable until traffic resumes, even though its session is alive. A tool-level error (e.g. bad arguments) is NOT a transport failure and does not affect reachability.

func (*ConnectionHealth) Wire added in v1.83.0

Wire renders runtime health into its JSON wire shape, formatting the last success time as RFC3339 UTC (omitted when no call has ever succeeded). Returns nil for a nil receiver so connections that do not track reachability omit the field entirely.

type ConnectionHealthWire added in v1.83.0

type ConnectionHealthWire struct {
	Reachable   bool   `json:"reachable"`
	LastSuccess string `json:"last_success,omitempty"`
	LastError   string `json:"last_error,omitempty"`
}

ConnectionHealthWire is the JSON wire shape for ConnectionHealth, shared by every operator surface (the list_connections MCP tool and the admin connections API) so they report identical reachability for the same connection by construction rather than by two copies happening to agree.

type ConnectionLister

type ConnectionLister interface {
	ListConnections() []ConnectionDetail
}

ConnectionLister is an optional interface for toolkits that manage multiple connections internally. Toolkits implementing this interface expose all their connections for discovery via the list_connections tool.

type ConnectionManager added in v1.48.0

type ConnectionManager interface {
	AddConnection(name string, config map[string]any) error
	RemoveConnection(name string) error
	HasConnection(name string) bool
}

ConnectionManager is an optional interface for toolkits that support adding and removing backend connections at runtime without restart. Used by the admin API to make DB-managed connections live immediately.

type ResourceAddress added in v1.131.0

type ResourceAddress struct {
	// Scope and ScopeID name the library. An empty scope means the caller's
	// own, which is the one library every authenticated caller may write.
	Scope   string
	ScopeID string
	// Path is the folder chain inside the library, for example
	// "datasets/media-manager".
	Path string
	// Filename is the file's name within that folder, and the last segment of
	// the canonical URI.
	Filename string
}

ResourceAddress is where a managed resource is filed: the library, the folder chain inside it, and the file's name in that folder (#1665).

It is the whole of a resource's address and the thing its canonical mcp:// URI is built from, which is what makes it an identity a caller can hold without holding an id. A scheduled script's memory of its own output is exactly the thing that gets cleared and rewritten, so the address is what survives across runs where a remembered id does not.

It lives here beside ResourceDestination because the two are the same address arriving for different reasons -- one to write into, one to look up -- and a second definition of "where a file is" is how the two would drift.

type ResourceDestination added in v1.131.0

type ResourceDestination struct {
	// Scope and ScopeID name the library the file is filed in. An empty scope
	// means the caller's own library, which is the one place every
	// authenticated caller may write.
	Scope   string `json:"scope,omitempty"`
	ScopeID string `json:"scope_id,omitempty"`
	// Path is the folder chain inside the library, for example
	// "datasets/media-manager". It is required: a managed resource is filed in
	// a folder, and the folder is half of the address this destination is.
	Path string `json:"path,omitempty"`
	// Filename is the file's name within that folder, and the last segment of
	// the canonical mcp:// URI. Together with the library and the path it is
	// the destination's whole address.
	Filename string `json:"filename,omitempty"`
	// ChangeSummary is what the version history shows beside the revision a
	// replacement records. Empty takes the platform's default.
	ChangeSummary string `json:"change_summary,omitempty"`

	// DisplayName, Description and Tags label the file, and are deliberately
	// NOT wire fields: every export tool already takes a name, a description
	// and tags for the asset it would otherwise write, and those are what label
	// the resource. One set of labels per call, rather than two that can
	// disagree about what the same bytes are called.
	//
	// They are recorded on a create and left alone by a replacement: a file
	// people have since renamed or re-tagged in the portal is not re-labeled
	// by the next scheduled refresh of its contents.
	DisplayName string   `json:"-"`
	Description string   `json:"-"`
	Tags        []string `json:"-"`
}

ResourceDestination is the managed resource an export lands in, addressed by the path it lives at rather than by the id it was given (#1663).

The path is the address because identity is what an export destination has to survive: the same call on Monday and on Tuesday means one file with two versions, not two files. A caller that had to name an id would have to remember one, and a scheduled script's memory of its own output is exactly the thing that is cleared and rewritten.

Every export tool that can write a portal asset can write one of these instead, which is why the type lives here: one destination vocabulary, one result shape, one implementation behind them, rather than a copy per toolkit.

type ResourceLander added in v1.131.0

type ResourceLander interface {
	// Check validates the destination and the caller's authority to write
	// there, writing nothing. A nil error means Land will not refuse the
	// address.
	CheckResourceDestination(ctx context.Context, dest ResourceDestination) error
	// LandResource streams content into the destination, creating the resource
	// or recording a new version of the one already at that address. The
	// contentType is what the producer says the bytes are; the destination's
	// filename refines it where the producer could only say "text".
	LandResource(
		ctx context.Context, dest ResourceDestination, content io.Reader, contentType string,
	) (*ResourceLanding, error)
}

ResourceLander writes an export's bytes into a managed resource at a path, creating the file the first time and recording a new version of it every time after.

It is two calls rather than one because an export's bytes are produced by asking an upstream for them, and a destination the platform would refuse must be refused BEFORE that request is made: a POST that cannot land anywhere has still been sent. Check is that refusal, and it is the same validation Land applies, so a destination Check accepts is one Land can write.

Implemented once, by the platform's managed-resource writer. A toolkit holds the interface and never the implementation, so the identity a write is made under is derived from the request rather than supplied by the tool.

type ResourceLanding added in v1.131.0

type ResourceLanding struct {
	ResourceID string `json:"resource_id"`
	// Reference is the mcp:resource:<id> form every tool that takes a
	// reference accepts.
	Reference string `json:"reference"`
	// URI is the canonical mcp:// address, which is what save_asset's
	// 'references' argument takes.
	URI         string `json:"uri"`
	Filename    string `json:"filename"`
	Scope       string `json:"scope"`
	ScopeID     string `json:"scope_id,omitempty"`
	Path        string `json:"path"`
	ContentType string `json:"content_type"`
	SizeBytes   int64  `json:"size_bytes"`
	// Version is the version number the content was recorded as: 1 for a
	// create, and the next number for every replacement after it.
	Version int `json:"version"`
	// Created distinguishes the two halves of create-or-replace, because they
	// mean different things to the caller: a create is a new address to wire
	// something up to, a replacement is an address that already has readers.
	Created bool `json:"created"`
	// TableChanges is one sentence per table registered over the file, saying
	// it followed onto the new version or is pinned and now behind it (#1536).
	// Absent when no table is registered over the file. It reports what this
	// write did, so it is named apart from the `tables` a fetched reference
	// carries, which are the rows a caller queries (#1666).
	TableChanges []string `json:"table_changes,omitempty"`
	Message      string   `json:"message"`
}

ResourceLanding is what a landed export reports: the two names the caller hands to the next call, what the write did to the file's identity, and what it did to the tables registered over it.

It leads with the reference and the URI for the reason manage_resource's own result does: a write whose result cannot be passed to the next call is a write the caller has to go looking for.

type ResourceQuery added in v1.131.0

type ResourceQuery struct {
	// Scope and ScopeID name the library. An empty scope is every library the
	// caller can see, which is deliberately wider than a write's default: a
	// listing answers "what is filed here", and someone browsing has no reason
	// to be shown only their own library when they can see three.
	Scope   string
	ScopeID string
	// Path is the folder the listing is rooted at, and it is a prefix: the
	// answer holds what is beneath it at every depth, which is what makes a
	// folder count mean anything. Empty is the whole library.
	Path string
	// Limit and Offset page the answer. A non-positive limit takes the
	// implementation's default.
	Limit  int
	Offset int
}

ResourceQuery narrows a listing of managed resources to one library and one folder.

Jump to

Keyboard shortcuts

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