Documentation
¶
Index ¶
- func ExtractTextContent(result *mcpsdk.CallToolResult) string
- func WriteMCPConfigToTempFile(servers map[string]schema.MCPServerConfig, toolchainPATH string) (string, error)
- type AuthEnvProvider
- type BridgedTool
- func (t *BridgedTool) Description() string
- func (t *BridgedTool) Execute(ctx context.Context, params map[string]interface{}) (*tools.Result, error)
- func (t *BridgedTool) IsRestricted() bool
- func (t *BridgedTool) Name() string
- func (t *BridgedTool) OriginalName() string
- func (t *BridgedTool) Parameters() []tools.Parameter
- func (t *BridgedTool) RequiresPermission() bool
- func (t *BridgedTool) ServerName() string
- type MCPJSONConfig
- type MCPJSONServer
- type Manager
- func (m *Manager) Get(name string) (*Session, error)
- func (m *Manager) List() []*Session
- func (m *Manager) Start(ctx context.Context, name string, opts ...StartOption) error
- func (m *Manager) Stop(name string) error
- func (m *Manager) StopAll() error
- func (m *Manager) Test(ctx context.Context, name string, opts ...StartOption) *TestResult
- type ParsedConfig
- type PerServerAuthProvider
- type ScopedAuthProvider
- type Session
- func (s *Session) CallTool(ctx context.Context, toolName string, args map[string]any) (*mcpsdk.CallToolResult, error)
- func (s *Session) Config() *ParsedConfig
- func (s *Session) LastError() error
- func (s *Session) Name() string
- func (s *Session) Ping(ctx context.Context) error
- func (s *Session) SetSuppressStderr(suppress bool)
- func (s *Session) Start(ctx context.Context, opts ...StartOption) error
- func (s *Session) Status() SessionStatus
- func (s *Session) Stop() error
- func (s *Session) Tools() []*mcpsdk.Tool
- type SessionStatus
- type StartOption
- type TestResult
- type ToolchainResolver
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.
func WriteMCPConfigToTempFile ¶
func WriteMCPConfigToTempFile(servers map[string]schema.MCPServerConfig, toolchainPATH string) (string, error)
WriteMCPConfigToTempFile generates an MCP config and writes it to a temp file. Returns the file path. Caller must clean up the file when done.
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 MCPJSONConfig ¶
type MCPJSONConfig struct {
MCPServers map[string]MCPJSONServer `json:"mcpServers"`
}
MCPJSONConfig represents the .mcp.json file format used by Claude Code, Codex CLI, and IDEs.
func GenerateMCPConfig ¶
func GenerateMCPConfig(servers map[string]schema.MCPServerConfig, toolchainPATH string) *MCPJSONConfig
GenerateMCPConfig builds a MCPJSONConfig from the given servers. ToolchainPATH is injected into each server's env if non-empty.
type MCPJSONServer ¶
type MCPJSONServer struct {
Command string `json:"command"`
Args []string `json:"args"`
Env map[string]string `json:"env,omitempty"`
}
MCPJSONServer represents a single MCP server entry in .mcp.json.
func BuildMCPJSONEntry ¶
func BuildMCPJSONEntry(serverCfg *schema.MCPServerConfig, toolchainPATH string) MCPJSONServer
BuildMCPJSONEntry creates a .mcp.json entry for a server. Servers with identity are wrapped with 'atmos auth exec' for credential injection. If toolchainPATH is non-empty, it is prepended to the server's PATH env var.
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) 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 PerServerAuthProvider ¶ added in v1.215.0
type PerServerAuthProvider interface {
ForServer(ctx context.Context, config *ParsedConfig) (AuthEnvProvider, error)
}
PerServerAuthProvider is an optional extension of AuthEnvProvider that returns a new AuthEnvProvider scoped to a specific server's configuration.
Implementations should apply the server's `env:` block (specifically ATMOS_* variables) before constructing the underlying auth manager so that ATMOS_PROFILE, ATMOS_CLI_CONFIG_PATH, ATMOS_BASE_PATH, etc. influence atmos config loading and identity resolution.
See ApplyAtmosEnvOverrides for the recommended env-application helper.
type ScopedAuthProvider ¶ added in v1.215.0
type ScopedAuthProvider struct {
// contains filtered or unexported fields
}
ScopedAuthProvider is a thin MCP adapter over the generic auth.CreateAndAuthenticateManagerWithEnvOverrides primitive. It implements both AuthEnvProvider and PerServerAuthProvider so WithAuthManager will dispatch through ForServer and build a server-scoped auth manager.
The actual per-server rebuild logic — applying ATMOS_* env vars, re-loading the atmos config, and constructing+authenticating the manager — lives in pkg/auth. This type only contributes the MCP-specific glue: plumbing ParsedConfig.Env into the primitive and wrapping failures with server + identity context so callers can errors.Is-match the sentinel.
MCP is the only current consumer with an N:1 need (multiple servers per invocation, each potentially loading a different atmos profile), but if another subsystem ever needs scoped auth it calls the pkg/auth primitive directly — not this adapter.
func NewScopedAuthProvider ¶ added in v1.215.0
func NewScopedAuthProvider(baseConfig *schema.AtmosConfiguration) *ScopedAuthProvider
NewScopedAuthProvider creates a ScopedAuthProvider using the given base config as future fallback context.
func (*ScopedAuthProvider) ForServer ¶ added in v1.215.0
func (p *ScopedAuthProvider) ForServer(_ context.Context, config *ParsedConfig) (AuthEnvProvider, error)
ForServer implements PerServerAuthProvider. It asks pkg/auth to construct an auth manager with the server's `env:` block applied to ATMOS_* variables.
Errors from the underlying primitive are returned as-is: pkg/auth already wraps with errUtils.ErrAuthManager, and Session.Start (the eventual caller) wraps with errUtils.ErrMCPServerStartFailed and the server name. Adding another wrap here would only duplicate context. The (nil, nil) "auth unavailable" branch is the one case the adapter must surface explicitly, because pkg/auth treats it as a normal "no manager needed" return.
PerServerAuthProvider is an exported interface, so a nil config is treated as a public-API boundary violation and surfaces a typed error instead of a panic. Internal Atmos callers always pass a non-nil config; this guard exists only for safety against future external implementations.
func (*ScopedAuthProvider) PrepareShellEnvironment ¶ added in v1.215.0
func (p *ScopedAuthProvider) PrepareShellEnvironment(ctx context.Context, identityName string, currentEnv []string) ([]string, error)
PrepareShellEnvironment satisfies AuthEnvProvider as a fallback path for callers that don't dispatch through ForServer. It builds an auth manager with no env overrides (i.e., using the parent's current environment).
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) SetSuppressStderr ¶
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.
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 ¶
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.
If authMgr also implements PerServerAuthProvider, ForServer is called first to obtain a server-scoped AuthEnvProvider. This allows the auth manager to be (re)constructed per-server with the server's `env:` block applied — so ATMOS_PROFILE, ATMOS_CLI_CONFIG_PATH, etc. influence identity resolution.
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 ¶
ToolchainResolver resolves command binary paths and provides toolchain PATH.