tool

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tool defines the shared data types used by source-level tool declarations, the per-type Connect functions, and the source dispatcher middlewares. It exposes the Tool/Response structs (consumed uniformly by middlewares and the MCP server registration) and a functional Options type (used to thread a logger and tracer through the call chain from cmd/main.go down to each per-type Connect).

Tool embeds *mcp.Tool so every field of the upstream mcp.Tool flows through the dispatcher untouched. The dispatcher only adds the Handler. Per-type Connect functions return a Tool whose embedded *mcp.Tool has Annotations set by the implementer; the dispatcher is a no-op transform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

Option mutates an Options value during construction. The functional options pattern lets callers override individual dependencies (logger, tracer) without having to construct and pass the full Options struct.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger overrides the default slog logger used by source-level code. Passing a nil logger is treated as "use the default" so that callers can pass an optional *slog.Logger without nil-checking first.

func WithTracer

func WithTracer(tracer trace.Tracer) Option

WithTracer overrides the default OTel tracer used by source-level code. Passing a nil tracer is treated as "use the default" so that callers can pass an optional trace.Tracer without nil-checking first.

type Options

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

Options holds the cross-cutting dependencies (logger, tracer) that flow from cmd/main.go through source.Apply into each per-type Connect. Fields are unexported: populate via WithLogger/WithTracer and read via the Logger() and Tracer() getters.

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions applies the given options to a fresh Options value. It always returns a non-nil *Options; if no options are provided, the returned value still yields working defaults from its getters.

func (*Options) Logger

func (o *Options) Logger() *slog.Logger

Logger returns the configured *slog.Logger, or slog.Default() if the receiver is nil or no logger was configured. The returned value is never nil so callers can chain slog calls without a nil check.

func (*Options) Tracer

func (o *Options) Tracer() trace.Tracer

Tracer returns the configured trace.Tracer, or the default OTel tracer for this package's instrumentation scope if the receiver is nil or no tracer was configured. The returned value is never nil.

type Response

type Response struct {
	Tools []Tool
}

Response is the result of a per-type Connect. Every Connect implementation returns this concrete type so that middlewares can iterate Tools in registration order without knowing the source type.

type Tool

type Tool struct {
	*mcp.Tool

	Handler mcp.ToolHandler
}

Tool is a single MCP tool description returned by a per-type Connect. It is consumed uniformly by the source dispatcher and middlewares: the dispatcher registers it with the MCP server via mcp.Server.AddTool, and middlewares may mutate the embedded *mcp.Tool before registration (renaming, filtering, classifying, etc.).

The *mcp.Tool is embedded by value-of-pointer: the dispatcher and any middlewares observe the same *mcp.Tool instance the per-type package constructed. The Handler is the only field the tool/ package adds.

Jump to

Keyboard shortcuts

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