mcpclient

package
v0.6.10 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package mcpclient manages configured Model Context Protocol connections and exposes protocol-native tool definitions and results to product adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 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.

type Session

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

Session owns the MCP connections and adapted tools for one coding session. Coding sessions are unloaded while idle, so their subprocesses and remote sessions naturally follow the same lifecycle.

func Open

func Open(ctx context.Context, path, workspace string) *Session

Open loads path and connects every server visible to workspace. A missing config is the normal disabled state and returns nil. Invalid or unavailable servers are isolated as diagnostics so one integration cannot prevent a conversation from opening.

func (*Session) Close

func (session *Session) Close()

Close gracefully terminates every MCP connection. It is idempotent.

func (*Session) Statuses

func (session *Session) Statuses() []ServerStatus

Statuses returns secret-free connection diagnostics for all configured servers.

func (*Session) Tools

func (session *Session) Tools() []Tool

Tools returns an independent slice of the tools discovered from connected MCP servers.

type Tool

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

Tool is one tool discovered from an MCP server. It retains the protocol definition and connection needed to call the original server without depending on Or's agent, provider, or permission types.

func (Tool) Call

func (tool Tool) Call(ctx context.Context, arguments any) (*protocol.CallToolResult, error)

Call invokes the tool with protocol-native arguments and returns the protocol-native result.

func (Tool) Definition

func (tool Tool) Definition() *protocol.Tool

Definition returns the MCP protocol definition advertised by the server. Callers must treat the returned definition as read-only.

func (Tool) ServerName

func (tool Tool) ServerName() string

ServerName returns the configured name of the server that owns the tool.

func (Tool) Transport

func (tool Tool) Transport() string

Transport returns the MCP transport used by the owning server.

Jump to

Keyboard shortcuts

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