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 ¶
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 ¶ added in v0.6.11
ParseConfig decodes one strict MCP configuration document.
func ReadConfig ¶
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 Connection ¶ added in v0.6.11
type Connection struct {
// contains filtered or unexported fields
}
Connection owns one initialized MCP client session and its discovered tools. Product-level managers can share it without depending on protocol internals.
func Connect ¶ added in v0.6.11
func Connect(ctx context.Context, name string, config ServerConfig, workspace string) (*Connection, error)
Connect initializes one server and discovers its complete tools/list result. Workspace scoping is a product concern and must be checked by the caller.
func (*Connection) Close ¶ added in v0.6.11
func (connection *Connection) Close()
Close gracefully terminates the protocol session. It is idempotent.
func (*Connection) Diagnostic ¶ added in v0.6.11
func (connection *Connection) Diagnostic() string
Diagnostic reports non-fatal tool definition problems found at startup.
func (*Connection) Name ¶ added in v0.6.11
func (connection *Connection) Name() string
Name returns the configured server name used for tool names and diagnostics.
func (*Connection) Tools ¶ added in v0.6.11
func (connection *Connection) Tools() []Tool
Tools returns an independent slice of the tools discovered at initialization.
func (*Connection) Transport ¶ added in v0.6.11
func (connection *Connection) Transport() string
Transport returns stdio or streamable_http.
type ProbeResult ¶
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. It remains as the compatibility aggregate used while connection ownership is moved to the application-level manager.
func Open ¶
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.
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 ¶
Call invokes the tool with protocol-native arguments and returns the protocol-native result.
func (Tool) Definition ¶
Definition returns the MCP protocol definition advertised by the server. Callers must treat the returned definition as read-only.
func (Tool) ServerName ¶
ServerName returns the configured name of the server that owns the tool.