mcp

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Typed MCP tools.

NewTypedTool wraps a typed handler — `func(ctx, In) (Out, error)` where In is a struct — as an MCP Tool. The framework derives the JSON Schema from In via reflection, decodes incoming arguments into a fresh In, runs the same `validate:"..."` rules used by the HTTP binding helpers, and invokes the handler. When Out is a non-empty struct (or a slice of one), an `outputSchema` is also derived so MCP clients can introspect the return shape — see MCP spec revision 2025-06-18 for the wire field.

The old builder path (mcp.NewTool(...).WithParameter(...).WithExecute(...)) keeps working; this is additive. Use the typed shape for new tools — it removes the hand-mirrored schema, the unchecked `params.(string)` type assertions, and the unchecked `(any, error)` return.

Schema generation covers the subset MCP clients actually consume:

  • object with typed properties + required list
  • strings, integers, numbers, booleans, arrays, nested objects
  • enum (from `validate:"oneof=…"`)
  • minimum/maximum (from `validate:"min=N,max=N"` on numeric fields)
  • minLength/maxLength (from min/max on strings; from `len=N`)
  • minItems/maxItems (from min/max on arrays/slices; from `len=N`)
  • description (from `mcp:"desc=…"`)

`$ref` / `$defs` are deliberately not emitted — nested structs are inlined. Cross-field rules and custom validators are out of scope.

Package mcp implements the Model Context Protocol (MCP) over JSON-RPC 2.0.

The package is transport-agnostic: HTTP, Server-Sent Events (SSE), and stdio transports are all provided, but the protocol Handler does not depend on any specific transport. The HTTP-server integration lives in pkg/server; the built-in tools and resources that need a *server.Server live in pkg/mcp/builtin.

Index

Constants

View Source
const (
	// DefaultProtocolVersion is the initialize-era MCP protocol version
	// advertised by default. It remains the default for compatibility with
	// existing 2025 clients while Streamable HTTP negotiates the current
	// revision independently on each request.
	DefaultProtocolVersion = "2025-11-25"

	// StreamableHTTPProtocolVersion is the current stateless Streamable HTTP
	// protocol revision supported by Handler.ServeHTTP.
	StreamableHTTPProtocolVersion = "2026-07-28"
)
View Source
const ProtocolVersion = DefaultProtocolVersion

ProtocolVersion is kept as a compatibility alias for callers that used the old package constant. New code should prefer DefaultProtocolVersion or a Handler's configured ProtocolVersion.

Variables

View Source
var (
	ErrMethodNotAllowed       = errors.New("method not allowed")
	ErrUnsupportedContentType = errors.New("unsupported content type")
)

ErrMethodNotAllowed and ErrUnsupportedContentType are sentinel errors used by the HTTP transport so ServeHTTP can categorise failures with errors.Is rather than substring-matching free-form messages. Adding a wrap site is a public contract — keep the sentinel set narrow and stable.

Functions

func NewStdioTransport

func NewStdioTransport(logger *slog.Logger) *stdioTransport

NewStdioTransport creates a new stdio transport using os.Stdin / os.Stdout.

func NewStdioTransportWithIO

func NewStdioTransportWithIO(r io.Reader, w io.Writer, logger *slog.Logger) *stdioTransport

NewStdioTransportWithIO creates a new stdio transport with custom IO.

func ToolError

func ToolError(message string) error

ToolError returns an error that tools can use for domain-level failures. The MCP handler converts it into a successful tools/call response with isError=true instead of a JSON-RPC protocol error.

func ToolErrorf

func ToolErrorf(format string, args ...any) error

ToolErrorf formats a domain-level tool failure.

Types

type CacheableResource

type CacheableResource interface {
	Resource
	ResourceCacheTTL() time.Duration
}

CacheableResource is an optional extension for resources whose read result is safe to reuse for a bounded time. Resources are uncached by default so live observability views (health, metrics, logs, route lists) never return stale data unless they explicitly opt in.

type Capabilities

type Capabilities struct {
	Resources *ResourcesCapability `json:"resources,omitempty"`
	Tools     *ToolsCapability     `json:"tools,omitempty"`
	SSE       *SSECapability       `json:"sse,omitempty"`
}

