mcp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandEnv

func ExpandEnv(env map[string]string) []string

ExpandEnv converts a map of env vars to KEY=VALUE format, expanding ${VAR} references from the OS environment. The result is appended to the current process environment.

func ExpandHeaders

func ExpandHeaders(headers map[string]string) map[string]string

ExpandHeaders expands ${VAR} in header values.

func LoadAllMCPServers

func LoadAllMCPServers(cwd string) map[string]ServerConfig

LoadAllMCPServers merges MCP server configs from global (~/.codebot/settings.json) and project (<cwd>/.codebot/settings.json). Project-level overrides global.

Types

type Client

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

Client wraps a single MCP server connection.

func Connect

func Connect(ctx context.Context, name string, cfg ServerConfig, onChange func()) (*Client, error)

Connect establishes an MCP connection using the transport specified in cfg. onChange is called when the server sends a tools/list_changed notification.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (*protocol.CallToolResult, error)

CallTool invokes a tool on the server.

func (*Client) Close

func (c *Client) Close() error

Close terminates the MCP session and server process.

func (*Client) Instructions

func (c *Client) Instructions() string

Instructions returns server instructions from the initialize result, if any.

func (*Client) ListTools

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

ListTools fetches the tool list from the server.

func (*Client) Name

func (c *Client) Name() string

Name returns the server name.

type MCPTool

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

MCPTool adapts an MCP server tool to the agentcore.Tool interface.

func NewMCPTool

func NewMCPTool(client *Client, tool protocol.Tool) *MCPTool

NewMCPTool creates an adapter from an MCP tool definition.

func (*MCPTool) ApprovalMetadata added in v0.0.4

func (t *MCPTool) ApprovalMetadata() approval.ToolMetadata

func (*MCPTool) Description

func (t *MCPTool) Description() string

func (*MCPTool) Execute

func (t *MCPTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

Execute calls the MCP tool and converts the result to JSON.

func (*MCPTool) Label

func (t *MCPTool) Label() string

func (*MCPTool) Name

func (t *MCPTool) Name() string

func (*MCPTool) Schema

func (t *MCPTool) Schema() map[string]any

Schema converts the MCP tool's InputSchema to the map[string]any format expected by agentcore.

type Manager

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

Manager manages the lifecycle of multiple MCP server connections.

func NewManager

func NewManager() *Manager

NewManager creates an empty Manager.

func (*Manager) Close

func (m *Manager) Close()

Close terminates all MCP server connections.

func (*Manager) Instructions

func (m *Manager) Instructions() []string

Instructions collects server instructions from all connected servers.

func (*Manager) MarkDirty added in v0.0.3

func (m *Manager) MarkDirty()

MarkDirty forces the dirty flag so that the next RefreshIfDirty call triggers a tool reload. Used after initial async connection completes.

func (*Manager) RefreshIfDirty

func (m *Manager) RefreshIfDirty(ctx context.Context) ([]agentcore.Tool, bool)

RefreshIfDirty re-fetches tools from all servers if any sent a list_changed notification since the last call. Returns the new tool list and true, or nil and false if nothing changed. Safe to call from the main loop.

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context, servers map[string]ServerConfig) []error

StartAll connects to all configured MCP servers in parallel. Partial failures are collected; successful servers remain active.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) []ServerStatus

Status returns the status of all MCP servers, including failed ones. ListTools calls run in parallel with per-server timeout; the mutex is not held during network I/O.

func (*Manager) Tools

func (m *Manager) Tools(ctx context.Context) []agentcore.Tool

Tools returns all MCP tools from connected servers as agentcore.Tool adapters.

type ServerConfig

type ServerConfig struct {
	Type    string            `json:"type,omitempty"` // "stdio" (default) or "http"
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

ServerConfig describes a single MCP server connection.

Stdio example (default):

{"command": "npx", "args": ["-y", "@upstash/context7-mcp"], "env": {"KEY": "${VAR}"}}

HTTP example:

{"type": "http", "url": "https://mcp.example.com/mcp", "headers": {"Authorization": "Bearer ${TOKEN}"}}

type ServerStatus

type ServerStatus struct {
	Name      string
	ToolCount int
	Error     string // non-empty if connection failed
	ListError string // non-empty if connected but ListTools failed
}

ServerStatus describes a connected or failed MCP server.

Jump to

Keyboard shortcuts

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