mcp

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mcp implements a client for the Model Context Protocol. It supports connecting to MCP servers via stdio (subprocess) transport, discovering tools, and invoking them on behalf of the primary model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCPClient

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

MCPClient manages connections to one or more MCP servers.

func NewMCPClient

func NewMCPClient(configs []config.MCPServerConfig) *MCPClient

NewMCPClient creates a new MCP client from the given server configurations. No connections are made until Connect is called.

func (*MCPClient) CallTool

func (c *MCPClient) CallTool(_ context.Context, serverName, toolName string, args json.RawMessage) (string, error)

CallTool invokes a tool on the specified MCP server and returns the text result.

func (*MCPClient) Close

func (c *MCPClient) Close() error

Close shuts down all MCP server connections.

func (*MCPClient) Connect

func (c *MCPClient) Connect(ctx context.Context) error

Connect starts all configured MCP servers and discovers their tools.

func (*MCPClient) ToToolDefinitions

func (c *MCPClient) ToToolDefinitions() []provider.ToolDefinition

ToToolDefinitions converts discovered MCP tools to provider.ToolDefinition format so they can be sent to the primary model alongside built-in tools. Tool names are prefixed with "mcp_{serverName}_" to avoid collisions.

func (*MCPClient) Tools

func (c *MCPClient) Tools() []MCPTool

Tools returns all tools discovered from connected MCP servers.

type MCPTool

type MCPTool struct {
	Name        string
	Description string
	InputSchema map[string]any
	ServerName  string // which server provides this tool
}

MCPTool represents a tool discovered from an MCP server.

Jump to

Keyboard shortcuts

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