discovery

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package discovery provides MCP server auto-discovery functionality. This system scans common configuration locations to automatically import existing MCP server configurations into centian.

Index

Constants

View Source
const (
	SourceTypeClaudeDesktop  = "claude-desktop"
	SourceTypeVSCodeMCP      = "vscode-mcp"
	SourceTypeVSCodeSettings = "vscode-settings"
	SourceTypeGenericMCP     = "generic-mcp"
)

Source type constants.

View Source
const (
	ClaudeDesktopConfigFile = "claude_desktop_config.json"
	VSCodeMCPConfigFile     = ".vscode/mcp.json"
	VSCodeSettingsFile      = "settings.json"
)

File path identifier constants.

View Source
const (
	ConfigKeyMCPServers     = "mcpServers"
	ConfigKeyServers        = "servers"
	ConfigKeyMCPServersPath = "mcp.servers"
)

Config key constants.

View Source
const (
	CentianCommand      = "centian"
	CentianStartCommand = "start"
	CentianPathFlag     = "--path"
	BackupFileSuffix    = ".centian-backup"
)

Centian proxy constants.

Variables

This section is empty.

Functions

func GetDefaultSearchPaths

func GetDefaultSearchPaths() []string

GetDefaultSearchPaths returns the default paths to search for MCP configurations.

func ImportServers

func ImportServers(servers []Server) int

ImportServers converts discovered servers to MCPServer configs and adds them to the global config.

func ShowImportSummary

func ShowImportSummary(imported int)

ShowImportSummary displays the results of the import process.

Types

type ClaudeDesktopDiscoverer

type ClaudeDesktopDiscoverer struct{}

ClaudeDesktopDiscoverer discovers MCP servers from Claude Desktop configuration.

func (*ClaudeDesktopDiscoverer) Description

func (c *ClaudeDesktopDiscoverer) Description() string

Description returns a description of what the Claude Desktop discoverer does.

func (*ClaudeDesktopDiscoverer) Discover

func (c *ClaudeDesktopDiscoverer) Discover() ([]Server, error)

Discover searches for MCP servers in Claude Desktop configuration files.

func (*ClaudeDesktopDiscoverer) IsAvailable

func (c *ClaudeDesktopDiscoverer) IsAvailable() bool

IsAvailable returns whether Claude Desktop discovery is available on the current platform.

func (*ClaudeDesktopDiscoverer) Name

func (c *ClaudeDesktopDiscoverer) Name() string

Name returns the name of the Claude Desktop discoverer.

type ConfigDiscoverer

type ConfigDiscoverer interface {
	// Name returns the human-readable name of this discoverer.
	Name() string

	// Description returns a description of what this discoverer searches for.
	Description() string

	// Discover scans for and parses MCP server configurations.
	Discover() ([]Server, error)

	// IsAvailable checks if this discoverer can run on the current system.
	IsAvailable() bool
}

ConfigDiscoverer defines the interface for config file discoverers.

type ConfigFileGroup

type ConfigFileGroup struct {
	SourcePath      string   `json:"sourcePath"`      // Absolute path to config file
	Servers         []Server `json:"servers"`         // Servers found in this file
	StdioCount      int      `json:"stdioCount"`      // Number of stdio servers
	HTTPCount       int      `json:"httpCount"`       // Number of http servers
	TotalCount      int      `json:"totalCount"`      // Total number of servers
	DuplicatesFound int      `json:"duplicatesFound"` // Total number of duplicate configs merged
}

ConfigFileGroup represents servers grouped by their source config file.

type ConfigParserFunc

type ConfigParserFunc func(data []byte, filePath string) ([]Server, error)

ConfigParserFunc is a function that parses config data and extracts MCP servers.

type GroupedDiscoveryResult

type GroupedDiscoveryResult struct {
	Groups []ConfigFileGroup `json:"groups"`
	Errors []string          `json:"errors"` // Non-fatal errors during discovery
}

GroupedDiscoveryResult contains servers grouped by source file.

func GroupDiscoveryResults

func GroupDiscoveryResults(result *Result) *GroupedDiscoveryResult

GroupDiscoveryResults groups servers by their source config file.

type Manager

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

Manager manages multiple config discoverers.

func NewDiscoveryManager

func NewDiscoveryManager() *Manager

NewDiscoveryManager creates a new discovery manager with default discoverers.

func (*Manager) DiscoverAll

func (dm *Manager) DiscoverAll() *Result

DiscoverAll runs all available discoverers and aggregates results.

func (*Manager) ListDiscoverers

func (dm *Manager) ListDiscoverers() []map[string]string

ListDiscoverers returns information about available discoverers.

func (*Manager) RegisterDiscoverer

func (dm *Manager) RegisterDiscoverer(discoverer ConfigDiscoverer)

RegisterDiscoverer adds a new config discoverer.

type Pattern