Capabilities represents the server's advertised MCP capabilities. Add fields here only when the corresponding capability is actually wired in Handler.Capabilities() and exercised on the wire; advertising an unsupported capability is worse than omitting it.

type ClientInfo

type ClientInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ClientInfo identifies an MCP client.

type DiscoveryConfig

type DiscoveryConfig struct {
	// MCPEndpoint is the URL path the MCP handler is mounted on (e.g. "/mcp").
	MCPEndpoint string
	// DefaultAddr is used to derive the base URL when the request has no Host header.
	DefaultAddr string
	// Transport identifies the transport in use (HTTP / Stdio).
	Transport TransportType
	// Policy controls discovery list visibility.
	Policy DiscoveryPolicy
	// Dev is retained for v1 source compatibility and has no effect. Tool
	// registration and IsDiscoverable control exposure.
	//
	// Deprecated: this field is a no-op and will be removed in v2.
	Dev bool
	// Filter, if non-nil, makes the final decision per tool. It overrides the
	// default rules entirely.
	Filter func(toolName string, r *http.Request) bool
}

DiscoveryConfig groups the inputs needed to build a DiscoveryInfo response.

type DiscoveryInfo

type DiscoveryInfo struct {
	Version      string            `json:"version"`
	Versions     []string          `json:"versions,omitempty"`
	Transports   []TransportInfo   `json:"transports"`
	Endpoints    map[string]string `json:"endpoints"`
	Capabilities map[string]any    `json:"capabilities,omitempty"`
}

DiscoveryInfo describes the MCP endpoints surfaced by the discovery API.

type DiscoveryPolicy

type DiscoveryPolicy int

DiscoveryPolicy controls how MCP tools and resources are exposed via the discovery endpoints (/.well-known/mcp.json and /mcp/discover).

const (
	// DiscoveryPublic shows all discoverable tools/resources (default).
	DiscoveryPublic DiscoveryPolicy = iota
	// DiscoveryCount only exposes counts, not names.
	DiscoveryCount
	// DiscoveryAuthenticated returns the full list only when the request
	// carries an Authorization header.
	DiscoveryAuthenticated
	// DiscoveryNone hides all tool/resource information.
	DiscoveryNone
)

type Extension

type Extension interface {
	// Name returns the extension name (e.g., "e-commerce", "blog").
	Name() string
	// Description returns a human-readable description.
	Description() string
	// Tools returns the tools provided by this extension.
	Tools() []Tool
	// Resources returns the resources provided by this extension.
	Resources() []Resource
	// Configure runs before registration with the supplied handler. Use it to
	// wire the extension up to the handler (e.g. capture a reference, register
	// extra namespaces).
	Configure(h *Handler) error
}

Extension represents a collection of MCP tools and resources that can be registered as a group. It's the lightweight way to package related functionality together.

type ExtensionBuilder

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

ExtensionBuilder provides a fluent API for building Extensions.

func NewExtension

func NewExtension(name string) *ExtensionBuilder

NewExtension creates a new extension builder.

func (*ExtensionBuilder) Build

func (b *ExtensionBuilder) Build() Extension

func (*ExtensionBuilder) WithDescription

func (b *ExtensionBuilder) WithDescription(desc string) *ExtensionBuilder

func (*ExtensionBuilder) WithResource

func (b *ExtensionBuilder) WithResource(resource Resource) *ExtensionBuilder

func (*ExtensionBuilder) WithResourceTemplate

func (b *ExtensionBuilder) WithResourceTemplate(template ResourceTemplate) *ExtensionBuilder

func (*ExtensionBuilder) WithTool

func (b *ExtensionBuilder) WithTool(tool Tool) *ExtensionBuilder

type Handler

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

Handler manages MCP protocol communication with multiple namespace support. The SSE state machine (client registry + per-client request channels) lives entirely in sseManager — Handler stays focused on JSON-RPC dispatch.

func NewHandler

func NewHandler(serverInfo ServerInfo) *Handler

NewHandler creates a new MCP handler instance.

func (*Handler) BuildDiscoveryInfo

