mcp

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package mcp turns the operations of the Go model into MCP tools that call the generated client: the tools type that registers them on a server of the official Go SDK, one tool definition and handler per operation, and the input type of every tool.

Index

Constants

View Source
const (
	PartTools  layout.PartID = "mcp.tools"
	PartInputs layout.PartID = "mcp.inputs"
)

The MCP parts.

View Source
const SDKPath = "github.com/modelcontextprotocol/go-sdk/mcp"

SDKPath is the import path of the MCP SDK the tools are written for.

Variables

This section is empty.

Functions

func Templates

func Templates() render.Set

Templates is the MCP template set. No block can be overridden yet.

Types

type AssignView

type AssignView struct {
	Field string
	From  string
}

AssignView fills Field from the input field From.

type FieldView

type FieldView struct {
	Name string
	Type string
	Tag  string
	Doc  string
}

FieldView is one field of an input struct.

type Generator

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

Generator builds the template data of the MCP parts.

func New

func New(m *gomodel.Model, opts Options) (*Generator, []diag.Diagnostic)

New returns the generator of the tools of m: one per operation the config and x-mcp keep, webhooks left out. Tool names that clash are numbered, with a note; an x-mcp name the SDK would reject is replaced with a warning, and a name some hosts reject is kept with one. A default that does not fit its schema is left out of every input, with one warning.

func (*Generator) Parts

func (g *Generator) Parts() []layout.Part

Parts returns the MCP parts with the parts each refers to. The tools build the request options of the client from the inputs, so they refer to the client, the inputs and the parameter types.

func (*Generator) View

func (g *Generator) View(part layout.PartID, s *gocode.Scope) any

View returns the data of part, with names written as the file of s spells them.

type GroupView

type GroupView struct {
	Field   string
	Type    string
	Assigns []AssignView
}

GroupView is the parameters of one location: the options field that holds them, the type of that field, and the field of each parameter with the input field it comes from.

type InputView

type InputView struct {
	Type   string
	Tool   string
	Fields []FieldView
}

InputView is the input of one tool: a field per parameter and one for the body, tagged with the property names of the schema.

type InputsView

type InputsView struct {
	Inputs []InputView
}

InputsView is the data of the inputs part: the input type of every tool.

type Options

type Options struct {
	Client       string
	Namer        *naming.Namer
	DefaultSkip  bool
	User         map[string]any
	Descriptions bool
}

Options are the settings of the MCP generator. Client is the client type the tools call; DefaultSkip leaves every operation out unless x-mcp turns it on; User is the config's user-context. Descriptions copies the spec's descriptions into the comments of the inputs.

type ToolView

type ToolView struct {
	Name         string
	Tool         string
	Description  string
	Schema       string
	Input        string
	Options      string
	IsReadOnly   bool
	IsIdempotent bool
	HasInput     bool
	IsRounded    bool
	Groups       []GroupView
	QueryString  *AssignView
	Body         *AssignView
	IsStream     bool
	HasResult    bool
	Text         string
	File         string
	HasNilCheck  bool
}

ToolView is one tool: its definition and its handler. Name is the operation, Tool the tool name. IsRounded says the handler decodes the arguments again, past the SDK's float64. Of the result, Text is it as text and File as a file; with neither it is structured content. HasNilCheck says the handler checks it for nil.

type ToolsView

type ToolsView struct {
	Client    string
	MCP       string
	JSON      string
	Context   string
	Errors    string
	Runtime   string
	MCPTool   string
	Strings   string
	HasStream bool
	HasFile   bool
	Tools     []ToolView
	User      map[string]any
}

ToolsView is the data of the tools part. Client is the client interface the tools call, as the file writes it; MCP, JSON, Context, Errors, Runtime, MCPTool and Strings are the names the packages are imported under. HasStream says whether a tool answers with the streaming error, HasFile whether one answers with a file.

Jump to

Keyboard shortcuts

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