tool

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tool turns OpenAPI operations into MCP tool definitions and builds the upstream HTTP request for a tool call. One operation becomes one tool: its input schema merges the operation's parameters with the JSON body fields, and a Def remembers where each argument belongs (path, query, header, or body) so the request can be reconstructed faithfully.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRequest

func BuildRequest(ctx context.Context, d Def, baseURL string, args map[string]any) (*http.Request, error)

BuildRequest turns a tool call's arguments into the upstream HTTP request for this operation, routing each argument to the path, query string, headers, or JSON body according to the Def. baseURL is the resolved API server root.

Types

type Def

type Def struct {
	Name        string
	Description string
	InputSchema map[string]any
	// contains filtered or unexported fields
}

Def is a built MCP tool: its wire-facing name/description/schema plus the routing knowledge needed to turn arguments back into an HTTP request.

func Defs

func Defs(doc *openapi.Document, readOnly bool, filter Filter) []Def

Defs builds tool definitions for every operation in the document. When readOnly is set, only safe (GET, HEAD) operations are exposed; filter, if non-empty, further narrows the set to operations it matches. Names are made unique and stable, and are assigned before filtering so a filter can match on the same name `ls` would show, regardless of what else got excluded.

func (Def) Method

func (d Def) Method() string

Method, Path, and Tags expose the underlying operation for previews and for suggesting matchable targets when a filter excludes everything.

func (Def) Path

func (d Def) Path() string

func (Def) Tags added in v0.5.1

func (d Def) Tags() []string

type Filter added in v0.4.0

type Filter struct {
	Include []string // substring or glob, matched against tool name, operationId, and path
	Tags    []string // exact match (case-insensitive) against an operation's tags
}

Filter narrows which operations become tools. An operation is kept if it matches any Include pattern or any Tag, so the two lists are OR'd together as one keep-set; an empty Filter keeps everything.

func (Filter) Empty added in v0.4.0

func (f Filter) Empty() bool

Empty reports whether the filter has no patterns and would keep everything.

Jump to

Keyboard shortcuts

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