func (h *Handler) BuildDiscoveryInfo(r *http.Request, cfg DiscoveryConfig) DiscoveryInfo

BuildDiscoveryInfo constructs the discovery payload based on the supplied configuration and request. The caller is responsible for marshalling and writing the response.

func (*Handler) Capabilities

func (h *Handler) Capabilities() Capabilities

Capabilities returns the server's MCP capabilities.

func (*Handler) HasNamespace

func (h *Handler) HasNamespace(name string) bool

HasNamespace reports whether a namespace with the given name has been registered via RegisterNamespace.

func (*Handler) HasResource

func (h *Handler) HasResource(uri string) bool

HasResource reports whether a resource with the given URI is registered.

func (*Handler) HasResourceTemplate

func (h *Handler) HasResourceTemplate(uriTemplate string) bool

HasResourceTemplate reports whether a resource template is registered.

func (*Handler) HasTool

func (h *Handler) HasTool(name string) bool

HasTool reports whether a tool with the given (possibly prefixed) name is registered.

func (*Handler) Logger

func (h *Handler) Logger() *slog.Logger

Logger returns the handler's logger.

func (*Handler) ProcessRequest

func (h *Handler) ProcessRequest(requestData []byte) []byte

ProcessRequest processes a single MCP request (raw JSON).

func (*Handler) ProcessRequestWithTransport

func (h *Handler) ProcessRequestWithTransport(transport Transport) error

ProcessRequestWithTransport processes an MCP request using the provided transport.

func (*Handler) ProtocolVersion

func (h *Handler) ProtocolVersion() string

ProtocolVersion returns the MCP protocol version this handler advertises.

func (*Handler) RPCEngine

func (h *Handler) RPCEngine() *jsonrpc.Engine

RPCEngine returns the underlying JSON-RPC engine. Exposed so tests and transports can dispatch a parsed request without re-marshalling.

func (*Handler) RegisterExtension

func (h *Handler) RegisterExtension(ext Extension) error

RegisterExtension wires all of an Extension's tools and resources into the handler. It calls Configure(h) first so the extension can hook in.

func (*Handler) RegisterNamespace

func (h *Handler) RegisterNamespace(name string, configs ...NamespaceConfig) error

RegisterNamespace registers an entire namespace with its tools and resources.

func (*Handler) RegisterResource

func (h *Handler) RegisterResource(resource Resource)

RegisterResource registers an MCP resource without namespace prefixing.

func (*Handler) RegisterResourceInNamespace

func (h *Handler) RegisterResourceInNamespace(resource Resource, namespace string)

RegisterResourceInNamespace registers an MCP resource in the specified namespace.

func (*Handler) RegisterResourceTemplate

func (h *Handler) RegisterResourceTemplate(template ResourceTemplate)

RegisterResourceTemplate registers an MCP resource template without namespace prefixing.

func (*Handler) RegisterResourceTemplateInNamespace

func (h *Handler) RegisterResourceTemplateInNamespace(template ResourceTemplate, namespace string)

RegisterResourceTemplateInNamespace registers an MCP resource template in the specified namespace.

func (*Handler) RegisterTool

func (h *Handler) RegisterTool(tool Tool)

RegisterTool registers an MCP tool without namespace prefixing.

func (*Handler) RegisterToolInNamespace

func (h *Handler) RegisterToolInNamespace(tool Tool, namespace string)

RegisterToolInNamespace registers an MCP tool in the specified namespace.

func (*Handler) RegisteredResourceTemplates

func (h *Handler) RegisteredResourceTemplates() []string

RegisteredResourceTemplates returns all registered resource template URI templates in registration order.

func (*Handler) RegisteredResources

func (h *Handler) RegisteredResources() []string

RegisteredResources returns all registered resource URIs. Returns a non-nil slice even when no resources are registered.

func (*Handler) RegisteredTools

func (h *Handler) RegisteredTools() []string

RegisteredTools returns all registered tool names. Returns a non-nil slice even when no tools are registered.

func (*Handler) ResourceCount

func (h *Handler) ResourceCount() int

ResourceCount returns the number of registered resources.

func (*Handler) ResourceTemplateCount

