mcptool

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcptool provides integration with the Model Context Protocol (MCP). It allows agents to connect to external MCP servers via stdio (subprocess) or HTTP (SSE / streamable HTTP) and expose their tools as tool.Tool / tool.FuncTool instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTool

func AddTool(src *mcp.Server, tl tool.FuncTool)

AddTool registers a tool.FuncTool on the given mcp.Server so it is exposed to MCP clients. Native mcp.Content and []mcp.Content results are returned as MCP content blocks; they must contain content types valid in a tool response. Nil content entries are represented as the text "null". A *mcp.CallToolResult is returned as-is. Array return schemas and their structured results are wrapped in an object with a "result" property so structured output also works with older MCP clients. The text content retains the original JSON for existing clients. Explicit MCP results and MCP/framework content bypass this wrapping. When an output schema is advertised, callers returning these types must provide structured content matching that schema for successful results.

func Connect

func Connect(ctx context.Context, transport mcp.Transport) (*mcp.ClientSession, error)

Connect dials an MCP server over the given transport and returns a client session with task-extension support.

func ListTools

func ListTools(ctx context.Context, session *mcp.ClientSession) ([]tool.Tool, error)

ListTools enumerates all pages of the remote server's tools and wraps each as a tool.Tool.

func ListToolsWithTasks added in v0.3.1

func ListToolsWithTasks(ctx context.Context, session *mcp.ClientSession, options TaskOptions) ([]tool.Tool, error)

ListToolsWithTasks lists the server's tools as task-aware functions. Calls to tools that return an MCP task are polled until completion; servers that do not create tasks can still return results inline. The session must be created with Connect so the task RPC methods are registered. Zero-valued options use the defaults documented on TaskOptions. The options and their capability declarations are copied before listing; subsequent changes do not affect the returned tools. Task input handling requires both a handler and explicit input capabilities in options.

See https://modelcontextprotocol.io/extensions/tasks/overview.

Types

type TaskInputHandler added in v0.3.1

type TaskInputHandler func(context.Context, mcp.InputRequest) (mcp.InputResponse, error)

TaskInputHandler resolves an input request from a running MCP task. It must support the capabilities declared in TaskOptions and be safe for concurrent calls when tools are invoked concurrently.

type TaskOptions added in v0.3.1

type TaskOptions struct {
	// DisableCancelRemoteTaskOnLocalCancellation leaves the remote task running
	// when the local invocation is canceled. When false, the tool makes a
	// best-effort attempt to cancel the remote task.
	DisableCancelRemoteTaskOnLocalCancellation bool

	// MaxConsecutiveStuckPolls limits consecutive input_required polls
	// without new input requests. Zero defaults to 60.
	MaxConsecutiveStuckPolls int

	// MaxTotalInputRequests limits unique input requests per invocation.
	// Zero defaults to 100.
	MaxTotalInputRequests int

	// RemoteCancellationTimeout bounds a remote cancellation attempt.
	// Zero defaults to 5 seconds.
	RemoteCancellationTimeout time.Duration

	// MinimumPollingInterval is the shortest accepted server polling interval.
	// Zero defaults to 10 milliseconds.
	MinimumPollingInterval time.Duration

	// MaximumPollingInterval is the longest accepted server polling interval.
	// Zero uses the largest whole-millisecond [time.Duration].
	MaximumPollingInterval time.Duration

	// InputHandler resolves task input requests. It must be configured together
	// with ElicitationCapabilities, SamplingCapabilities, or both.
	InputHandler TaskInputHandler

	// ElicitationCapabilities declares the elicitation modes supported by
	// InputHandler. Nil declares no support; an empty value declares form
	// elicitation. The declaration is sent only on task-aware requests.
	ElicitationCapabilities *mcp.ElicitationCapabilities

	// SamplingCapabilities declares the sampling features supported by
	// InputHandler. Nil declares no support; an empty value declares basic
	// sampling without context or tools. The declaration is sent only on
	// task-aware requests.
	SamplingCapabilities *mcp.SamplingCapabilities //nolint:staticcheck // MCP sampling remains supported during the SEP-2577 deprecation window.
}

TaskOptions configures the task lifecycle for tools returned by ListToolsWithTasks. The zero value uses the default lifecycle settings. Options and capability declarations are copied when tools are listed.

Jump to

Keyboard shortcuts

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