type Pattern struct {
	FileRegex    string   `json:"fileRegex"`    // Regex pattern for file path/name
	ContentRegex []string `json:"contentRegex"` // Content must match these patterns
	Parser       string   `json:"parser"`       // Parser function name
	SourceType   string   `json:"sourceType"`   // For replacement logic
	Priority     int      `json:"priority"`     // Higher = search first
}

Pattern defines how to find and parse a specific type of config file.

func GetDefaultPatterns

func GetDefaultPatterns() []Pattern

GetDefaultPatterns returns the default discovery patterns for common MCP config files.

func GetPriorityPatterns

func GetPriorityPatterns() []Pattern

GetPriorityPatterns returns patterns sorted by priority (highest first).

type RegexDiscoverer

type RegexDiscoverer struct {
	DiscovererName        string
	DiscovererDescription string
	Patterns              []Pattern
	SearchPaths           []string
	MaxDepth              int
	Enabled               bool
}

RegexDiscoverer represents a regex-based pattern for discovering MCP configs.

func CreateCustomRegexDiscoverer

func CreateCustomRegexDiscoverer(name, description string, patterns []Pattern, searchPaths []string) *RegexDiscoverer

CreateCustomRegexDiscoverer creates a RegexDiscoverer with custom patterns.

func GetDefaultRegexDiscoverer

func GetDefaultRegexDiscoverer() *RegexDiscoverer

GetDefaultRegexDiscoverer creates a RegexDiscoverer with default patterns for common MCP configs.

func (*RegexDiscoverer) Description

func (r *RegexDiscoverer) Description() string

Description returns a description of what the regex-based discoverer does.

func (*RegexDiscoverer) Discover

func (r *RegexDiscoverer) Discover() ([]Server, error)

Discover searches for MCP servers using regex-based pattern matching.

func (*RegexDiscoverer) IsAvailable

func (r *RegexDiscoverer) IsAvailable() bool

IsAvailable returns whether the regex-based discoverer is enabled.

func (*RegexDiscoverer) Name

func (r *RegexDiscoverer) Name() string

Name returns the name of the regex-based discoverer.

type ReplacementConfig

type ReplacementConfig struct {
	SourcePath      string   // Path to original config file
	SourceType      string   // Type: "claude-desktop", "vscode-mcp", "vscode-settings"
	OriginalServers []string // Names of servers being replaced
	ProxyConfig     string   // Replacement config snippet
}

ReplacementConfig contains information for replacing a source config with centian proxy.

type Result

type Result struct {
	Servers []Server `json:"servers"`
	Errors  []string `json:"errors"` // Non-fatal errors during discovery
}

Result contains the results of auto-discovery scan.

type Server

type Server struct {
	Name            string            `json:"name"`            // Server name
	Command         string            `json:"command"`         // Executable command (for stdio transport)
	Args            []string          `json:"args"`            // Command arguments
	Env             map[string]string `json:"env"`             // Environment variables
	URL             string            `json:"url"`             // HTTP/WebSocket URL (for http/ws transport)
	Headers         map[string]string `json:"headers"`         // HTTP headers (for http transport)
	Transport       string            `json:"transport"`       // Transport type: stdio, http, websocket
	Description     string            `json:"description"`     // Human readable description
	Source          string            `json:"source"`          // Where it was discovered from
	SourcePath      string            `json:"sourcePath"`      // Full path to source file
	ReplacementMode bool              `json:"replacementMode"` // Whether to generate replacement configs
	DuplicatesFound int               `json:"duplicatesFound"` // Number of identical configs found and merged
}

Server represents an MCP server found during auto-discovery.

func ParseConfigFile

func ParseConfigFile(data []byte, filePath string) ([]Server, error)

ParseConfigFile parses an MCP configuration file and returns discovered servers. This is the exported entry point for parsing config files from external packages.

type UserInterface

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

UserInterface provides user interface functions for the discovery system.

func NewDiscoveryUI

func NewDiscoveryUI() *UserInterface

NewDiscoveryUI creates a new discovery UI interface.

func (*UserInterface) ShowDiscoveryResults

func (ui *UserInterface) ShowDiscoveryResults(result *Result) ([]Server, error)

ShowDiscoveryResults displays discovered servers and prompts for user consent.

type VSCodeDiscoverer

type VSCodeDiscoverer struct{}

VSCodeDiscoverer discovers MCP servers from VS Code configurations.

func (*VSCodeDiscoverer) Description

func (v *VSCodeDiscoverer) Description() string

Description returns a description of what the VS Code discoverer does.

func (*VSCodeDiscoverer) Discover

func (v *VSCodeDiscoverer) Discover() ([]Server, error)

Discover searches for MCP servers in VS Code configuration files.

func (*VSCodeDiscoverer) IsAvailable

func (v *VSCodeDiscoverer) IsAvailable() bool

IsAvailable returns whether VS Code discovery is available on the current platform.

func (*VSCodeDiscoverer) Name

func (v *VSCodeDiscoverer) Name() string

Name returns the name of the VS Code discoverer.

Jump to

Keyboard shortcuts

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