func (h *Handler) ResourceTemplateCount() int

ResourceTemplateCount returns the number of registered resource templates.

func (*Handler) RunStdioLoop

func (h *Handler) RunStdioLoop() error

RunStdioLoop runs the MCP handler in stdio mode until EOF is received. EOF is treated as a normal shutdown signal.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for the MCP endpoint.

func (*Handler) ServerInfo

func (h *Handler) ServerInfo() ServerInfo

ServerInfo returns the server info associated with this handler.

func (*Handler) SetLegacyRoutedSSEEnabled deprecated

func (h *Handler) SetLegacyRoutedSSEEnabled(enabled bool)

SetLegacyRoutedSSEEnabled enables HyperServe's proprietary X-SSE-* routed stream. It is disabled by default and exists only for migration of existing HyperServe-specific clients.

Deprecated: use MCP 2026-07-28 Streamable HTTP and subscriptions/listen.

func (*Handler) SetLogger

func (h *Handler) SetLogger(l *slog.Logger)

SetLogger overrides the handler's logger. Useful for tests that want to silence output.

func (*Handler) SetOriginValidator

func (h *Handler) SetOriginValidator(validator func(*http.Request) bool)

SetOriginValidator overrides the default MCP Origin policy. The default accepts requests without Origin (normal for non-browser clients) and requires browser origins to match the request Host. Passing nil restores that default. Applications allowing cross-origin browser clients should authenticate them and validate an explicit origin allowlist here.

func (*Handler) SetProtocolVersion

func (h *Handler) SetProtocolVersion(version string)

SetProtocolVersion overrides the initialize-era compatibility version advertised in legacy responses and discovery. Empty values reset to the default. StreamableHTTPProtocolVersion is selected independently through per-request metadata and cannot be configured as the legacy version.

func (*Handler) SetToolCallTimeout

func (h *Handler) SetToolCallTimeout(d time.Duration)

SetToolCallTimeout overrides the per-call timeout used when dispatching tools/call. Zero or negative values reset to defaultToolCallTimeout.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context) error

Shutdown gracefully completes active subscriptions/listen streams and closes legacy routed SSE connections. It is safe to call more than once.

func (*Handler) Tool

func (h *Handler) Tool(name string) (Tool, bool)

Tool returns a tool by its (possibly prefixed) name.

func (*Handler) ToolCount

func (h *Handler) ToolCount() int

ToolCount returns the number of registered tools.

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string     `json:"protocolVersion"`
	Capabilities    any        `json:"capabilities"`
	ClientInfo      ClientInfo `json:"clientInfo"`
}

InitializeParams is the parameter struct for the "initialize" method.

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string       `json:"protocolVersion"`
	Capabilities    Capabilities `json:"capabilities"`
	ServerInfo      ServerInfo   `json:"serverInfo"`
}

InitializeResult is the result returned by the "initialize" method.

type Namespace

type Namespace struct {
	Name              string
	Tools             []Tool
	Resources         []Resource
	ResourceTemplates []ResourceTemplate
}

Namespace represents a named collection of MCP tools and resources.

type NamespaceConfig

type NamespaceConfig func(*Namespace)

NamespaceConfig configures a Namespace.

func WithNamespaceResourceTemplates

func WithNamespaceResourceTemplates(templates ...ResourceTemplate) NamespaceConfig

WithNamespaceResourceTemplates adds resource templates to a namespace.

func WithNamespaceResources

func WithNamespaceResources(resources ...Resource) NamespaceConfig

WithNamespaceResources adds resources to a namespace.

func WithNamespaceTools

func WithNamespaceTools(tools ...Tool) NamespaceConfig

WithNamespaceTools adds tools to a namespace.

type Resource

type Resource interface {
	URI() string
	Name() string
	Description() string
	MimeType() string
	Read() (any, error)
	List() ([]string, error)
}

Resource defines the interface for Model Context Protocol resources.

type ResourceContent

type ResourceContent struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType"`
	Text     any    `json:"text"`
}

ResourceContent represents the content body of a resource.

type ResourceEmitter

type ResourceEmitter interface {
	Update(uri string) error
}

