tool

package
v0.11.1 Latest Latest
Warning

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

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

Documentation

Overview

Package toolmcp adapts MCP server tools for use in bond agent loops. It bridges the Model Context Protocol SDK's client session to bond's Tool interface, allowing bond agents to invoke tools hosted on MCP servers.

Package schema provides JSON Schema generation and validation helpers for bond tools. It wraps github.com/google/jsonschema-go/jsonschema to derive schemas from Go types and validate data against them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnforceStructuredOutput

func EnforceStructuredOutput[Out any](tool bond.Tool) bond.Tool

EnforceStructuredOutput wraps a Tool so that its output is validated against the JSON Schema derived from Out. If the tool's output doesn't conform to the schema, Run returns an error.

Example:

wrapped := schema.EnforceStructuredOutput[MyOutput](baseTool)

func FromMCP

func FromMCP(ctx context.Context, session Session) ([]bond.Tool, error)

ServerTools discovers tools from an MCP server session and returns them as bond Tools. Each returned tool delegates execution to the MCP server via CallTool.

Types

type Schema

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

Schema wraps a generated JSON Schema and implements json.Marshaler.

func SchemaFor

func SchemaFor[T any]() Schema

For derives a JSON Schema from the Go type T using struct tags (json, jsonschema). Returns a Schema suitable for use as bond.FuncToolOptions.InputSchema or OutputSchema.

Example:

type AddInput struct {
    A int `json:"a" jsonschema:"first number"`
    B int `json:"b" jsonschema:"second number"`
}

schema.For[AddInput]() // returns json.Marshaler with the derived schema

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Schema) Validate

func (s Schema) Validate(data any) error

Validate checks whether data conforms to the schema. Returns an error describing all validation failures, or nil if valid.

type Session

type Session interface {
	ListTools(ctx context.Context, params *mcp.ListToolsParams) (*mcp.ListToolsResult, error)
	CallTool(ctx context.Context, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
}

Session defines the subset of *mcp.ClientSession used by this package. Allows mocking in tests.

Directories

Path Synopsis
Package builtin provides a suite of reusable tools for Bond agents that cover common system interactions: shell command execution, HTTP fetching, file I/O, and environment variable access.
Package builtin provides a suite of reusable tools for Bond agents that cover common system interactions: shell command execution, HTTP fetching, file I/O, and environment variable access.
Package registry provides a plugin that exposes a large collection of tools through a stable 3-tool gateway: list_tools, describe_tool, use_tool.
Package registry provides a plugin that exposes a large collection of tools through a stable 3-tool gateway: list_tools, describe_tool, use_tool.

Jump to

Keyboard shortcuts

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