mcp

package
v0.0.0-...-05e9f27 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotConnected indicates the MCP server has no active session.
	ErrNotConnected = errors.New("mcp server not connected")
	// ErrTransportRequired indicates no transport was configured.
	ErrTransportRequired = errors.New("mcp transport required")
)

Functions

This section is empty.

Types

type Builder

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

Builder provides a fluent API for connecting to MCP servers.

func NewBuilder

func NewBuilder(engine engineRef, name string) *Builder

NewBuilder creates an MCP builder for the given server name.

func (*Builder) AllowTools

func (b *Builder) AllowTools(names ...string) *Builder

AllowTools limits exposure to the provided tool names.

func (*Builder) AutoRefresh

func (b *Builder) AutoRefresh(enabled bool) *Builder

AutoRefresh toggles tool refresh on tool list changed notifications.

func (*Builder) ClientOptions

func (b *Builder) ClientOptions(opts sdkmcp.ClientOptions) *Builder

ClientOptions overrides MCP client options.

func (*Builder) Command

func (b *Builder) Command(path string, args ...string) *Builder

Command configures a command transport.

func (*Builder) CommandExec

func (b *Builder) CommandExec(cmd *exec.Cmd) *Builder

CommandExec uses a preconfigured exec.Cmd for the command transport.

func (*Builder) Connect

func (b *Builder) Connect(ctx context.Context) (*Server, error)

Connect establishes a connection to the MCP server.

func (*Builder) DenyTools

func (b *Builder) DenyTools(names ...string) *Builder

DenyTools blocks the provided tool names.

func (*Builder) Dir

func (b *Builder) Dir(dir string) *Builder

Dir sets the working directory for command transports.

func (*Builder) Env

func (b *Builder) Env(key, value string) *Builder

Env sets an environment variable for command transports.

func (*Builder) Filter

func (b *Builder) Filter(filter ToolFilter) *Builder

Filter applies a custom tool filter.

func (*Builder) HTTPClient

func (b *Builder) HTTPClient(client *http.Client) *Builder

HTTPClient sets the HTTP client used by HTTP-based transports.

func (*Builder) Header

func (b *Builder) Header(key, value string) *Builder

Header adds a header to HTTP-based transports.

func (*Builder) Headers

func (b *Builder) Headers(headers http.Header) *Builder

Headers adds multiple headers to HTTP-based transports.

func (*Builder) IO

func (b *Builder) IO(reader io.ReadCloser, writer io.WriteCloser) *Builder

IO configures an IO transport using explicit reader/writer streams.

func (*Builder) Implementation

func (b *Builder) Implementation(name, version string) *Builder

Implementation sets the MCP client implementation name and version.

func (*Builder) KeepAlive

func (b *Builder) KeepAlive(interval time.Duration) *Builder

KeepAlive configures periodic client pinging.

func (*Builder) Prefix

func (b *Builder) Prefix(prefix string) *Builder

Prefix sets the tool ID prefix used for MCP tools.

func (*Builder) Register

func (b *Builder) Register(ctx context.Context) (*Server, error)

Register connects to the server, loads tools, and registers them with the tool registry.

func (*Builder) RegisterTo

func (b *Builder) RegisterTo(reg *tool.Registry) *Builder

RegisterTo sets the tool registry to register remote tools into.

func (*Builder) SSE

func (b *Builder) SSE(endpoint string) *Builder

SSE configures the legacy SSE transport.

func (*Builder) SessionOptions

func (b *Builder) SessionOptions(opts *sdkmcp.ClientSessionOptions) *Builder

SessionOptions sets MCP session options.

func (*Builder) Streamable

func (b *Builder) Streamable(endpoint string) *Builder

Streamable configures a streamable HTTP transport.

func (*Builder) StreamableRetries

func (b *Builder) StreamableRetries(max int) *Builder

StreamableRetries sets the max retries for streamable HTTP transports.

func (*Builder) TerminateAfter

func (b *Builder) TerminateAfter(duration time.Duration) *Builder

TerminateAfter controls how long to wait before SIGTERM when closing a command transport.

