mcp

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mcp provides Model Context Protocol client connections and tool registration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractServer

func ExtractServer(name string) (server, shortName string, ok bool)

ExtractServer parses an MCP tool name (mcp__server__tool) and returns the server name and short tool name. Returns ok=false for non-MCP names.

func MakeName

func MakeName(server, tool string) string

MakeName constructs a prefixed MCP tool name from server and tool names.

Types

type Result

type Result struct {
	Name    string   // Server name
	Session *Session // non-nil on success
	Error   error    // non-nil on failure
}

Result holds the outcome of connecting to a single MCP server.

func ConnectAll

func ConnectAll(ctx context.Context, servers map[string]Server, progress func(name string)) []Result

ConnectAll connects to multiple MCP servers in parallel. progress is called (if non-nil) when each server connection starts. Returns a result for every server (both successes and failures).

func (Result) StatusDisplay

func (r Result) StatusDisplay() string

StatusDisplay returns a formatted connection status string.

func (Result) ToolNames

func (r Result) ToolNames() []string

ToolNames returns the prefixed tool names from a successful connection. Returns nil if the connection failed.

type Server

type Server struct {
	Disabled  bool              `yaml:"disabled"`                                   // true = skip connection (default false = enabled)
	Deferred  bool              `yaml:"deferred"`                                   // true = all tools from this server are deferred
	Type      string            `yaml:"type" validate:"omitempty,oneof=http stdio"` // "http" or "stdio"
	URL       string            `yaml:"url"`                                        // For HTTP transport
	Command   string            `yaml:"command"`                                    // For STDIO transport
	Args      []string          `yaml:"args"`                                       // For STDIO transport
	Env       env.Env           `yaml:"env"`                                        // Environment variables
	Headers   map[string]string `yaml:"headers"`                                    // For HTTP transport
	Timeout   time.Duration     `yaml:"timeout"`                                    // Connection timeout
	Condition string            `yaml:"condition"`                                  // condition expression for conditional inclusion
	Source    string            `yaml:"-"`                                          // file path this server was loaded from
}

Server represents an MCP server configuration.

func (Server) Connect

func (s Server) Connect(ctx context.Context) (client.MCPClient, error)

Connect creates and initializes an MCP client session.

func (Server) Display

func (s Server) Display() string

Display returns a human-readable summary of the server's connection target. For HTTP: the URL. For STDIO: command + args.

func (Server) EffectiveType

func (s Server) EffectiveType() string

EffectiveType returns the transport type, defaulting to "stdio".

func (Server) Expanded

func (s Server) Expanded() Server

Expanded returns a copy with environment variables expanded.

func (Server) IsEnabled

func (s Server) IsEnabled() bool

IsEnabled reports whether this server should be connected at startup.

type Session

type Session struct {
	Name     string           // Server name for tool prefixing
	Client   client.MCPClient // Active MCP client
	MCPTools []mcplib.Tool    // Discovered MCP tools
}

Session represents a connected MCP server session.

func NewSession

func NewSession(ctx context.Context, name string, server Server) (*Session, error)

NewSession connects to a server and discovers its tools.

func (*Session) Close

func (s *Session) Close() error

Close disconnects the MCP client.

func (*Session) Tools

func (s *Session) Tools() []*Tool

Tools returns wrapped MCP tools implementing tool.Tool interface.

type Tool

type Tool struct {
	tool.Base
	// contains filtered or unexported fields
}

Tool wraps an MCP tool to implement the tool.Tool interface.

func NewTool

func NewTool(serverName string, mcpTool mcplib.Tool, client client.MCPClient) *Tool

NewTool creates a Tool wrapper.

func (*Tool) Description

func (t *Tool) Description() string

Description returns the MCP tool's description.

func (*Tool) Examples

func (t *Tool) Examples() string

Examples returns empty string (MCP tools don't provide examples).

func (*Tool) Execute

func (t *Tool) Execute(ctx context.Context, args map[string]any) (string, error)

Execute calls the MCP tool on the remote server.

func (*Tool) Name

func (t *Tool) Name() string

Name returns the prefixed tool name.

func (*Tool) Sandboxable

func (t *Tool) Sandboxable() bool

Sandboxable returns false because MCP tools execute on remote servers.

func (*Tool) Schema

func (t *Tool) Schema() tool.Schema

Schema converts MCP schema to tool.Schema.

func (*Tool) Usage

func (t *Tool) Usage() string

Usage returns usage instructions.

Jump to

Keyboard shortcuts

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