mcp

package
v0.50.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransportStreamableHTTP = "streamable_http"
	TransportStdio          = "stdio"

	AuthNone   = "none"
	AuthAPIKey = "api_key"
	AuthOAuth  = "oauth"
)
View Source
const DefaultOAuthRedirectURL = "http://localhost:1456/auth/mcp/callback"

Variables

View Source
var (
	ErrServerNotConfigured = errors.New("mcp server not configured")
	ErrServerDisconnected  = errors.New("mcp server disconnected")
	ErrAuthRequired        = errors.New("mcp authentication required")
	ErrAuthFailed          = errors.New("mcp authentication failed")
	ErrToolNotFound        = errors.New("mcp tool not found")
	ErrTimeout             = errors.New("mcp operation timed out")
	ErrProtocol            = errors.New("mcp protocol error")
	ErrRemoteTool          = errors.New("mcp remote tool error")
	ErrAlreadyStarted      = errors.New("mcp manager already started")
)

Functions

func DefaultConfigPath

func DefaultConfigPath() string

func NewBrowserOAuthCodeFetcher

func NewBrowserOAuthCodeFetcher(redirectURL string) mcpauth.AuthorizationCodeFetcher

Types

type AuthConfig

type AuthConfig struct {
	Type   string   `json:"type,omitempty"`
	Header string   `json:"header,omitempty"`
	Scheme string   `json:"scheme,omitempty"`
	Key    string   `json:"key,omitempty"`
	Scopes []string `json:"scopes,omitempty"`
}

type Config

type Config struct {
	Servers map[string]ServerConfig `json:"servers"`
}

func LoadConfig

func LoadConfig() (*Config, error)

func (*Config) Validate

func (c *Config) Validate() error

type Error

type Error struct {
	Kind   error
	Server string
	Tool   string
	Err    error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Manager

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

func NewManager

func NewManager(opts ...Option) (*Manager, error)

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, server, tool string, arguments map[string]any) (*ToolResult, error)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) ListTools

func (m *Manager) ListTools(ctx context.Context, server string) ([]Tool, error)

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, server string, opts ...RefreshOption) error

func (*Manager) Servers

func (m *Manager) Servers() []ServerStatus

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

func (*Manager) Status

func (m *Manager) Status(server string) ServerStatus

func (*Manager) WaitInitialScan

func (m *Manager) WaitInitialScan(ctx context.Context) error

type Option

type Option func(*managerOptions)

func WithAuthStore

func WithAuthStore(store *keenauth.Store) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithOAuthAuthorizationCodeFetcher

func WithOAuthAuthorizationCodeFetcher(fetcher mcpauth.AuthorizationCodeFetcher) Option

func WithOAuthClientIDMetadataDocument

func WithOAuthClientIDMetadataDocument(url string) Option

func WithOAuthClientName

func WithOAuthClientName(name string) Option

func WithOAuthPreregisteredClient

func WithOAuthPreregisteredClient(clientID, clientSecret string) Option

func WithOAuthRedirectURL

func WithOAuthRedirectURL(redirectURL string) Option

func WithStandaloneSSEDisabled

func WithStandaloneSSEDisabled(disabled bool) Option

func WithStdioTerminateTimeout

func WithStdioTerminateTimeout(timeout time.Duration) Option

func WithStreamableMaxRetries

func WithStreamableMaxRetries(maxRetries int) Option

func WithTimeouts

func WithTimeouts(connect, listTools, callTool time.Duration) Option

type RefreshOption

type RefreshOption func(*managerOptions)

func WithRefreshConnectTimeout

func WithRefreshConnectTimeout(timeout time.Duration) RefreshOption

func WithRefreshOAuthAuthorizationCodeFetcher

func WithRefreshOAuthAuthorizationCodeFetcher(fetcher mcpauth.AuthorizationCodeFetcher) RefreshOption

func WithRefreshOAuthForceReauth

func WithRefreshOAuthForceReauth(force bool) RefreshOption

func WithRefreshOAuthRedirectURL

func WithRefreshOAuthRedirectURL(redirectURL string) RefreshOption

type Runtime

type Runtime interface {
	Start(context.Context) error
	Close() error
	Servers() []ServerStatus
	Status(string) ServerStatus
	WaitInitialScan(context.Context) error
	ListTools(context.Context, string) ([]Tool, error)
	CallTool(context.Context, string, string, map[string]any) (*ToolResult, error)
	Refresh(context.Context, string, ...RefreshOption) error
}

type ServerConfig

type ServerConfig struct {
	URL     string            `json:"url,omitempty"`
	Auth    AuthConfig        `json:"auth,omitempty"`
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

type ServerState

type ServerState string
const (
	StateConfigured   ServerState = "configured"
	StateConnecting   ServerState = "connecting"
	StateConnected    ServerState = "connected"
	StateDisconnected ServerState = "disconnected"
	StateAuthRequired ServerState = "auth_required"
	StateAuthFailed   ServerState = "auth_failed"
)

type ServerStatus

type ServerStatus struct {
	Name                    string
	Transport               string
	AuthType                string
	State                   ServerState
	LastConnectedAt         time.Time
	LastToolRefreshAt       time.Time
	LastError               string
	ToolCount               int
	Endpoint                string
	StdioCommand            string
	NegotiatedProtocol      string
	NegotiatedServerName    string
	NegotiatedServerVersion string
	Description             string
}

type Tool

type Tool struct {
	Name         string
	Title        string
	Description  string
	InputSchema  any
	OutputSchema any
}

type ToolResult

type ToolResult struct {
	Content           []mcpsdk.Content
	StructuredContent any
	IsError           bool
	Meta              map[string]any
}

Jump to

Keyboard shortcuts

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