tools

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownToolType = fmt.Errorf("unknown tool type")

Functions

func GetCompatibleSource

func GetCompatibleSource[T any](resourceMgr SourceProvider, sourceName, toolName, toolType string) (T, error)

func IsAuthorized

func IsAuthorized(authRequiredSources []string, verifiedAuthServices []string) bool

Helper function that returns if a tool invocation request is authorized

func IsValidName

func IsValidName(s string) bool

func Register

func Register(resourceType string, factory ToolConfigFactory) bool

Register allows individual tool packages to register their configuration factory function. This is typically called from an init() function in the tool's package. It associates a 'type' string with a function that can produce the specific ToolConfig type. It returns true if the registration was successful, and false if a tool with the same type was already registered.

Types

type AccessToken

type AccessToken string

func (AccessToken) ParseBearerToken

func (token AccessToken) ParseBearerToken() (string, error)

type BaseTool added in v1.4.0

type BaseTool[T ToolMeta] struct {
	Cfg T

	StaticParameters parameters.Parameters
	// contains filtered or unexported fields
}

BaseTool provides default implementations of various methods on the Tool interface. Tools embed BaseTool to drop their boilerplate and override only methods that need custom behavior.

func NewBaseTool added in v1.4.0

func NewBaseTool[T ToolMeta](cfg T, annotations *ToolAnnotations, metadata Manifest, staticParameters parameters.Parameters) BaseTool[T]

NewBaseTool constructs a BaseTool from a resolved Config (typically the per-tool Config after Initialize has filled in defaults), the resolved annotations, the precomputed Manifest, and the tool's static parameters.

func (BaseTool[T]) Authorized added in v1.4.0

func (b BaseTool[T]) Authorized(verifiedAuthServices []string) bool

func (BaseTool[T]) EmbedParams added in v1.4.0

func (b BaseTool[T]) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error)

func (BaseTool[T]) GetAnnotations added in v1.4.0

func (b BaseTool[T]) GetAnnotations() *ToolAnnotations

func (BaseTool[T]) GetAuthRequired added in v1.4.0

func (b BaseTool[T]) GetAuthRequired() []string

func (BaseTool[T]) GetAuthTokenHeaderName added in v1.4.0

func (b BaseTool[T]) GetAuthTokenHeaderName(_ SourceProvider) (string, error)

func (BaseTool[T]) GetDescription added in v1.4.0

func (b BaseTool[T]) GetDescription() string

func (BaseTool[T]) GetName added in v1.4.0

func (b BaseTool[T]) GetName() string

func (BaseTool[T]) GetParameters added in v1.4.0

func (b BaseTool[T]) GetParameters() parameters.Parameters

func (BaseTool[T]) GetScopesRequired added in v1.4.0

func (b BaseTool[T]) GetScopesRequired() []string

func (BaseTool[T]) Manifest added in v1.4.0

func (b BaseTool[T]) Manifest() Manifest

func (BaseTool[T]) RequiresClientAuthorization added in v1.4.0

func (b BaseTool[T]) RequiresClientAuthorization(_ SourceProvider) (bool, error)

type ConfigBase added in v1.4.0

type ConfigBase struct {
	Name           string   `yaml:"name"           validate:"required"`
	Description    string   `yaml:"description"`
	AuthRequired   []string `yaml:"authRequired"`
	ScopesRequired []string `yaml:"scopesRequired"`
}

ConfigBase owns the YAML fields that every tool's Config shares and that BaseTool reads through. Description is eagerly defaulted by the tool's Initialize (many prebuilt configs omit description: and rely on a canned per-tool string), so post-Initialize ConfigBase.Description holds the resolved value.

func (ConfigBase) GetAuthRequired added in v1.4.0

func (c ConfigBase) GetAuthRequired() []string

func (ConfigBase) GetDescription added in v1.4.0

func (c ConfigBase) GetDescription() string

func (ConfigBase) GetName added in v1.4.0

func (c ConfigBase) GetName() string

func (ConfigBase) GetScopesRequired added in v1.4.0

func (c ConfigBase) GetScopesRequired() []string

type HTTPMethod

type HTTPMethod string

HTTPMethod is a string of a valid HTTP method (e.g "GET")

func (*HTTPMethod) UnmarshalYAML

func (i *HTTPMethod) UnmarshalYAML(ctx context.Context, unmarshal func(interface{}) error) error

type Manifest

type Manifest struct {
	Description  string                         `json:"description"`
	Parameters   []parameters.ParameterManifest `json:"parameters"`
	AuthRequired []string                       `json:"authRequired"`
}

Manifest is the representation of tools sent to Client SDKs.

type SourceProvider

type SourceProvider interface {
	GetSource(sourceName string) (sources.Source, bool)
}

SourceProvider defines the minimal view of the server.ResourceManager that the Tool package needs. This is implemented to prevent import cycles.

type Tool

type Tool interface {
	GetName() string
	GetDescription() string
	GetAuthRequired() []string
	GetAnnotations() *ToolAnnotations
	Invoke(context.Context, SourceProvider, parameters.ParamValues, AccessToken) (any, util.ToolboxError)
	EmbedParams(context.Context, parameters.ParamValues, map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error)
	Manifest() Manifest
	Authorized([]string) bool
	RequiresClientAuthorization(SourceProvider) (bool, error)
	ToConfig() ToolConfig
	GetAuthTokenHeaderName(SourceProvider) (string, error)
	GetParameters() parameters.Parameters
	GetScopesRequired() []string
}

