tool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tool provides proxy-tool registration on top of modelcontextprotocol/go-sdk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProxy

func AddProxy[Args, Result any](server *sdkmcp.Server, b *Bridge, spec ProxySpec[Args, Result])

AddProxy registers a typed proxy tool on a go-sdk server.

func AddProxyNoArgs

func AddProxyNoArgs[Result any](server *sdkmcp.Server, b *Bridge, name, description string, execute func(context.Context, *Bridge) (Result, error))

AddProxyNoArgs registers a proxy tool with no arguments.

func CallNoArgs

func CallNoArgs[Result any](b *Bridge, ctx context.Context, method string) (Result, error)

CallNoArgs executes a backend call with no params.

func CallTyped

func CallTyped[Args, Result any](b *Bridge, ctx context.Context, method string, args Args) (Result, error)

CallTyped executes a backend call with typed result decoding.

func NormalizeField

func NormalizeField(p *string, norm func(string) (string, error)) error

NormalizeField normalizes one string field in tool args.

func NormalizeID

func NormalizeID[T any](args T, norm func(string) (string, error), idOf func(*T) *string) (T, error)

NormalizeID normalizes one id field in typed tool args.

func PrepareWorkDir

func PrepareWorkDir[T any](defaultWorkDir string, args T, set func(*T, string), get func(T) string) (T, summarize.Meta, error)

PrepareWorkDir fills an empty work_dir field from defaultWorkDir.

func PresentCappedList

func PresentCappedList[T any](items []T, limit int, hintTemplate string) (any, summarize.Meta)

PresentCappedList wraps a slice in structured tool list data.

func ResolveWorkDir

func ResolveWorkDir(defaultWorkDir, argWorkDir string) string

ResolveWorkDir returns argWorkDir when set, otherwise defaultWorkDir.

Types

type Backend

type Backend interface {
	Call(ctx context.Context, method string, params any) (any, error)
}

Backend executes tool calls against an application service.

type Bridge

type Bridge struct {
	Backend   Backend
	Responder *summarize.Responder
}

Bridge carries shared proxy-tool state.

type FuncBackend

type FuncBackend func(ctx context.Context, method string, params any) (any, error)

FuncBackend adapts a function to Backend.

func (FuncBackend) Call

func (f FuncBackend) Call(ctx context.Context, method string, params any) (any, error)

Call implements Backend.

type ProxySpec

type ProxySpec[Args, Result any] struct {
	Name        string
	Description string
	Normalize   func(Args) (Args, error)
	Validate    func(Args) error
	Prepare     func(*Bridge, Args) (Args, summarize.Meta, error)
	Execute     func(context.Context, *Bridge, Args) (Result, error)
	Present     func(Args, Result) (any, summarize.Meta)
}

ProxySpec configures one proxied MCP tool.

Jump to

Keyboard shortcuts

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