mcp

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package mcp owns Or's product-level MCP configuration, connection manager, leases, diagnostics, and adaptation of protocol tools to coding-agent tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayTitle

func DisplayTitle(definition *protocol.Tool) string

DisplayTitle returns the MCP-standard display-name precedence for a tool.

func ToolName

func ToolName(serverName, originalName string) string

ToolName returns the provider-safe, deterministic name Or advertises for an MCP tool.

func WriteConfig

func WriteConfig(path string, config Config) error

WriteConfig atomically replaces path with a private, canonical JSON file.

Types

type Config

type Config struct {
	Version    int                     `json:"version"`
	MCPServers map[string]ServerConfig `json:"mcpServers"`
}

Config is the on-disk MCP server configuration. It intentionally lives in Or's private data directory rather than in a workspace: opening an untrusted repository must never be enough to start an arbitrary local process.

func ParseConfig

func ParseConfig(data []byte) (Config, error)

ParseConfig decodes one strict MCP configuration document.

func ReadConfig

func ReadConfig(path string) (Config, error)

ReadConfig loads the product-owned MCP configuration without connecting to any server. A missing file remains distinguishable from an empty config so callers can decide whether MCP should be surfaced at all.

type Lease

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

Lease is one conversation's immutable view of tools and server statuses.

func (*Lease) Close

func (lease *Lease) Close()

Close releases this lease without closing connections still used by another runtime or retained by the active manager generation.

func (*Lease) Statuses

func (lease *Lease) Statuses() []ServerStatus

Statuses returns an independent slice of secret-free diagnostics.

func (*Lease) Tools

func (lease *Lease) Tools() []tools.Tool

Tools returns an independent slice of MCP tools adapted to Or's tool and permission contracts.

type Manager

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

Manager loads one product-owned config and shares matching connections among conversation runtimes. Config generations are isolated so active runtimes retain their old connections while newly loaded runtimes use new settings.

func New

func New(ctx context.Context, path string) *Manager

New creates a manager and loads its initial configuration. Configuration errors are retained as lease diagnostics instead of preventing app startup.

func (*Manager) Acquire

func (manager *Manager) Acquire(ctx context.Context, workspace string) *Lease

Acquire waits for every applicable server in the current generation and returns one immutable snapshot. Individual server failures are represented in Statuses and never fail the whole lease.

func (*Manager) Close

func (manager *Manager) Close()

Close cancels initialization and closes every cached connection.

func (*Manager) Path

func (manager *Manager) Path() string

Path returns the private configuration file managed by this instance.

func (*Manager) Reload

func (manager *Manager) Reload() error

Reload installs the latest on-disk configuration as a new generation. Old connections remain alive until every lease using them has been released.

func (*Manager) Warm

func (manager *Manager) Warm(workspace string)

Warm starts resolving the servers visible to workspace without retaining a conversation lease. Connections from the active config generation remain cached for later sessions.

func (*Manager) WarmGlobal

func (manager *Manager) WarmGlobal()

WarmGlobal starts workspace-independent HTTP servers. It is safe during app startup before any project or scratch workspace has been selected.

type ProbeResult

type ProbeResult struct {
	Transport string      `json:"transport"`
	Tools     []ProbeTool `json:"tools"`
}

ProbeResult reports a successful initialize and tools/list round trip.

func Probe

func Probe(ctx context.Context, name string, config ServerConfig, workspace string) (ProbeResult, error)

Probe connects to one saved server long enough to discover its tools, then closes the connection. Calling it is an explicit user action in settings.

type ProbeTool

type ProbeTool struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

ProbeTool is compact protocol metadata discovered during a connection probe.

type ServerConfig

type ServerConfig struct {
	Disabled       bool              `json:"disabled,omitempty"`
	Command        string            `json:"command,omitempty"`
	Args           []string          `json:"args,omitempty"`
	Env            map[string]string `json:"env,omitempty"`
	Cwd            string            `json:"cwd,omitempty"`
	URL            string            `json:"url,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	Workspaces     []string          `json:"workspaces,omitempty"`
	TimeoutSeconds int               `json:"timeoutSeconds,omitempty"`
}

ServerConfig describes either one stdio server (Command) or one Streamable HTTP server (URL). Workspaces scopes a server to exact workspace roots; an empty list makes it available to every session.

func (ServerConfig) AppliesTo

func (config ServerConfig) AppliesTo(workspace string) (bool, error)

AppliesTo reports whether this server is visible to one exact workspace.

func (ServerConfig) Validate

func (config ServerConfig) Validate() error

Validate checks the transport-level fields that do not require expanding environment references or opening a connection.

type ServerState

type ServerState string
const (
	StateConnected  ServerState = "connected"
	StateDisabled   ServerState = "disabled"
	StateError      ServerState = "error"
	StateOutOfScope ServerState = "out_of_scope"
)

type ServerStatus

type ServerStatus struct {
	Name      string      `json:"name"`
	Transport string      `json:"transport,omitempty"`
	State     ServerState `json:"state"`
	ToolCount int         `json:"toolCount,omitempty"`
	Error     string      `json:"error,omitempty"`
}

ServerStatus is a secret-free connection diagnostic returned by mcp_status.

Directories

Path Synopsis
Package client owns protocol-native Model Context Protocol connections, transports, tool discovery, and tool calls.
Package client owns protocol-native Model Context Protocol connections, transports, tool discovery, and tool calls.

Jump to

Keyboard shortcuts

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