type ToolAnnotations

type ToolAnnotations struct {
	DestructiveHint *bool `json:"destructiveHint,omitempty" yaml:"destructiveHint,omitempty"`
	IdempotentHint  *bool `json:"idempotentHint,omitempty" yaml:"idempotentHint,omitempty"`
	OpenWorldHint   *bool `json:"openWorldHint,omitempty" yaml:"openWorldHint,omitempty"`
	ReadOnlyHint    *bool `json:"readOnlyHint,omitempty" yaml:"readOnlyHint,omitempty"`
}

https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations

func GetAnnotationsOrDefault

func GetAnnotationsOrDefault(annotations *ToolAnnotations, defaultFn func() *ToolAnnotations) *ToolAnnotations

GetAnnotationsOrDefault returns the provided annotations if non-nil, otherwise returns the result of calling defaultFn.

func NewDestructiveAnnotations

func NewDestructiveAnnotations() *ToolAnnotations

NewDestructiveAnnotations creates default annotations for a destructive tool. Use this for tools that create, update, or delete data.

func NewReadOnlyAnnotations

func NewReadOnlyAnnotations() *ToolAnnotations

NewReadOnlyAnnotations creates default annotations for a read-only tool. Use this for tools that only query/fetch data without side effects.

func NewWriteAnnotations added in v1.4.0

func NewWriteAnnotations() *ToolAnnotations

NewWriteAnnotations creates default annotations for a non-destructive write tool: ReadOnlyHint is false, DestructiveHint is left unset.

type ToolConfig

type ToolConfig interface {
	ToolConfigType() string
	Initialize(map[string]sources.Source) (Tool, error)
}

func DecodeConfig

func DecodeConfig(ctx context.Context, resourceType string, name string, decoder *yaml.Decoder) (ToolConfig, error)

DecodeConfig looks up the registered factory for the given type and uses it to decode the tool configuration.

type ToolConfigFactory

type ToolConfigFactory func(ctx context.Context, name string, decoder *yaml.Decoder) (ToolConfig, error)

ToolConfigFactory defines the signature for a function that creates and decodes a specific tool's configuration. It takes the context, the tool's name, and a YAML decoder to parse the config.

type ToolMeta added in v1.4.0

type ToolMeta interface {
	GetName() string
	GetDescription() string
	GetAuthRequired() []string
	GetScopesRequired() []string
}

ToolMeta is the read-only view BaseTool needs of any tool's Config. Tools satisfy it for free by embedding ConfigBase.

type Toolset

type Toolset struct {
	ToolsetConfig
	Tools    []*Tool         `yaml:",inline"`
	Manifest ToolsetManifest `yaml:",inline"`
	// contains filtered or unexported fields
}

func (Toolset) ContainsTool added in v1.3.0

func (t Toolset) ContainsTool(name string) bool

ContainsTool reports whether the toolset includes a tool with the given name. When built via Initialize, lookups are O(1) via toolNameSet; for Toolsets constructed directly (e.g., in tests), falls back to a linear scan of ToolNames.

func (Toolset) ToConfig

func (t Toolset) ToConfig() ToolsetConfig

type ToolsetConfig

type ToolsetConfig struct {
	Name      string   `yaml:"name"`
	ToolNames []string `yaml:",inline"`
}

func (ToolsetConfig) Initialize

func (t ToolsetConfig) Initialize(serverVersion string, toolsMap map[string]Tool) (Toolset, error)

type ToolsetManifest

type ToolsetManifest struct {
	ServerVersion string              `json:"serverVersion"`
	ToolsManifest map[string]Manifest `json:"tools"`
}

Directories

Path Synopsis
alloydb
bigquery
cassandra
clickhouse
cloudhealthcare
cloudloggingadmin
cloudsql
cloudsqladmin
cloudsqlmssql
cloudsqlmysql
cloudsqlpg
cloudstorage
cloudstoragecommon
Package cloudstoragecommon holds helpers shared across the Cloud Storage tool implementations, chiefly error classification.
Package cloudstoragecommon holds helpers shared across the Cloud Storage tool implementations, chiefly error classification.
cockroachdb
conversationalanalytics
dataform
datalineage
dataplex
dataproc
elasticsearch
firebird
firestore
looker
mindsdb
mongodb
mssql
mysql
neo4j
neo4jexecutecypher/classifier
Package classifier provides tools to classify Cypher queries as either read-only or write operations.
Package classifier provides tools to classify Cypher queries as either read-only or write operations.
neo4jschema/cache
Package cache provides a simple, thread-safe, in-memory key-value store.
Package cache provides a simple, thread-safe, in-memory key-value store.
neo4jschema/helpers
Package helpers provides utility functions for transforming and processing Neo4j schema data.
Package helpers provides utility functions for transforming and processing Neo4j schema data.
neo4jschema/types
Package types contains the shared data structures for Neo4j schema representation.
Package types contains the shared data structures for Neo4j schema representation.
oceanbase
oracle
postgres
serverlessspark
singlestore
snowflake
spanner
sqlite
tidb
trino
utility

Jump to

Keyboard shortcuts

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