Documentation
¶
Overview ¶
Package mcpapi adapts the official MCP Go SDK to the builder-style API this codebase was written against, so tool definitions did not have to change when the project moved off mark3labs/mcp-go for MCP spec 2026-07-28.
Everything here produces official SDK types: Tool, CallToolResult and TextContent are aliases, and input schemas are *jsonschema.Schema.
Index ¶
- func InputSchemaOf(t Tool) *jsonschema.Schema
- type CallToolRequest
- type CallToolResult
- type Content
- type PropertyOption
- func DefaultArray[T any](value []T) PropertyOption
- func DefaultBool(value bool) PropertyOption
- func DefaultNumber[T int | int64 | float64](value T) PropertyOption
- func DefaultString(value string) PropertyOption
- func Description(desc string) PropertyOption
- func Enum(values ...string) PropertyOption
- func Items(schema any) PropertyOption
- func MaxLength(maxLen int) PropertyOption
- func Maximum(maxVal float64) PropertyOption
- func MinLength(minLen int) PropertyOption
- func Minimum(minVal float64) PropertyOption
- func Properties(props map[string]any) PropertyOption
- func Required() PropertyOption
- func WithStringItems(opts ...PropertyOption) PropertyOption
- type Schema
- type TextContent
- type Tool
- type ToolAnnotations
- type ToolOption
- func WithArray(name string, opts ...PropertyOption) ToolOption
- func WithBoolean(name string, opts ...PropertyOption) ToolOption
- func WithDescription(description string) ToolOption
- func WithDestructiveHintAnnotation(value bool) ToolOption
- func WithIdempotentHintAnnotation(value bool) ToolOption
- func WithNumber(name string, opts ...PropertyOption) ToolOption
- func WithObject(name string, opts ...PropertyOption) ToolOption
- func WithOpenWorldHintAnnotation(value bool) ToolOption
- func WithReadOnlyHintAnnotation(value bool) ToolOption
- func WithString(name string, opts ...PropertyOption) ToolOption
- func WithTitle(title string) ToolOption
- func WithTitleAnnotation(title string) ToolOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InputSchemaOf ¶
func InputSchemaOf(t Tool) *jsonschema.Schema
InputSchemaOf returns a tool's input schema, or nil if it is not a *jsonschema.Schema (which only happens for tools built outside this package).
Types ¶
type CallToolRequest ¶
type CallToolRequest = mcp.CallToolRequest
SDK types re-exported so tools only import this package.
type CallToolResult ¶
type CallToolResult = mcp.CallToolResult
SDK types re-exported so tools only import this package.
func NewToolResultError ¶
func NewToolResultError(text string) *CallToolResult
NewToolResultError returns a tool-level failure. This is not a protocol error: the message is delivered to the model so it can self-correct.
func NewToolResultErrorFromErr ¶
func NewToolResultErrorFromErr(text string, err error) *CallToolResult
NewToolResultErrorFromErr returns a tool-level failure built from an error.
func NewToolResultJSON ¶
func NewToolResultJSON[T any](data T) (*CallToolResult, error)
NewToolResultJSON returns a successful result carrying data as JSON, both as text and as structured content.
func NewToolResultText ¶
func NewToolResultText(text string) *CallToolResult
NewToolResultText returns a successful result carrying a single text block.
type PropertyOption ¶
type PropertyOption func(*property)
PropertyOption configures a single parameter of a tool's input schema.
func DefaultArray ¶
func DefaultArray[T any](value []T) PropertyOption
DefaultArray sets the default value of an array parameter.
func DefaultBool ¶
func DefaultBool(value bool) PropertyOption
DefaultBool sets the default value of a boolean parameter.
func DefaultNumber ¶
func DefaultNumber[T int | int64 | float64](value T) PropertyOption
DefaultNumber sets the default value of a number parameter.
func DefaultString ¶
func DefaultString(value string) PropertyOption
DefaultString sets the default value of a string parameter.
func Description ¶
func Description(desc string) PropertyOption
Description sets a parameter description.
func Enum ¶
func Enum(values ...string) PropertyOption
Enum restricts a string parameter to a fixed set of values.
func Items ¶
func Items(schema any) PropertyOption
Items sets the element schema of an array parameter.
func MaxLength ¶
func MaxLength(maxLen int) PropertyOption
MaxLength sets the maximum length of a string parameter.
func Maximum ¶
func Maximum(maxVal float64) PropertyOption
Maximum sets the inclusive upper bound of a number parameter.
func MinLength ¶
func MinLength(minLen int) PropertyOption
MinLength sets the minimum length of a string parameter.
func Minimum ¶
func Minimum(minVal float64) PropertyOption
Minimum sets the inclusive lower bound of a number parameter.
func Properties ¶
func Properties(props map[string]any) PropertyOption
Properties sets the properties of an object parameter. Each value is a JSON Schema fragment, either a *jsonschema.Schema or a map[string]any.
func WithStringItems ¶
func WithStringItems(opts ...PropertyOption) PropertyOption
WithStringItems declares an array parameter's elements as strings.
type Schema ¶
type Schema = jsonschema.Schema
SDK types re-exported so tools only import this package.
type TextContent ¶
type TextContent = mcp.TextContent
SDK types re-exported so tools only import this package.
func AsTextContent ¶
func AsTextContent(content any) (*TextContent, bool)
AsTextContent reports whether content is a text block, returning it if so.
type Tool ¶
SDK types re-exported so tools only import this package.
func NewTool ¶
func NewTool(name string, opts ...ToolOption) Tool
NewTool builds a tool with an object input schema. The SDK panics on registration if the input schema is nil or is not an object, so it is always populated here.
type ToolAnnotations ¶
type ToolAnnotations = mcp.ToolAnnotations
SDK types re-exported so tools only import this package.
type ToolOption ¶
type ToolOption func(*Tool)
ToolOption configures a Tool.
func WithArray ¶
func WithArray(name string, opts ...PropertyOption) ToolOption
WithArray adds an array parameter.
func WithBoolean ¶
func WithBoolean(name string, opts ...PropertyOption) ToolOption
WithBoolean adds a boolean parameter.
func WithDescription ¶
func WithDescription(description string) ToolOption
WithDescription sets the tool description.
func WithDestructiveHintAnnotation ¶
func WithDestructiveHintAnnotation(value bool) ToolOption
WithDestructiveHintAnnotation declares whether the tool may perform destructive updates.
func WithIdempotentHintAnnotation ¶
func WithIdempotentHintAnnotation(value bool) ToolOption
WithIdempotentHintAnnotation declares whether repeated calls with the same arguments have any additional effect.
func WithNumber ¶
func WithNumber(name string, opts ...PropertyOption) ToolOption
WithNumber adds a number parameter.
func WithObject ¶
func WithObject(name string, opts ...PropertyOption) ToolOption
WithObject adds an object parameter.
func WithOpenWorldHintAnnotation ¶
func WithOpenWorldHintAnnotation(value bool) ToolOption
WithOpenWorldHintAnnotation declares whether the tool interacts with external entities.
func WithReadOnlyHintAnnotation ¶
func WithReadOnlyHintAnnotation(value bool) ToolOption
WithReadOnlyHintAnnotation declares whether the tool modifies its environment.
func WithString ¶
func WithString(name string, opts ...PropertyOption) ToolOption
WithString adds a string parameter.
func WithTitle ¶
func WithTitle(title string) ToolOption
WithTitle sets the tool's human-readable display name.
func WithTitleAnnotation ¶
func WithTitleAnnotation(title string) ToolOption
WithTitleAnnotation sets the annotation title.