mcp

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mcp provides Model Context Protocol client and server management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadMCPTools

func LoadMCPTools(baseDir string, registry *tools.Registry) error

LoadMCPTools loads MCP server configurations from .mcp.json and registers their tools with the provided tool registry. Returns nil if .mcp.json doesn't exist (graceful skip). Returns error if config is invalid or if any server fails to initialize.

Types

type Client

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

Client represents an MCP client connected to a server via stdio

func NewClient

func NewClient(command string, args ...string) (*Client, error)

NewClient creates a new MCP client that will connect to the specified command

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (map[string]interface{}, error)

CallTool invokes a tool on the server with the given arguments

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, clientName, clientVersion, protocolVersion string) error

Initialize performs the MCP initialization handshake

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]Tool, error)

ListTools retrieves the list of available tools from the server

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown gracefully shuts down the client connection

type MCPConfig

type MCPConfig struct {
	Version string                  `json:"version"`
	Servers map[string]ServerConfig `json:"servers"`
}

MCPConfig represents the .mcp.json configuration file format

type MCPToolAdapter

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

MCPToolAdapter wraps an MCP tool to implement Jeff's Tool interface

func NewMCPToolAdapter

func NewMCPToolAdapter(client *Client, mcpTool Tool) *MCPToolAdapter

NewMCPToolAdapter creates a new adapter for an MCP tool

func (*MCPToolAdapter) AsToolDefinition

func (a *MCPToolAdapter) AsToolDefinition() core.ToolDefinition

AsToolDefinition converts the MCP tool to Jeff's ToolDefinition format This is used when registering the tool with the API

func (*MCPToolAdapter) Description

func (a *MCPToolAdapter) Description() string

Description returns the tool's human-readable description

func (*MCPToolAdapter) Execute

func (a *MCPToolAdapter) Execute(ctx context.Context, params map[string]interface{}) (*tools.Result, error)

Execute runs the MCP tool and converts the result to Jeff's Result format

func (*MCPToolAdapter) GetInputSchema

func (a *MCPToolAdapter) GetInputSchema() map[string]interface{}

GetInputSchema returns the tool's input schema

func (*MCPToolAdapter) Name

func (a *MCPToolAdapter) Name() string

Name returns the tool's unique identifier

func (*MCPToolAdapter) RequiresApproval

func (a *MCPToolAdapter) RequiresApproval(_ map[string]interface{}) bool

RequiresApproval determines if this tool execution needs user approval For MCP tools, we default to not requiring approval unless specific patterns are detected (can be enhanced later)

type MCPToolManager

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

MCPToolManager manages MCP tool adapters for a server

func NewMCPToolManager

func NewMCPToolManager(client *Client) *MCPToolManager

NewMCPToolManager creates a new tool manager for an MCP server

func (*MCPToolManager) Count

func (m *MCPToolManager) Count() int

Count returns the number of available tools

func (*MCPToolManager) GetTool

func (m *MCPToolManager) GetTool(name string) tools.Tool

GetTool returns a specific MCP tool by name

func (*MCPToolManager) GetTools

func (m *MCPToolManager) GetTools() []tools.Tool

GetTools returns all available MCP tools as Jeff tools

func (*MCPToolManager) RefreshTools

func (m *MCPToolManager) RefreshTools(ctx context.Context) error

RefreshTools fetches the latest tool list from the MCP server

type Registry

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

Registry manages MCP server configurations

func NewRegistry

func NewRegistry(baseDir string) *Registry

NewRegistry creates a new server registry

func (*Registry) AddServer

func (r *Registry) AddServer(server ServerConfig) error

AddServer adds a new server configuration

func (*Registry) ConfigPath

func (r *Registry) ConfigPath() string

ConfigPath returns the path to the .mcp.json file

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered servers

func (*Registry) GetServer

func (r *Registry) GetServer(name string) (ServerConfig, error)

GetServer retrieves a server configuration by name

func (*Registry) ListServers

func (r *Registry) ListServers() []ServerConfig

ListServers returns all registered servers

func (*Registry) Load

func (r *Registry) Load() error

Load reads the registry from .mcp.json

func (*Registry) RemoveServer

func (r *Registry) RemoveServer(name string) error

RemoveServer removes a server configuration

func (*Registry) Save

func (r *Registry) Save() error

Save persists the registry to .mcp.json

func (*Registry) ServerExists

func (r *Registry) ServerExists(name string) bool

ServerExists checks if a server with the given name exists

func (*Registry) UpdateServer

func (r *Registry) UpdateServer(server ServerConfig) error

UpdateServer updates an existing server configuration

type ServerConfig

type ServerConfig struct {
	Name      string   `json:"name"`
	Transport string   `json:"transport"`
	Command   string   `json:"command"`
	Args      []string `json:"args,omitempty"`
}

ServerConfig represents an MCP server configuration

type ServerInfo

type ServerInfo struct {
	Name         string                 `json:"name"`
	Version      string                 `json:"version"`
	Capabilities map[string]interface{} `json:"capabilities"`
}

ServerInfo contains information about the connected MCP server

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"inputSchema"`
}

Tool represents an MCP tool definition

Jump to

Keyboard shortcuts

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