toolgen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateToolName

func GenerateToolName(path, method, operationID, xMCPName string) string

GenerateToolName generates a tool name. Priority: x-mcp-tool-name > operationId > method_path.

func LoadSpec

func LoadSpec(ctx context.Context, source string) (*openapi3.T, error)

LoadSpec loads and validates an OpenAPI spec.

func SanitizeToolName

func SanitizeToolName(s string) string

SanitizeToolName converts to valid MCP name: lowercase, alphanumeric, dots, underscores.

func ServerURL

func ServerURL(doc *openapi3.T, override string) (string, error)

ServerURL returns the base API URL from spec or override.

Types

type GenerateOptions

type GenerateOptions struct {
	SpecSource string
	Tag        string
	ServerURL  string
}

GenerateOptions configures tool generation.

type GeneratedTool

type GeneratedTool struct {
	Name        string
	Description string
	InputSchema json.RawMessage
	ParamMeta   []ParamMeta
	Path        string
	Method      string
	ServerURL   string
}

GeneratedTool holds MCP tool definition and request metadata.

func Generate

func Generate(ctx context.Context, opts GenerateOptions) ([]GeneratedTool, error)

Generate produces MCP tools from an OpenAPI spec.

type MCPExtensions

type MCPExtensions struct {
	ToolName    string
	Description string
	Hidden      *bool
}

MCPExtensions holds x-mcp-* extension fields.

func ExtractExtensions

func ExtractExtensions(opExt, pathExt map[string]any) MCPExtensions

ExtractExtensions extracts x-mcp-* fields, preferring operation over path level.

type ParamMeta

type ParamMeta struct {
	Name     string
	In       string // "path", "query", "header", "body"
	Required bool
}

ParamMeta tracks parameter source for request reconstruction.

type SchemaResult

type SchemaResult struct {
	InputSchema json.RawMessage
	ParamMeta   []ParamMeta
}

SchemaResult holds converted JSON Schema and parameter location metadata.

func ConvertSchema

func ConvertSchema(params openapi3.Parameters, body *openapi3.RequestBodyRef) (*SchemaResult, error)

ConvertSchema merges parameters and body into flat JSON Schema, erroring on name collisions.

type TagFilter

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

TagFilter filters operations by tag, respecting x-mcp-hidden.

func NewTagFilter

func NewTagFilter(tag string) *TagFilter

NewTagFilter returns a filter for the given tag.

func (*TagFilter) Include

func (f *TagFilter) Include(opTags []string, opExt, pathExt map[string]any) bool

Include returns true if operation should be included. Included if x-mcp-hidden is false, or unset with matching tag.

Jump to

Keyboard shortcuts

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