ResourceEmitter emits resource update notifications for an active subscription. MCP update notifications are invalidation signals: clients should call resources/read to fetch the latest content.

type ResourceInfo

type ResourceInfo struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	Description string `json:"description"`
	MimeType    string `json:"mimeType"`
}

ResourceInfo describes a resource in resources/list responses.

type ResourceReadParams

type ResourceReadParams struct {
	URI string `json:"uri"`
}

ResourceReadParams is the parameter struct for "resources/read".

type ResourceTemplate

type ResourceTemplate interface {
	URITemplate() string
	Name() string
	Description() string
	MimeType() string
	Match(uri string) (params map[string]string, ok bool)
	Read(ctx context.Context, uri string, params map[string]string) (any, error)
}

ResourceTemplate defines a parameterized family of MCP resources.

type ResourceTemplateExtension

type ResourceTemplateExtension interface {
	ResourceTemplates() []ResourceTemplate
}

ResourceTemplateExtension is implemented by extensions that also provide parameterized resource templates. It is optional so existing Extension implementations remain source-compatible.

type ResourceTemplateInfo

type ResourceTemplateInfo struct {
	URITemplate string `json:"uriTemplate"`
	Name        string `json:"name"`
	Description string `json:"description"`
	MimeType    string `json:"mimeType,omitempty"`
}

ResourceTemplateInfo describes a resource template in resources/templates/list responses.

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool `json:"subscribe,omitempty"`
	ListChanged bool `json:"listChanged,omitempty"`
}

ResourcesCapability represents the server's resource management capabilities.

type SSECapability

type SSECapability struct {
	Enabled       bool   `json:"enabled"`
	Endpoint      string `json:"endpoint"`
	HeaderRouting bool   `json:"headerRouting"`
}

SSECapability represents the server's Server-Sent Events capability.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ServerInfo identifies an MCP server.

type SubscribableResourceTemplate

type SubscribableResourceTemplate interface {
	ResourceTemplate
	Subscribe(ctx context.Context, uri string, params map[string]string, emit ResourceEmitter) error
}

SubscribableResourceTemplate extends ResourceTemplate with live update subscriptions. Subscribe should block until ctx is canceled or the subscription ends.

type Tool

type Tool interface {
	Name() string
	Description() string
	Schema() map[string]any
	Execute(params map[string]any) (any, error)
}

Tool defines the interface for Model Context Protocol tools.

func NewTypedTool

func NewTypedTool[In, Out any](name, description string, fn TypedToolFunc[In, Out]) Tool

NewTypedTool returns a Tool whose input schema is derived from In (which must be a struct or pointer to a struct). When Out is also a struct (or slice/array of struct), an output schema is derived too and emitted as `outputSchema` in tools/list. The returned Tool implements ToolWithContext, so the per-call timeout enforced by Handler.handleToolsCall is propagated to fn.

type CreatePostArgs struct {
    Title  string   `json:"title"  validate:"required,max=200"`
    Author string   `json:"author" validate:"required"`
    Tags   []string `json:"tags,omitempty" validate:"max=10"`
}
type Post struct {
    ID, Title, Author string
    Tags              []string
    CreatedAt         time.Time
}

tool := mcp.NewTypedTool("create_post", "Create a new blog post.",
    func(ctx context.Context, args CreatePostArgs) (Post, error) {
        return blog.create(args)
    })
srv.RegisterMCPTool(tool)

Type inference at the call site picks both In and Out off the function value, so callers don't write the type parameters explicitly.

Panics at registration if In is not a struct type — the panic is preferable to silently emitting a schema no client can use.

type ToolBuilder

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

ToolBuilder provides a fluent API for building Tools with a hand-tuned schema. Prefer NewTypedTool[In, Out] when the input shape is a struct; reach for this builder when you need a schema the type system can't describe (oneOf, polymorphic shapes, schema-from-JSON-file, etc.).

func NewTool

func NewTool(name string) *ToolBuilder

NewTool creates a new tool builder.

func (*ToolBuilder) Build

func (b *ToolBuilder) Build() Tool

func (*ToolBuilder) WithDescription

func (b *ToolBuilder) WithDescription(desc string) *ToolBuilder

