Documentation
¶
Overview ¶
Package mcp provides secret management for MCP server environment variables. It handles detecting, storing, and resolving sensitive environment variables using the credentials backend for secure storage.
Index ¶
- Constants
- func BuildFullEnvForServer(serverName string, config *MCPServerConfig) (map[string]string, error)
- func CredentialKey(serverName, envVarName string) string
- func FormatForLLM(err *InvalidArgsError) string
- func GetMCPValidationFailures() int64
- func IsGitHubMCPConfigured(config MCPConfig) bool
- func IsSecretEnvVar(name string) bool
- func IsSecretRef(value string) bool
- func MarshalJSONWithRedaction(config MCPConfig) ([]byte, error)
- func MaskEnvValue(value string) string
- func MaskEnvVars(env map[string]string) map[string]string
- func MigrateEnvSecrets(serverName string, env map[string]string) (map[string]string, int, error)
- func MigrateEnvSecretsFromServer(serverName string, config *MCPServerConfig) (int, error)
- func MigrateSecretsToCredentialsField(serverName string, config *MCPServerConfig) (int, error)
- func ParseSecretRef(value string) (serverName, envVarName string, ok bool)
- func ResolveCredentialsForServer(serverName string, config *MCPServerConfig) (map[string]string, error)
- func ResolveEnvVars(serverName string, env map[string]string) (map[string]string, error)
- func SaveGitHubMCPServer(config *MCPServerConfig) error
- func SaveMCPConfig(mcpConfig *MCPConfig) error
- func SecretRef(serverName, envVarName string) string
- func ShouldPromptGitHubSetup(workingDir string, cfg MCPConfig, dismissedPrompts map[string]bool) bool
- type AgentTool
- type DefaultMCPManager
- func (m *DefaultMCPManager) AddServer(config MCPServerConfig) error
- func (m *DefaultMCPManager) AutoDiscoverGitHubServer(ctx context.Context) error
- func (m *DefaultMCPManager) CallTool(ctx context.Context, serverName, toolName string, args map[string]interface{}) (*MCPToolCallResult, error)
- func (m *DefaultMCPManager) GetAllTools(ctx context.Context) ([]MCPTool, error)
- func (m *DefaultMCPManager) GetServer(name string) (MCPServer, bool)
- func (m *DefaultMCPManager) GetServerStats() map[string]interface{}
- func (m *DefaultMCPManager) ListServers() []MCPServer
- func (m *DefaultMCPManager) RemoveServer(name string) error
- func (m *DefaultMCPManager) StartAll(ctx context.Context) error
- func (m *DefaultMCPManager) StopAll(ctx context.Context) error
- type EnvVarTemplate
- type GitHubRepoInfo
- type InvalidArgsError
- type MCPClient
- func (c *MCPClient) CallTool(ctx context.Context, request MCPToolCallRequest) (*MCPToolCallResult, error)
- func (c *MCPClient) GetConfig() MCPServerConfig
- func (c *MCPClient) GetName() string
- func (c *MCPClient) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*MCPContent, error)
- func (c *MCPClient) GetRestartCount() int
- func (c *MCPClient) Initialize(ctx context.Context) error
- func (c *MCPClient) IsDisabled() bool
- func (c *MCPClient) IsRunning() bool
- func (c *MCPClient) ListPrompts(ctx context.Context) ([]MCPPrompt, error)
- func (c *MCPClient) ListResources(ctx context.Context) ([]MCPResource, error)
- func (c *MCPClient) ListTools(ctx context.Context) ([]MCPTool, error)
- func (c *MCPClient) ReadResource(ctx context.Context, uri string) (*MCPContent, error)
- func (c *MCPClient) Start(ctx context.Context) error
- func (c *MCPClient) Stop(ctx context.Context) error
- type MCPConfig
- func (c *MCPConfig) AddGitHubServer(githubToken string)
- func (c *MCPConfig) AddServer(serverConfig MCPServerConfig) error
- func (c *MCPConfig) GetConfigSummary() map[string]interface{}
- func (c *MCPConfig) GetEnabledServers() []MCPServerConfig
- func (c *MCPConfig) HasGitHubToken() bool
- func (c *MCPConfig) RemoveServer(name string)
- func (c *MCPConfig) UnmarshalJSON(data []byte) error
- func (c *MCPConfig) ValidateConfig() error
- type MCPContent
- type MCPError
- type MCPHTTPClient
- func (c *MCPHTTPClient) CallTool(ctx context.Context, request MCPToolCallRequest) (*MCPToolCallResult, error)
- func (c *MCPHTTPClient) GetConfig() MCPServerConfig
- func (c *MCPHTTPClient) GetName() string
- func (c *MCPHTTPClient) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*MCPContent, error)
- func (c *MCPHTTPClient) Initialize(ctx context.Context) error
- func (c *MCPHTTPClient) IsRunning() bool
- func (c *MCPHTTPClient) ListPrompts(ctx context.Context) ([]MCPPrompt, error)
- func (c *MCPHTTPClient) ListResources(ctx context.Context) ([]MCPResource, error)
- func (c *MCPHTTPClient) ListTools(ctx context.Context) ([]MCPTool, error)
- func (c *MCPHTTPClient) ReadResource(ctx context.Context, uri string) (*MCPContent, error)
- func (c *MCPHTTPClient) Start(ctx context.Context) error
- func (c *MCPHTTPClient) Stop(ctx context.Context) error
- type MCPManager
- type MCPMessage
- type MCPPrompt
- type MCPPromptArgument
- type MCPResource
- type MCPServer
- type MCPServerConfig
- type MCPServerRegistry
- func (r *MCPServerRegistry) AddTemplate(template MCPServerTemplate) error
- func (r *MCPServerRegistry) GetTemplate(id string) (MCPServerTemplate, bool)
- func (r *MCPServerRegistry) GetTemplatesByType(serverType string) []MCPServerTemplate
- func (r *MCPServerRegistry) ListTemplates() []MCPServerTemplate
- func (r *MCPServerRegistry) SearchTemplates(query string) []MCPServerTemplate
- type MCPServerTemplate
- type MCPTemplatesConfig
- type MCPTool
- type MCPToolCallRequest
- type MCPToolCallResult
- type MCPToolWrapper
- func (w *MCPToolWrapper) CanExecute(ctx context.Context, params Parameters) bool
- func (w *MCPToolWrapper) Category() string
- func (w *MCPToolWrapper) Description() string
- func (w *MCPToolWrapper) EstimatedDuration() time.Duration
- func (w *MCPToolWrapper) Execute(ctx context.Context, params Parameters) (*Result, error)
- func (w *MCPToolWrapper) GetMCPTool() MCPTool
- func (w *MCPToolWrapper) GetServerName() string
- func (w *MCPToolWrapper) GetToolName() string
- func (w *MCPToolWrapper) IsAvailable() bool
- func (w *MCPToolWrapper) Name() string
- func (w *MCPToolWrapper) RequiredPermissions() []string
- func (w *MCPToolWrapper) SetAvailable(available bool)
- func (w *MCPToolWrapper) SetCategory(category string)
- func (w *MCPToolWrapper) SetTimeout(timeout time.Duration)
- func (w *MCPToolWrapper) ToAgentTool() AgentTool
- func (w *MCPToolWrapper) ValidateArgs(args map[string]interface{}) error
- type Parameters
- type Result
- type ValidationFailure
Constants ¶
const ( CategoryWeb = "web" PermissionNetworkAccess = "network_access" )
Local constants to avoid importing tools package and creating cycle
const ( ErrorCodeParse = -32700 ErrorCodeInvalidRequest = -32600 ErrorCodeMethodNotFound = -32601 ErrorCodeInvalidParams = -32602 ErrorCodeInternalError = -32603 )
Standard error codes
Variables ¶
This section is empty.
Functions ¶
func BuildFullEnvForServer ¶
func BuildFullEnvForServer(serverName string, config *MCPServerConfig) (map[string]string, error)
BuildFullEnvForServer combines non-secret Env vars with resolved credentials. Returns the complete environment map to use when starting the MCP server. It resolves both the Credentials map and any placeholder refs that remain in Env (e.g. when MigrateEnvSecretsFromServer was called but MigrateSecretsToCredentialsField has not yet moved the placeholders from Env to Credentials).
func CredentialKey ¶
CredentialKey returns the credential store key for an MCP server's environment variable. Format: "mcp/{server}/{envvar}"
func FormatForLLM ¶
func FormatForLLM(err *InvalidArgsError) string
FormatForLLM returns a structured, LLM-friendly message that enumerates failing field paths and human-readable reasons. This is designed to be used as the tool result so the model can self-correct on the next iteration.
func GetMCPValidationFailures ¶
func GetMCPValidationFailures() int64
GetMCPValidationFailures returns the total count of MCP argument validation failures since process start. Useful for monitoring if a particular server is producing bad arguments at rate (cross-reference with structured logs).
func IsGitHubMCPConfigured ¶
IsGitHubMCPConfigured checks if a GitHub MCP server is already configured in the given MCPConfig.
func IsSecretEnvVar ¶
IsSecretEnvVar returns true if the env var name looks like it contains credentials. It checks for common secret keywords and excludes known non-secret prefixes.
func IsSecretRef ¶
IsSecretRef returns true if the value matches the credential placeholder pattern.
func MarshalJSONWithRedaction ¶
MarshalJSONWithRedaction marshals the MCP config to JSON with all credentials redacted. This is a convenience function that combines RedactMCPConfig with json.MarshalIndent.
func MaskEnvValue ¶
MaskEnvValue returns a masked version of a value for safe display. Secrets are shown as first 4 chars + "****", placeholders show as "{{stored}}".
func MaskEnvVars ¶
MaskEnvVars returns a copy of the env map with secret values masked. Values that are credential placeholders are shown as "{{stored}}", and values that look like secrets (per IsSecretEnvVar) are masked.
func MigrateEnvSecrets ¶
MigrateEnvSecrets detects plaintext secrets in an environment map and migrates them to the credential store, replacing them with placeholders. Returns the updated map and count of migrated secrets.
The migration is two-phase: all secrets are stored in the credential backend first; only if all writes succeed is the returned map updated with placeholder values.
func MigrateEnvSecretsFromServer ¶
func MigrateEnvSecretsFromServer(serverName string, config *MCPServerConfig) (int, error)
MigrateEnvSecretsFromServer migrates plaintext secrets in an MCPServerConfig's Env map to the credential store, replacing values with placeholders. Returns the count of migrated secrets and any error.
The migration attempts to be atomic: all secrets are collected first and stored in the credential backend before any config.Env values are mutated. If any store fails, the config.Env map is left untouched.
func MigrateSecretsToCredentialsField ¶
func MigrateSecretsToCredentialsField(serverName string, config *MCPServerConfig) (int, error)
MigrateSecretsToCredentialsField migrates secrets from the Env map to the Credentials field. This is a one-time migration for existing configs that used Env for secrets. Returns the count of migrated secrets and any error.
The migration: 1. Reads all secrets from config.Env (which may contain plaintext or placeholders) 2. Stores them in the credential backend (if not already stored) 3. Removes them from config.Env 4. Adds them to config.Credentials with placeholder values
func ParseSecretRef ¶
ParseSecretRef parses a credential placeholder and returns its components. The value between "{{credential:" and "}}" is split on "/" - first part is ignored ("mcp"), second is server name, third is env var name.
func ResolveCredentialsForServer ¶
func ResolveCredentialsForServer(serverName string, config *MCPServerConfig) (map[string]string, error)
ResolveCredentialsForServer resolves all credential placeholders for a server and returns a map of env var name -> actual value. This is used when starting an MCP server to build the full environment.
func ResolveEnvVars ¶
ResolveEnvVars resolves credential placeholders in an environment map. For each entry: - If it's a placeholder, resolve it from the credential store - If the credential store has an empty value, fall back to os.Getenv() - Non-placeholder values pass through unchanged
func SaveGitHubMCPServer ¶
func SaveGitHubMCPServer(config *MCPServerConfig) error
SaveGitHubMCPServer loads the current MCP config, adds/replaces the github server entry, and persists it via SaveMCPConfig.
func SaveMCPConfig ¶
SaveMCPConfig saves MCP configuration to file
func SecretRef ¶
SecretRef returns the placeholder string for a credential reference. Format: "{{credential:mcp/{server}/{envvar}}}"
func ShouldPromptGitHubSetup ¶
func ShouldPromptGitHubSetup(workingDir string, cfg MCPConfig, dismissedPrompts map[string]bool) bool
ShouldPromptGitHubSetup returns true if we should prompt the user about GitHub MCP setup. Returns false if already configured, the prompt was previously dismissed, or the working directory is not a GitHub repo.
Types ¶
type AgentTool ¶
type AgentTool struct {
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters interface{} `json:"parameters"`
} `json:"function"`
}
AgentTool represents the agent's tool format for compatibility
type DefaultMCPManager ¶
type DefaultMCPManager struct {
// contains filtered or unexported fields
}
DefaultMCPManager implements the MCPManager interface
func NewMCPManager ¶
func NewMCPManager(logger *utils.Logger) *DefaultMCPManager
NewMCPManager creates a new MCP manager
func (*DefaultMCPManager) AddServer ¶
func (m *DefaultMCPManager) AddServer(config MCPServerConfig) error
AddServer adds a new MCP server
func (*DefaultMCPManager) AutoDiscoverGitHubServer ¶
func (m *DefaultMCPManager) AutoDiscoverGitHubServer(ctx context.Context) error
AutoDiscoverTools attempts to discover and start GitHub MCP server automatically
func (*DefaultMCPManager) CallTool ¶
func (m *DefaultMCPManager) CallTool(ctx context.Context, serverName, toolName string, args map[string]interface{}) (*MCPToolCallResult, error)
CallTool calls a tool on the appropriate server
func (*DefaultMCPManager) GetAllTools ¶
func (m *DefaultMCPManager) GetAllTools(ctx context.Context) ([]MCPTool, error)
GetAllTools gets all tools from all running servers
func (*DefaultMCPManager) GetServer ¶
func (m *DefaultMCPManager) GetServer(name string) (MCPServer, bool)
GetServer gets an MCP server by name
func (*DefaultMCPManager) GetServerStats ¶
func (m *DefaultMCPManager) GetServerStats() map[string]interface{}
GetServerStats returns statistics about all servers
func (*DefaultMCPManager) ListServers ¶
func (m *DefaultMCPManager) ListServers() []MCPServer
ListServers lists all registered servers
func (*DefaultMCPManager) RemoveServer ¶
func (m *DefaultMCPManager) RemoveServer(name string) error
RemoveServer removes an MCP server
type EnvVarTemplate ¶
type EnvVarTemplate struct {
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required"`
Secret bool `json:"secret"`
Default string `json:"default"`
}
EnvVarTemplate represents a required environment variable
type GitHubRepoInfo ¶
type GitHubRepoInfo struct {
Owner string // GitHub owner/organisation
Repo string // Repository name
URL string // Full HTTPS URL, e.g. https://github.com/owner/repo
}
GitHubRepoInfo holds information about a detected GitHub repository.
func DetectGitHubRepo ¶
func DetectGitHubRepo(workingDir string) *GitHubRepoInfo
DetectGitHubRepo checks if the current working directory is inside a git repo with a GitHub remote. Returns nil if not a GitHub repo.
type InvalidArgsError ¶
type InvalidArgsError struct {
// Tool is the name of the tool that failed validation
Tool string
// Server is the MCP server name hosting the tool
Server string
// Failures contains the individual validation errors
Failures []ValidationFailure
// contains filtered or unexported fields
}
InvalidArgsError is returned when tool arguments fail JSON Schema validation. It contains structured validation failures that can be formatted for LLM consumption.
func (*InvalidArgsError) Error ¶
func (e *InvalidArgsError) Error() string
Error returns a concise, LLM-friendly validation error message enumerating field paths and reasons instead of raw jsonschema output. This format enables the model to self-correct on the next iteration.
func (*InvalidArgsError) Unwrap ¶
func (e *InvalidArgsError) Unwrap() error
Unwrap returns the underlying error for errors.Is/errors.As compatibility.
type MCPClient ¶
type MCPClient struct {
// contains filtered or unexported fields
}
MCPClient implements the MCPServer interface for subprocess-based MCP servers
func NewMCPClient ¶
func NewMCPClient(config MCPServerConfig, logger *utils.Logger) *MCPClient
NewMCPClient creates a new MCP client for a server
func (*MCPClient) CallTool ¶
func (c *MCPClient) CallTool(ctx context.Context, request MCPToolCallRequest) (*MCPToolCallResult, error)
CallTool calls a tool on the server
func (*MCPClient) GetConfig ¶
func (c *MCPClient) GetConfig() MCPServerConfig
GetConfig returns the server configuration
func (*MCPClient) GetPrompt ¶
func (c *MCPClient) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*MCPContent, error)
GetPrompt gets a prompt from the server
func (*MCPClient) GetRestartCount ¶
GetRestartCount returns how many times the underlying server has been started (including manual Start calls and reconnects). Safe for concurrent reads — startInternal increments under c.mutex.
func (*MCPClient) Initialize ¶
Initialize sends initialize request to server
func (*MCPClient) IsDisabled ¶
IsDisabled checks if the server has been disabled due to excessive failures
func (*MCPClient) ListPrompts ¶
ListPrompts lists available prompts from the server
func (*MCPClient) ListResources ¶
func (c *MCPClient) ListResources(ctx context.Context) ([]MCPResource, error)
ListResources lists available resources from the server
func (*MCPClient) ReadResource ¶
ReadResource reads a resource from the server
type MCPConfig ¶
type MCPConfig struct {
Enabled bool `json:"enabled"`
Servers map[string]MCPServerConfig `json:"servers"`
AutoStart bool `json:"auto_start"`
AutoDiscover bool `json:"auto_discover"`
Timeout time.Duration `json:"timeout"`
}
MCPConfig represents the MCP configuration
func DefaultMCPConfig ¶
func DefaultMCPConfig() MCPConfig
DefaultMCPConfig returns the default MCP configuration
func LoadMCPConfig ¶
LoadMCPConfig loads MCP configuration from file
func RedactMCPConfig ¶
RedactMCPConfig returns a copy of the MCP config with all server credentials redacted. This is used for diagnostic output, config exports, and any other display paths where credential values should not be exposed.
func (*MCPConfig) AddGitHubServer ¶
AddGitHubServer adds a GitHub MCP server to the configuration
func (*MCPConfig) AddServer ¶
func (c *MCPConfig) AddServer(serverConfig MCPServerConfig) error
AddServer adds a custom MCP server to the configuration
func (*MCPConfig) GetConfigSummary ¶
GetConfigSummary returns a summary of the current MCP configuration
func (*MCPConfig) GetEnabledServers ¶
func (c *MCPConfig) GetEnabledServers() []MCPServerConfig
GetEnabledServers returns a list of servers that should be started
func (*MCPConfig) HasGitHubToken ¶
HasGitHubToken checks if a GitHub token is configured for any server
func (*MCPConfig) RemoveServer ¶
RemoveServer removes an MCP server from the configuration
func (*MCPConfig) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling for MCPConfig to handle timeout as string or duration
func (*MCPConfig) ValidateConfig ¶
ValidateConfig validates the MCP configuration
type MCPContent ¶
type MCPContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Annotations map[string]interface{} `json:"annotations,omitempty"`
}
MCPContent represents content in MCP responses
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
MCPError represents an MCP protocol error
type MCPHTTPClient ¶
type MCPHTTPClient struct {
// contains filtered or unexported fields
}
MCPHTTPClient represents an HTTP-based MCP client for remote servers
func NewMCPHTTPClient ¶
func NewMCPHTTPClient(config MCPServerConfig, logger *utils.Logger) *MCPHTTPClient
NewMCPHTTPClient creates a new HTTP MCP client
func (*MCPHTTPClient) CallTool ¶
func (c *MCPHTTPClient) CallTool(ctx context.Context, request MCPToolCallRequest) (*MCPToolCallResult, error)
CallTool calls a tool on the server
func (*MCPHTTPClient) GetConfig ¶
func (c *MCPHTTPClient) GetConfig() MCPServerConfig
GetConfig returns the server configuration
func (*MCPHTTPClient) GetName ¶
func (c *MCPHTTPClient) GetName() string
GetName returns the server name
func (*MCPHTTPClient) GetPrompt ¶
func (c *MCPHTTPClient) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*MCPContent, error)
GetPrompt gets a prompt from the server
func (*MCPHTTPClient) Initialize ¶
func (c *MCPHTTPClient) Initialize(ctx context.Context) error
Initialize sends initialize request to the server
func (*MCPHTTPClient) IsRunning ¶
func (c *MCPHTTPClient) IsRunning() bool
IsRunning checks if the client is running
func (*MCPHTTPClient) ListPrompts ¶
func (c *MCPHTTPClient) ListPrompts(ctx context.Context) ([]MCPPrompt, error)
ListPrompts lists available prompts from the server
func (*MCPHTTPClient) ListResources ¶
func (c *MCPHTTPClient) ListResources(ctx context.Context) ([]MCPResource, error)
ListResources lists available resources from the server
func (*MCPHTTPClient) ListTools ¶
func (c *MCPHTTPClient) ListTools(ctx context.Context) ([]MCPTool, error)
ListTools lists available tools from the server
func (*MCPHTTPClient) ReadResource ¶
func (c *MCPHTTPClient) ReadResource(ctx context.Context, uri string) (*MCPContent, error)
ReadResource reads a resource from the server
type MCPManager ¶
type MCPManager interface {
// AddServer adds a new MCP server
AddServer(config MCPServerConfig) error
// RemoveServer removes an MCP server
RemoveServer(name string) error
// GetServer gets an MCP server by name
GetServer(name string) (MCPServer, bool)
// ListServers lists all registered servers
ListServers() []MCPServer
// StartAll starts all configured servers
StartAll(ctx context.Context) error
// StopAll stops all running servers
StopAll(ctx context.Context) error
// GetAllTools gets all tools from all running servers
GetAllTools(ctx context.Context) ([]MCPTool, error)
// CallTool calls a tool on the appropriate server
CallTool(ctx context.Context, serverName, toolName string, args map[string]interface{}) (*MCPToolCallResult, error)
}
MCPManager manages multiple MCP servers
type MCPMessage ¶
type MCPMessage struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params interface{} `json:"params,omitempty"`
Result interface{} `json:"result,omitempty"`
Error *MCPError `json:"error,omitempty"`
}
MCPMessage represents an MCP protocol message
type MCPPrompt ¶
type MCPPrompt struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Arguments []MCPPromptArgument `json:"arguments,omitempty"`
ServerName string `json:"server_name"`
}
MCPPrompt represents a prompt available via MCP
type MCPPromptArgument ¶
type MCPPromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required"`
}
MCPPromptArgument represents a prompt argument
type MCPResource ¶
type MCPResource struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
ServerName string `json:"server_name"`
}
MCPResource represents a resource available via MCP
type MCPServer ¶
type MCPServer interface {
// Start starts the MCP server process
Start(ctx context.Context) error
// Stop stops the MCP server process
Stop(ctx context.Context) error
// IsRunning checks if the server is running
IsRunning() bool
// GetName returns the server name
GetName() string
// GetConfig returns the server configuration
GetConfig() MCPServerConfig
// Initialize sends initialize request to server
Initialize(ctx context.Context) error
// ListTools lists available tools from the server
ListTools(ctx context.Context) ([]MCPTool, error)
// CallTool calls a tool on the server
CallTool(ctx context.Context, request MCPToolCallRequest) (*MCPToolCallResult, error)
// ListResources lists available resources from the server
ListResources(ctx context.Context) ([]MCPResource, error)
// ReadResource reads a resource from the server
ReadResource(ctx context.Context, uri string) (*MCPContent, error)
// ListPrompts lists available prompts from the server
ListPrompts(ctx context.Context) ([]MCPPrompt, error)
// GetPrompt gets a prompt from the server
GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*MCPContent, error)
}
MCPServer represents an MCP server interface
type MCPServerConfig ¶
type MCPServerConfig struct {
Name string `json:"name"`
Type string `json:"type,omitempty"` // "stdio" or "http"
Command string `json:"command,omitempty"` // For stdio servers
Args []string `json:"args,omitempty"` // For stdio servers
URL string `json:"url,omitempty"` // For HTTP servers
Env map[string]string `json:"env,omitempty"` // Non-secret environment variables
Credentials map[string]string `json:"credentials,omitempty"` // Secret credentials (env var name -> placeholder)
WorkingDir string `json:"working_dir,omitempty"` // For stdio servers
Timeout time.Duration `json:"timeout,omitempty"`
AutoStart bool `json:"auto_start"`
MaxRestarts int `json:"max_restarts"`
}
MCPServerConfig represents the configuration for an MCP server
func RedactServerConfig ¶
func RedactServerConfig(server MCPServerConfig) MCPServerConfig
RedactServerConfig returns a copy of server config with credentials redacted. The Credentials map values (which are credential reference placeholders like "{{credential:mcp/server/ENVVAR}}") are kept as-is since they are safe indirect references, not actual secrets. The Env map is redacted for sensitive keys.
func RunGitHubMCPSetup ¶
func RunGitHubMCPSetup(_ context.Context, repo *GitHubRepoInfo, reader *bufio.Reader) (*MCPServerConfig, error)
RunGitHubMCPSetup performs the interactive GitHub MCP server setup. It presents the user with three options matching cmd/mcp.go's setupGitHubMCPServer: (1) OAuth remote, (2) Docker+PAT, (3) npx+PAT. Returns the configured server config on success, or an error.
func (MCPServerConfig) GetCredentialNames ¶
func (s MCPServerConfig) GetCredentialNames() []string
GetCredentialNames returns the list of credential env var names for this server
func (MCPServerConfig) HasCredentials ¶
func (s MCPServerConfig) HasCredentials() bool
HasCredentials returns true if the server has any credentials configured
func (MCPServerConfig) MarshalJSON ¶
func (s MCPServerConfig) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for MCPServerConfig. This wrapper avoids infinite recursion with the custom UnmarshalJSON implementation. Note: this serializes credentials as-is (placeholder refs). Masking for API responses is handled at the HTTP layer via mcpServerResponse / maskCredentials.
func (*MCPServerConfig) UnmarshalJSON ¶
func (s *MCPServerConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for MCPServerConfig to handle timeout as string or duration
type MCPServerRegistry ¶
type MCPServerRegistry struct {
// contains filtered or unexported fields
}
MCPServerRegistry holds templates for known MCP servers
func NewMCPServerRegistry ¶
func NewMCPServerRegistry() *MCPServerRegistry
NewMCPServerRegistry creates a new server registry
func (*MCPServerRegistry) AddTemplate ¶
func (r *MCPServerRegistry) AddTemplate(template MCPServerTemplate) error
AddTemplate adds a custom template to the registry
func (*MCPServerRegistry) GetTemplate ¶
func (r *MCPServerRegistry) GetTemplate(id string) (MCPServerTemplate, bool)
GetTemplate returns a server template by ID
func (*MCPServerRegistry) GetTemplatesByType ¶
func (r *MCPServerRegistry) GetTemplatesByType(serverType string) []MCPServerTemplate
GetTemplatesByType returns templates of a specific type
func (*MCPServerRegistry) ListTemplates ¶
func (r *MCPServerRegistry) ListTemplates() []MCPServerTemplate
ListTemplates returns all available templates
func (*MCPServerRegistry) SearchTemplates ¶
func (r *MCPServerRegistry) SearchTemplates(query string) []MCPServerTemplate
SearchTemplates searches for templates by name or description
type MCPServerTemplate ¶
type MCPServerTemplate struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"` // "stdio", "http"
URL string `json:"url"` // For HTTP servers
Command string `json:"command"`
Args []string `json:"args"`
EnvVars []EnvVarTemplate `json:"env_vars"`
Timeout time.Duration `json:"timeout"`
Features []string `json:"features"`
AuthType string `json:"auth_type"`
Docs string `json:"docs"`
}
MCPServerTemplate represents a template for creating MCP servers
func (*MCPServerTemplate) CreateServerConfig ¶
func (template *MCPServerTemplate) CreateServerConfig(name string, envValues map[string]string, customURL string, customCommand string, customArgs []string) MCPServerConfig
CreateServerConfig creates a server config from a template with user values
type MCPTemplatesConfig ¶
type MCPTemplatesConfig struct {
Templates map[string]MCPServerTemplate `json:"templates"`
}
MCPTemplatesConfig represents the templates configuration file
type MCPTool ¶
type MCPTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"`
ServerName string `json:"server_name"`
}
MCPTool represents a tool available via MCP
type MCPToolCallRequest ¶
type MCPToolCallRequest struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
MCPToolCallRequest represents a tool call request
type MCPToolCallResult ¶
type MCPToolCallResult struct {
Content []MCPContent `json:"content"`
IsError bool `json:"isError"`
}
MCPToolCallResult represents a tool call result
type MCPToolWrapper ¶
type MCPToolWrapper struct {
// contains filtered or unexported fields
}
MCPToolWrapper wraps an MCP tool to implement the standard Tool interface
func NewMCPToolWrapper ¶
func NewMCPToolWrapper(mcpTool MCPTool, manager MCPManager) *MCPToolWrapper
NewMCPToolWrapper creates a new wrapper for an MCP tool to implement the standard Tool interface
func (*MCPToolWrapper) CanExecute ¶
func (w *MCPToolWrapper) CanExecute(ctx context.Context, params Parameters) bool
CanExecute checks if the tool can be executed with the current context
func (*MCPToolWrapper) Category ¶
func (w *MCPToolWrapper) Category() string
Category returns the category this tool belongs to
func (*MCPToolWrapper) Description ¶
func (w *MCPToolWrapper) Description() string
Description returns a human-readable description of what the tool does
func (*MCPToolWrapper) EstimatedDuration ¶
func (w *MCPToolWrapper) EstimatedDuration() time.Duration
EstimatedDuration returns an estimate of how long the tool will take to execute
func (*MCPToolWrapper) Execute ¶
func (w *MCPToolWrapper) Execute(ctx context.Context, params Parameters) (*Result, error)
Execute runs the tool with the given context and parameters
func (*MCPToolWrapper) GetMCPTool ¶
func (w *MCPToolWrapper) GetMCPTool() MCPTool
GetMCPTool returns the underlying MCP tool
func (*MCPToolWrapper) GetServerName ¶
func (w *MCPToolWrapper) GetServerName() string
GetServerName returns the server name
func (*MCPToolWrapper) GetToolName ¶
func (w *MCPToolWrapper) GetToolName() string
GetToolName returns the original tool name (without MCP prefix)
func (*MCPToolWrapper) IsAvailable ¶
func (w *MCPToolWrapper) IsAvailable() bool
IsAvailable checks if the tool is available in the current environment
func (*MCPToolWrapper) Name ¶
func (w *MCPToolWrapper) Name() string
Name returns the unique name of the tool
func (*MCPToolWrapper) RequiredPermissions ¶
func (w *MCPToolWrapper) RequiredPermissions() []string
RequiredPermissions returns the permissions needed to execute this tool
func (*MCPToolWrapper) SetAvailable ¶
func (w *MCPToolWrapper) SetAvailable(available bool)
SetAvailable allows enabling/disabling the tool
func (*MCPToolWrapper) SetCategory ¶
func (w *MCPToolWrapper) SetCategory(category string)
SetCategory allows customizing the tool category
func (*MCPToolWrapper) SetTimeout ¶
func (w *MCPToolWrapper) SetTimeout(timeout time.Duration)
SetTimeout allows customizing the tool timeout
func (*MCPToolWrapper) ToAgentTool ¶
func (w *MCPToolWrapper) ToAgentTool() AgentTool
ToAgentTool converts the MCP tool to the agent's Tool format
func (*MCPToolWrapper) ValidateArgs ¶
func (w *MCPToolWrapper) ValidateArgs(args map[string]interface{}) error
ValidateArgs validates arguments against the tool's input schema using JSON Schema validation. Returns nil if the arguments are valid or if there is no schema to validate against. Returns an InvalidArgsError with structured failures on validation errors.
type Parameters ¶
Local type definitions to avoid import cycle
type ValidationFailure ¶
type ValidationFailure struct {
// Path is the JSON pointer path to the failing field (e.g., ".query", ".filters[0]")
Path string
// Reason is a human-readable explanation of why validation failed
Reason string
}
ValidationFailure represents a single validation error at a specific field path.