servertool

package
v0.260806.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMCPToolName

func IsMCPToolName(name string) bool

IsMCPToolName reports whether name looks like a normalized MCP tool name (i.e. it parses successfully via ParseNormalizedToolName).

func RemapLegacyAdvisorToolName

func RemapLegacyAdvisorToolName(toolName string) string

RemapLegacyAdvisorToolName normalises the legacy "advisor" source ID to "builtin". All other tool names pass through unchanged.

func ScenarioFromContext

func ScenarioFromContext(ctx context.Context) (typ.RuleScenario, bool)

ScenarioFromContext reads the scenario stored under client.ScenarioContextKey. Useful for HookDeps.GetScenarioSink implementations.

Types

type AdvisorHook

type AdvisorHook struct{}

AdvisorHook injects AdvisorContext before an advisor tool call. Exported for test compatibility in packages that alias this type.

func (AdvisorHook) Match

func (h AdvisorHook) Match(toolName string) bool

func (AdvisorHook) PrepareContext

func (h AdvisorHook) PrepareContext(deps HookDeps, ctx context.Context, messages []map[string]any) context.Context

type DefaultExecutor

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

DefaultExecutor is the standard implementation of Executor.

func NewDefaultExecutor

func NewDefaultExecutor(rt RuntimeCaller, deps HookDeps) *DefaultExecutor

NewDefaultExecutor creates a DefaultExecutor with no hooks. Use Pipeline.NewExecutor to get an executor with registered tool hooks.

func (*DefaultExecutor) Execute

Execute runs the full tool-call pipeline and returns the updated context, result, and error.

type Executor

type Executor interface {
	Execute(ctx context.Context, call ToolCall) (context.Context, coretool.ToolResult, error)
}

Executor executes a single MCP tool call through the full pipeline: name validation, legacy remapping, callable guard, hooks, and dispatch.

type Hook

type Hook interface {
	Match(toolName string) bool
	PrepareContext(deps HookDeps, ctx context.Context, messages []map[string]any) context.Context
}

Hook prepares runtime context for a specific MCP servertool call. Hooks run after the worker response arrives and before local tool execution.

type HookDeps

type HookDeps interface {
	// GetAdvisorMaxUses returns the configured maximum advisor calls per request.
	GetAdvisorMaxUses() int
	// GetScenarioSink returns an enabled recording sink for the given scenario, or nil.
	GetScenarioSink(ctx context.Context) *obs.Sink
}

HookDeps provides the server-level dependencies that hooks may need.

type Pipeline

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

Pipeline owns all registered ToolProviders and builds executors with the correct hook set. Construct once at server startup; call Register for each tool, then RegisterInto to populate the VirtualToolRegistry.

func NewPipeline

func NewPipeline() *Pipeline

NewPipeline returns an empty Pipeline.

func (*Pipeline) NewExecutor

func (p *Pipeline) NewExecutor(rt RuntimeCaller, deps HookDeps) *DefaultExecutor

NewExecutor returns a DefaultExecutor wired with the current hook list.

func (*Pipeline) Register

func (p *Pipeline) Register(provider ToolProvider)

Register adds a ToolProvider to the pipeline. If provider.Hook() is non-nil it is appended to the hook list.

func (*Pipeline) RegisterInto

func (p *Pipeline) RegisterInto(registry VirtualToolRegistry)

RegisterInto writes all provider descriptors into registry. Call once after all providers have been registered.

type RuntimeCaller

type RuntimeCaller interface {
	CallTool(ctx context.Context, normalizedName, arguments string) (coretool.ToolResult, error)
	ListCallableServerToolNames(ctx context.Context) map[string]struct{}
	GetAdvisorMaxUses() int
}

RuntimeCaller is the subset of the tool runtime used by DefaultExecutor.

type ToolCall

type ToolCall struct {
	NormalizedName string
	Arguments      string
	Messages       []map[string]any
}

ToolCall describes a single MCP tool invocation.

type ToolProvider

type ToolProvider interface {
	// Descriptor returns the VirtualTool to register in the runtime registry.
	Descriptor() coretool.VirtualTool
	// Hook returns a pre-call context hook, or nil if not needed.
	Hook() Hook
}

ToolProvider is implemented by each virtual server tool. Register once; Pipeline derives hooks and registry entries from it.

type VirtualToolRegistry

type VirtualToolRegistry interface {
	Register(coretool.VirtualTool)
}

Jump to

Keyboard shortcuts

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