func (*ToolBuilder) WithExecute

func (b *ToolBuilder) WithExecute(fn func(map[string]any) (any, error)) *ToolBuilder

func (*ToolBuilder) WithParameter

func (b *ToolBuilder) WithParameter(name, paramType, description string, required bool) *ToolBuilder

type ToolCallParams

type ToolCallParams struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`
}

ToolCallParams is the parameter struct for "tools/call".

type ToolInfo

type ToolInfo struct {
	Name         string         `json:"name"`
	Description  string         `json:"description"`
	InputSchema  map[string]any `json:"inputSchema"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
}

ToolInfo describes a tool in tools/list responses. OutputSchema is the `outputSchema` field added in the MCP spec revision 2025-06-18; tools that implement ToolWithOutputSchema populate it via the handler's tools/list path, others omit it.

type ToolResult

type ToolResult struct {
	Content []map[string]any `json:"content"`
	IsError bool             `json:"isError,omitempty"`
}

ToolResult represents the result of a tool execution.

type ToolWithContext

type ToolWithContext interface {
	Tool
	ExecuteWithContext(ctx context.Context, params map[string]any) (any, error)
}

ToolWithContext is an enhanced Tool that supports context for cancellation and timeouts during ExecuteWithContext.

type ToolWithOutputSchema

type ToolWithOutputSchema interface {
	OutputSchema() map[string]any
}

ToolWithOutputSchema is implemented by tools that can describe their return shape. The handler's tools/list path checks this interface via type assertion and surfaces the result as the `outputSchema` field on ToolInfo (MCP spec revision 2025-06-18). Returning nil omits the field.

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

ToolsCapability represents the server's tool execution capabilities.

type Transport

type Transport interface {
	Send(response *jsonrpc.Response) error
	Receive() (*jsonrpc.Request, error)
	Close() error
}

Transport defines the interface for MCP communication transports.

type TransportConfig

type TransportConfig func(*TransportOptions)

TransportConfig configures MCP transport options.

func OverStdio

func OverStdio() TransportConfig

OverStdio configures MCP to use stdio transport.

The HTTP/SSE counterparts that used to live here were unused (no caller outside this file); HTTP is the default when no Over* config is supplied, and SSE shares the HTTP endpoint via Accept-header routing. Configure the endpoint path with WithMCPEndpoint from pkg/server instead.

func WithDeveloperMode

func WithDeveloperMode() TransportConfig

WithDeveloperMode marks the transport options as opting into the developer preset.

func WithObservabilityMode

func WithObservabilityMode() TransportConfig

WithObservabilityMode marks the transport options as opting into the observability preset. The preset itself is implemented by callers (e.g. pkg/mcp/builtin) which read this flag.

type TransportInfo

type TransportInfo struct {
	Type        string            `json:"type"`
	Endpoint    string            `json:"endpoint"`
	Description string            `json:"description"`
	Headers     map[string]string `json:"headers,omitempty"`
}

TransportInfo describes one available transport mechanism.

type TransportOptions

type TransportOptions struct {
	Transport         TransportType
	Endpoint          string
	ObservabilityMode bool
	DeveloperMode     bool
}

TransportOptions holds transport configuration. It is exported so callers (most notably pkg/server) can inspect the resolved transport selection after applying a series of TransportConfig functions.

type TransportType

type TransportType int

TransportType identifies the kind of transport used for MCP communication.

const (
	// HTTPTransport selects HTTP-based MCP communication.
	HTTPTransport TransportType = iota
	// StdioTransport selects stdin/stdout MCP communication.
	StdioTransport
)

type TypedToolFunc

type TypedToolFunc[In, Out any] func(ctx context.Context, args In) (Out, error)

TypedToolFunc is the signature an MCP tool implements when registered via NewTypedTool. The In value is decoded and validated before the function runs; Out is JSON-marshaled by the framework. Use `struct{}` for either side when the tool takes no arguments or returns no payload.

Directories

Path Synopsis
Package builtin provides ready-to-register MCP tools and resources.
Package builtin provides ready-to-register MCP tools and resources.

Jump to

Keyboard shortcuts

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