Help us shape the future of Go! Take the 2026 Go Developer Survey

toolsearch

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package toolsearch indexes allowed MCP tools and implements search tool responses.

Index

Constants

View Source
const (
	// SearchToolName is the public MCP tool used to find available tools.
	SearchToolName = "search_tools"
	// CallToolName is the public MCP tool used to invoke a search result.
	CallToolName = "call_tool"
)

Variables

View Source
var (
	// ErrNotReady indicates that the index did not become ready before the wait ended.
	ErrNotReady = errors.New("tool search index is not ready")
)

Functions

func Definitions

func Definitions() []*mcp.Tool

Definitions returns the search and generic call MCP tool definitions.

func Revision

func Revision(ref Reference, componentName, originalToolName string, tool *mcp.Tool) string

Revision identifies an exposed tool definition and its source tool. Its inputs must be safe to expose to clients: component connection settings may contain credentials and must not contribute to a client-visible digest.

Types

type CallArguments

type CallArguments struct {
	Name      string          `json:"name"`
	Revision  string          `json:"revision"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

CallArguments is the input accepted by the generic MCP call tool.

func ParseCallArguments

func ParseCallArguments(arguments any) (CallArguments, error)

ParseCallArguments validates a generic tool call and defaults omitted arguments to an empty object.

type Document

type Document struct {
	ExposedName string
	Component   string
	Reference   Reference
	Revision    string
	Tool        *mcp.Tool
}

Document contains the effective tool definition and identity to index.

type Hit

type Hit struct {
	Reference Reference `json:"tool"`
	Revision  string    `json:"revision"`
	Component string    `json:"component"`
	Tool      *mcp.Tool `json:"definition"`
}

Hit is a matching tool with the information needed to invoke it.

type Index

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

Index owns one immutable snapshot's index and its background builder.

func New

func New(documents []Document) *Index

New creates an unbuilt index for one allowed-tool snapshot.

func (*Index) Call

func (i *Index) Call(ctx context.Context, arguments any) (*mcp.CallToolResult, error)

Call handles the search MCP tool's arguments and result formatting.

func (*Index) Revision

func (i *Index) Revision(ref Reference) (string, bool)

Revision returns the revision indexed for a tool reference in this snapshot.

func (*Index) Search

func (i *Index) Search(ctx context.Context, text string, limit, offset int) (Results, error)

Search waits for a ready index and returns ranked matches after offset.

func (*Index) Start

func (i *Index) Start(ctx context.Context)

Start builds in the background and retries failed attempts until stopped.

func (*Index) Stop

func (i *Index) Stop()

Stop cancels pending work. A published index remains usable by in-flight requests.

type Reference

type Reference struct {
	Name string `json:"name"`
}

Reference identifies a tool by its unique exposed name.

type Results

type Results struct {
	Tools   []Hit `json:"tools"`
	HasMore bool  `json:"hasMore"`
}

Results contains ranked search hits and indicates whether more matches exist.

Jump to

Keyboard shortcuts

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