client

package
v1.214.0-test.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTextContent

func ExtractTextContent(result *mcpsdk.CallToolResult) string

ExtractTextContent extracts text from an MCP CallToolResult.

Types

type AuthEnvProvider

type AuthEnvProvider interface {
	PrepareShellEnvironment(ctx context.Context, identityName string, currentEnv []string) ([]string, error)
}

AuthEnvProvider is the subset of auth.AuthManager needed for MCP credential injection.

type BridgedTool

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

BridgedTool wraps an external MCP tool to implement the Atmos tools.Tool interface. It namespaces the tool name with the server name to avoid conflicts.

func BridgeTools

func BridgeTools(session *Session) []*BridgedTool

BridgeTools creates BridgedTools for all tools from a session.

func NewBridgedTool

func NewBridgedTool(serverName string, tool *mcpsdk.Tool, session *Session) *BridgedTool

NewBridgedTool creates a new BridgedTool from an MCP tool definition.

func (*BridgedTool) Description

func (t *BridgedTool) Description() string

Description returns the tool's description from the MCP server.

func (*BridgedTool) Execute

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

Execute calls the tool on the external MCP server and returns a tools.Result.

func (*BridgedTool) IsRestricted

func (t *BridgedTool) IsRestricted() bool

IsRestricted returns false.

func (*BridgedTool) Name

func (t *BridgedTool) Name() string

Name returns the namespaced tool name (e.g., "aws-eks__list_clusters"). Uses double underscore as separator and sanitizes to match AI provider requirements (Anthropic requires tool names to match ^[a-zA-Z0-9_-]{1,128}$).

func (*BridgedTool) OriginalName

func (t *BridgedTool) OriginalName() string

OriginalName returns the tool name without the server prefix.

func (*BridgedTool) Parameters

func (t *BridgedTool) Parameters() []tools.Parameter

Parameters extracts parameter definitions from the MCP tool's InputSchema.

func (*BridgedTool) RequiresPermission

func (t *BridgedTool) RequiresPermission() bool

RequiresPermission returns true — external tools require permission by default.

func (*BridgedTool) ServerName

func (t *BridgedTool) ServerName() string

ServerName returns the server name.

type Manager

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

Manager manages the lifecycle of external MCP server processes.

func NewManager

func NewManager(servers map[string]schema.MCPServerConfig) (*Manager, error)

NewManager creates a Manager from atmos configuration.

func RegisterMCPTools

func RegisterMCPTools(
	registry *tools.Registry,
	atmosConfig *schema.AtmosConfiguration,
	authProvider AuthEnvProvider,
	toolchain ToolchainResolver,
) (*Manager, error)

RegisterMCPTools starts configured MCP servers and registers their tools in the Atmos AI tool registry. Returns the Manager so the caller can stop all servers on exit.

Optional providers:

  • authProvider: injects credentials for servers with identity configured.
  • toolchain: resolves command binaries and provides toolchain PATH for prerequisites like uvx/npx that may be managed by Atmos toolchain.

Servers that fail to start are reported as errors but do not prevent other servers from registering.

func (*Manager) Get

func (m *Manager) Get(name string) (*Session, error)

Get returns a session by name.

func (*Manager) List

func (m *Manager) List() []*Session

List returns all sessions sorted by name.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, name string, opts ...StartOption) error

Start starts a specific server with optional start options (e.g., auth).

func (*Manager) Stop

func (m *Manager) Stop(name string) error

Stop stops a specific server.

func (*Manager) StopAll

func (m *Manager) StopAll() error

StopAll stops all running servers.

func (*Manager) Test

func (m *Manager) Test(ctx context.Context, name string, opts ...StartOption) *TestResult

Test tests connectivity to an MCP server by starting it, listing tools, and pinging the server.

type ParsedConfig

type ParsedConfig struct {
	Name        string
	Description string
	Command     string
	Args        []string
	Env         map[string]string
	AutoStart   bool
	Timeout     time.Duration
	Identity    string
}

ParsedConfig holds a parsed server config with resolved timeout.

func ParseConfig

func ParseConfig(name string, cfg schema.MCPServerConfig) (*ParsedConfig, error)

ParseConfig validates and converts an MCPServerConfig into a ParsedConfig.

type Session

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

Session wraps an MCP client connection to an external server.

func NewSession

func NewSession(config *ParsedConfig) *Session

NewSession creates a new session in stopped state.

func (*Session) CallTool

func (s *Session) CallTool(ctx context.Context, toolName string, args map[string]any) (*mcpsdk.CallToolResult, error)

CallTool calls a tool on the MCP server.

func (*Session) Config

func (s *Session) Config() *ParsedConfig

Config returns the parsed configuration.

func (*Session) LastError

func (s *Session) LastError() error

LastError returns the last error that occurred.

func (*Session) Name

func (s *Session) Name() string

Name returns the server name.

func (*Session) Ping

func (s *Session) Ping(ctx context.Context) error

Ping checks connectivity to the MCP server.

func (*Session) SetSuppressStderr

func (s *Session) SetSuppressStderr(suppress bool)

SetSuppressStderr controls whether subprocess stderr is forwarded to os.Stderr. When true, MCP server log output is suppressed (used during AI commands).

func (*Session) Start

func (s *Session) Start(ctx context.Context, opts ...StartOption) error

Start connects to the external MCP server subprocess. StartOptions (e.g., WithAuthManager) can modify the subprocess environment.

func (*Session) Status

func (s *Session) Status() SessionStatus

Status returns the current session status.

func (*Session) Stop

func (s *Session) Stop() error

Stop gracefully shuts down the MCP server subprocess.

func (*Session) Tools

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

Tools returns the cached list of tools from the MCP server.

type SessionStatus

type SessionStatus string

SessionStatus represents the state of an MCP client session.

const (
	// StatusStopped indicates the session is not running.
	StatusStopped SessionStatus = "stopped"
	// StatusStarting indicates the session is being initialized.
	StatusStarting SessionStatus = "starting"
	// StatusRunning indicates the session is connected and ready.
	StatusRunning SessionStatus = "running"
	// StatusError indicates the session failed to start or lost connection.
	StatusError SessionStatus = "error"
)

type StartOption

type StartOption func(ctx context.Context, config *ParsedConfig, env []string) ([]string, error)

StartOption is a function that modifies the subprocess environment before starting.

func WithAuthManager

func WithAuthManager(authMgr AuthEnvProvider) StartOption

WithAuthManager returns a StartOption that injects auth credentials when the server has identity configured.

func WithToolchain

func WithToolchain(resolver ToolchainResolver) StartOption

WithToolchain returns a StartOption that resolves the MCP server command binary via the Atmos toolchain and prepends toolchain PATH to the subprocess environment. This ensures prerequisites like uvx/npx are available even if not on the system PATH.

type TestResult

type TestResult struct {
	ServerStarted bool
	Initialized   bool
	ToolCount     int
	PingOK        bool
	Error         error
}

TestResult contains the results of testing an MCP server.

type ToolchainResolver

type ToolchainResolver interface {
	Resolve(command string) string
	EnvVars() []string
}

ToolchainResolver resolves command binary paths and provides toolchain PATH.

Jump to

Keyboard shortcuts

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