func (*Builder) ToolID

func (b *Builder) ToolID(fn ToolIDFunc) *Builder

ToolID maps MCP tool names to local tool IDs.

func (*Builder) Transport

func (b *Builder) Transport(t sdkmcp.Transport) *Builder

Transport sets a custom MCP transport.

type ProxyTool

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

ProxyTool exposes a remote MCP tool as a local tool.Tool.

func (*ProxyTool) Description

func (p *ProxyTool) Description() string

Description returns a human-readable tool description when available.

func (*ProxyTool) ID

func (p *ProxyTool) ID() string

ID returns the tool ID.

func (*ProxyTool) Run

func (p *ProxyTool) Run(ctx context.Context, call tool.Call, _ tool.Emitter) (tool.Result, error)

Run executes the remote tool via MCP.

func (*ProxyTool) Schema

func (p *ProxyTool) Schema() tool.Schema

Schema returns the tool schema.

type Registry

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

Registry stores MCP server connections by name.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new MCP registry.

func (*Registry) CloseAll

func (r *Registry) CloseAll() error

CloseAll closes all registered servers.

func (*Registry) Get

func (r *Registry) Get(name string) (*Server, bool)

Get returns a server by name.

func (*Registry) List

func (r *Registry) List() []string

List returns registered server names.

func (*Registry) Register

func (r *Registry) Register(server *Server)

Register stores a server by name.

type Server

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

Server represents a connected MCP server and its exposed tools.

func (*Server) CallTool

func (s *Server) CallTool(ctx context.Context, name string, args json.RawMessage) (*sdkmcp.CallToolResult, error)

CallTool calls a remote tool by name.

func (*Server) Client

func (s *Server) Client() *sdkmcp.Client

Client returns the underlying MCP client.

func (*Server) Close

func (s *Server) Close() error

Close closes the MCP session.

func (*Server) Connect

func (s *Server) Connect(ctx context.Context) error

Connect establishes the MCP session if not already connected.

func (*Server) Name

func (s *Server) Name() string

Name returns the server name.

func (*Server) Prefix

func (s *Server) Prefix() string

Prefix returns the tool ID prefix.

func (*Server) Refresh

func (s *Server) Refresh(ctx context.Context) error

Refresh re-fetches tools from the MCP server and updates proxies.

func (*Server) RegisterTools

func (s *Server) RegisterTools(reg *tool.Registry)

RegisterTools registers the MCP tools into the provided registry and stores it for refresh.

func (*Server) Session

func (s *Server) Session() *sdkmcp.ClientSession

Session returns the underlying MCP client session.

func (*Server) ToolID

func (s *Server) ToolID(toolName string) string

ToolID returns the local tool ID for an MCP tool name.

func (*Server) ToolIDs

func (s *Server) ToolIDs() []string

ToolIDs returns the registered tool IDs.

func (*Server) Tools

func (s *Server) Tools() []*ProxyTool

Tools returns the proxy tools.

type ToolFilter

type ToolFilter func(*sdkmcp.Tool) bool

ToolFilter decides whether a tool should be exposed.

type ToolIDFunc

type ToolIDFunc func(serverName, toolName string) string

ToolIDFunc maps an MCP tool name to a local tool ID.

type Toolkit

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

Toolkit wraps an MCP server as a toolkit.

func NewToolkit

func NewToolkit(id string, server *Server) *Toolkit

NewToolkit creates a toolkit for an MCP server.

func (*Toolkit) BindRegistry

func (t *Toolkit) BindRegistry(reg *tool.Registry)

BindRegistry binds the toolkit to a registry for refresh updates.

func (*Toolkit) DefaultToolIDs

func (t *Toolkit) DefaultToolIDs() []string

DefaultToolIDs returns MCP tool IDs.

func (*Toolkit) ID

func (t *Toolkit) ID() string

ID returns the toolkit ID.

func (*Toolkit) Tools

func (t *Toolkit) Tools(ctx context.Context) ([]tool.Tool, error)

Tools returns MCP proxy tools.

Jump to

Keyboard shortcuts

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