Documentation
¶
Overview ¶
Package mcp implements a native MCP (Model Context Protocol) client layer for pig. It is a pig-only surface (pi has no native MCP): it reads standard `mcpServers` config files, lazily spawns/connects servers over stdio or Streamable HTTP, and exposes tool discovery + invocation to the proxy tool built in codingagent/core (see core/mcp_integration.go).
The package is deliberately leaf-ish: it depends only on the official SDK (github.com/modelcontextprotocol/go-sdk) and stdlib. All pig-side knowledge (config paths, trust gating, `!command`/$env header resolution, tool definition plumbing) lives in codingagent/core.
Index ¶
- Constants
- Variables
- func LoadConfigFileChain(files []ConfigFile) (*Config, []Diagnostic, error)
- func LoadConfigFiles(paths []string) (*Config, []Diagnostic, error)
- func ParseConfigBytes(path string, content []byte) (*Config, []Diagnostic)
- func ParseConfigFile(path string) (*Config, []Diagnostic, error)
- type Config
- type ConfigFile
- type CredentialStore
- func (s *CredentialStore) Load(name, serverURL string) (*OAuthServerState, error)
- func (s *CredentialStore) Remove(name, serverURL string) (bool, error)
- func (s *CredentialStore) Save(name, serverURL string, state *OAuthServerState) error
- func (s *CredentialStore) Tokens(name, serverURL string) *OAuthTokens
- func (s *CredentialStore) WithRefreshLock(name, serverURL string, fn func() error) error
- type Diagnostic
- type MCPAuthConfig
- type Manager
- func (m *Manager) CallTool(ctx context.Context, server, tool string, args map[string]any) (*ToolCallOutput, error)
- func (m *Manager) Close() error
- func (m *Manager) DescribeTool(ctx context.Context, name string) (ToolInfo, error)
- func (m *Manager) HasServers() bool
- func (m *Manager) ListServerTools(ctx context.Context, name string) ([]ToolInfo, error)
- func (m *Manager) Reconnect(ctx context.Context, name string) error
- func (m *Manager) SearchTools(ctx context.Context, query string, limit int) ([]ToolMatch, error)
- func (m *Manager) ServerNames() []string
- func (m *Manager) SetServerDisabled(name string, disabled bool) error
- func (m *Manager) SetServerDisabledInProject(name string, disabled bool) error
- func (m *Manager) SignIn(ctx context.Context, name string, prompt SignInPrompt, openURL func(string)) error
- func (m *Manager) SignOut(name string) (bool, error)
- func (m *Manager) StartEager()
- func (m *Manager) Status() []ServerStatus
- type ManagerOptions
- type OAuthCallback
- type OAuthCallbackServer
- func (s *OAuthCallbackServer) Close() error
- func (s *OAuthCallbackServer) Port() int
- func (s *OAuthCallbackServer) RedirectURL() string
- func (s *OAuthCallbackServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *OAuthCallbackServer) WaitForCallback(state string, path string, timeout time.Duration) <-chan OAuthCallback
- type OAuthChallenge
- type OAuthClientInformation
- type OAuthConfig
- type OAuthServerState
- type OAuthSettings
- type OAuthTokens
- type OAuthTransportHandler
- type ServerConfig
- type ServerStatus
- type SignInPrompt
- type ToolCallOutput
- type ToolInfo
- type ToolMatch
Constants ¶
const ( // LifecycleLazy (default) connects on first use and reaps the server after // IdleTimeoutMs of inactivity. LifecycleLazy = "lazy" // LifecycleEager connects when the manager starts and reaps after idle. LifecycleEager = "eager" // LifecycleKeepAlive connects eagerly and is never reaped. LifecycleKeepAlive = "keep-alive" // LifecycleLazyKeepAlive connects on first use and is never reaped. LifecycleLazyKeepAlive = "lazy-keep-alive" )
Lifecycle values for ServerConfig.
const ( DefaultIdleTimeoutMs = 5 * 60 * 1000 DefaultRequestTimeoutMs = 60 * 1000 )
Defaults overridable via ManagerOptions (config-level zero values fall back to these).
Variables ¶
var ErrRefreshLockBusy = errors.New("another process is refreshing the MCP server's tokens")
ErrRefreshLockBusy reports that another process held the refresh lock for the whole wait (pi: McpRefreshLockBusyError). A sign-in then skips the refresh and goes to the browser step; any other lock failure fails it.
var ErrSignInCancelled = errors.New("sign-in cancelled")
ErrSignInCancelled reports that the user cancelled a sign-in (pi: McpSignInCancelledError).
var ErrSignInRequired = errors.New("requires sign-in")
ErrSignInRequired reports that a server needs an interactive sign-in (stored credentials missing, expired, or rejected). The manager maps it to the "needs-auth" server status.
Functions ¶
func LoadConfigFileChain ¶ added in v1.0.1
func LoadConfigFileChain(files []ConfigFile) (*Config, []Diagnostic, error)
LoadConfigFileChain parses the given files in order and merges them with later files winning on per-server conflicts. Project-scoped files accept override entries (no `command`/`url`, only `disabled`): they are resolved after the whole chain against the server with the same name defined in a later file, and recorded in Config.Overrides (#10277).
func LoadConfigFiles ¶
func LoadConfigFiles(paths []string) (*Config, []Diagnostic, error)
LoadConfigFiles parses the given files in order and merges them, with later files winning on per-server conflicts (whole-entry replacement, not field merge). Invalid servers are dropped from the merged result but reported in the returned diagnostics. All files are treated as non-project (no override entries); use LoadConfigFileChain for scoped chains.
func ParseConfigBytes ¶
func ParseConfigBytes(path string, content []byte) (*Config, []Diagnostic)
ParseConfigBytes parses the raw JSON content of one MCP config file. A missing `mcpServers` key is not an error (empty config); malformed JSON and invalid server entries produce diagnostics.
func ParseConfigFile ¶
func ParseConfigFile(path string) (*Config, []Diagnostic, error)
ParseConfigFile reads and parses one MCP config file. A missing file is not an error and returns a nil config.
Types ¶
type Config ¶
type Config struct {
MCPServers map[string]ServerConfig `json:"mcpServers"`
// Sources maps each merged server name to the file path of the winning
// definition (later-wins chain; pig-only, not serialized). Set only by
// LoadConfigFiles — the /mcp panel needs it to write `disabled` back to
// the file that actually owns the server.
Sources map[string]string `json:"-"`
// Overrides maps server names to the project file that overrides them
// (pi 1387af7b4's McpServerEntry.override; pig-only, not serialized). A
// project entry without `command`/`url` overrides only `disabled` of the
// server with the same name defined in a later (global/user-level) file.
Overrides map[string]string `json:"-"`
}
Config is the root shape of a pig MCP config file. It matches the ecosystem-standard `mcpServers` key so existing Claude Code / Cursor style .mcp.json files work as-is.
func (*Config) SortedServerNames ¶
SortedServerNames returns the merged server names in deterministic order.
type ConfigFile ¶ added in v1.0.1
ConfigFile is one file in the config chain with its scope. Project-scoped files accept override entries (no `command`/`url`) that only set `disabled` on a server defined elsewhere in the chain (#10277).
type CredentialStore ¶ added in v1.0.2
type CredentialStore struct {
// contains filtered or unexported fields
}
CredentialStore persists per-server OAuth state in one JSON file. Safe for concurrent use; file reads/writes and the cross-process refresh lock are serialized through flock (unix). On windows the lock is a no-op (declared deviation: refreshes serialize in-process only).
func NewCredentialStore ¶ added in v1.0.2
func NewCredentialStore(path, lockDir string) *CredentialStore
NewCredentialStore builds a store backed by path. The refresh-lock files live in lockDir (usually the agent dir); empty lockDir means refreshes are only serialized within this process.
func (*CredentialStore) Load ¶ added in v1.0.2
func (s *CredentialStore) Load(name, serverURL string) (*OAuthServerState, error)
Load returns the stored state for the server, or nil when none. State for another server URL is ignored so credentials never leak across servers (pi: provider.own).
func (*CredentialStore) Remove ¶ added in v1.0.2
func (s *CredentialStore) Remove(name, serverURL string) (bool, error)
Remove deletes the server's stored credentials and reports whether any were stored.
func (*CredentialStore) Save ¶ added in v1.0.2
func (s *CredentialStore) Save(name, serverURL string, state *OAuthServerState) error
Save writes the state for the server, creating the file (and its directory) when missing.
func (*CredentialStore) Tokens ¶ added in v1.0.2
func (s *CredentialStore) Tokens(name, serverURL string) *OAuthTokens
Tokens returns the stored tokens of a server without taking over anything (pi: McpOAuthCredentialStore.tokens — the /mcp panel notices sign-ins done by another process).
func (*CredentialStore) WithRefreshLock ¶ added in v1.0.2
func (s *CredentialStore) WithRefreshLock(name, serverURL string, fn func() error) error
WithRefreshLock runs fn while no other process refreshes the server's tokens (pi: McpOAuthServerStore.withRefreshLock). Held from reading the tokens to saving the rotated ones; without it, two processes refreshing with the same refresh token lose the grant when the server rotates. A lock held for the whole wait returns ErrRefreshLockBusy; other failures (for example an unusable lock directory) surface as-is and fail the sign-in.
type Diagnostic ¶
type Diagnostic struct {
Severity string `json:"severity"`
Message string `json:"message"`
Path string `json:"path,omitempty"`
Server string `json:"server,omitempty"`
}
Diagnostic is a config-level problem. Severity is "warning" or "error"; errors mean the config (or the offending server) was not loaded.
type MCPAuthConfig ¶ added in v1.0.2
type MCPAuthConfig struct {
Provider string `json:"provider"`
}
MCPAuthConfig sends a provider's login token instead of OAuth.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the configured MCP servers: lazy connect, tool discovery, tool invocation, idle reaping and shutdown. It is safe for concurrent use.
Locking: Manager.mu guards the server map and `closed`; each serverState has its own mutex serializing lifecycle (connect/close/reap) and requests for that server. Status() reads only fields guarded by Manager.mu-style snapshots, so it never blocks on an in-flight tool call.
func NewManager ¶
func NewManager(config *Config, opts ManagerOptions) *Manager
NewManager creates a Manager for the given (already merged) config. It does not connect anything: lazy servers connect on first use, eager/keep-alive servers connect when StartEager is called.
func (*Manager) CallTool ¶
func (m *Manager) CallTool(ctx context.Context, server, tool string, args map[string]any) (*ToolCallOutput, error)
CallTool invokes `tool` (display or raw name, or explicit "server__tool") with the given arguments on its server, honoring the server's request timeout and include/exclude filters.
func (*Manager) DescribeTool ¶
DescribeTool returns the full ToolInfo for a display name (ToolPrefix + raw name) or raw name. It resolves the name across servers, connecting as needed.
func (*Manager) HasServers ¶
HasServers reports whether any server is configured.
func (*Manager) ListServerTools ¶
ListServerTools returns the filtered tool list of one server, connecting it first if needed (lazy semantics unchanged). Disabled servers error. The result is a copy. (pig-only: the /mcp panel lists tools on expand.)
func (*Manager) Reconnect ¶
Reconnect drops the server's current session (if any) and connects afresh. Connect errors are returned as-is for the caller to surface (the /mcp panel shows them on the server row). Disabled servers are never connected. (pig-only: pi-mcp-adapter's ctrl+r.)
func (*Manager) SearchTools ¶
SearchTools connects servers as needed to list their tools, filters by the configured include/exclude globs, scores them against the query and returns the top `limit` matches (all matches when limit <= 0). An empty query lists every tool.
func (*Manager) ServerNames ¶
ServerNames returns the configured server names in sorted order.
func (*Manager) SetServerDisabled ¶
SetServerDisabled flips a server's disabled flag in memory and writes it back to the config file that owns it (JSON surgery on mcpServers[name] only — sibling servers and unknown fields are preserved). The write target is the project override file when the server is overridden (#10277), else its winning source file; enabling deletes the key instead of writing false, except on override entries whose explicit value replaces the overridden server's. A disabled server is torn down; a re-enabled one goes back to disconnected and reconnects lazily. When the manager was built without a source path, only the in-memory flag changes. (pig-only: pi-mcp-adapter keeps an overlay state file; pig persists to the source mcp.json per user decision.)
func (*Manager) SetServerDisabledInProject ¶ added in v1.0.1
SetServerDisabledInProject flips a server's disabled flag in memory and writes it as a project override into the trusted project's mcp.json (#10277: "enable/disable in this project" — the global server keeps its global setting). Later plain enable/disable calls also target the project file (pi: entry.override is set by saveConfig). Errors when no project config target exists (untrusted project or no project scope).
func (*Manager) SignIn ¶ added in v1.0.2
func (m *Manager) SignIn(ctx context.Context, name string, prompt SignInPrompt, openURL func(string)) error
SignIn runs the interactive sign-in for the server (S12-4; pi: signIn + signInMcpServer). The prompt shows the authorization URL and collects the pasted redirect URL; openURL (optional) opens the browser. On success the pending challenge is answered and the server reconnects.
func (*Manager) SignOut ¶ added in v1.0.2
SignOut removes the server's stored OAuth credentials and disconnects (pi: signOut). Returns whether credentials were stored.
func (*Manager) StartEager ¶
func (m *Manager) StartEager()
StartEager connects every eager/keep-alive server in the background. Connection failures only mark server status; they are not fatal.
func (*Manager) Status ¶
func (m *Manager) Status() []ServerStatus
Status returns a snapshot of all servers' runtime state.
m.mu is released before acquiring any st.mu: connectLocked takes m.mu while holding st.mu, so the reverse order here would be an ABBA deadlock.
type ManagerOptions ¶
type ManagerOptions struct {
// ResolveHeaders is applied to a server's Headers at connect time, before
// any network traffic. pig wires core.ResolveHeadersOrThrow here so
// `!command` / `$env` header values work; the mcp package stays free of
// core dependencies.
ResolveHeaders func(server string, headers map[string]string) (map[string]string, error)
// HTTPClient overrides the HTTP client used for Streamable HTTP servers
// (tests point it at httptest servers via a custom transport).
HTTPClient *http.Client
// Logger receives debug output when set (pig wires a PIG_MCP_DEBUG-gated
// file writer).
Logger func(format string, args ...any)
// ClientVersion is reported to servers during initialize.
ClientVersion string
// ReapInterval is how often the idle reaper wakes (default 30s).
ReapInterval time.Duration
// DefaultIdleTimeout / DefaultRequestTimeout override the package
// defaults when config-level values are 0.
DefaultIdleTimeout time.Duration
DefaultRequestTimeout time.Duration
// ConnectTimeout bounds a single connect (default 10s).
ConnectTimeout time.Duration
// TransportFactory overrides transport construction (pig-only test seam:
// tests hand back in-memory transports; a future unix-socket transport
// would plug in here too). When nil, stdio/HTTP are built from config.
TransportFactory func(server string, cfg ServerConfig) (mcp.Transport, error)
// ProjectConfigPath is the trusted project's mcp.json — where
// SetServerDisabledInProject writes project overrides (#10277, pi's
// LoadedMcpConfig.projectConfig). Empty = unavailable (untrusted project
// or no project scope); the /mcp panel then hides the project toggle.
ProjectConfigPath string
// CredentialStore persists OAuth tokens (S12-4: <agentDir>/mcp-auth.json).
// Nil = OAuth flows unavailable; OAuth servers then fail to connect with
// a needs-sign-in error.
CredentialStore *CredentialStore
// ProviderToken reads a /login provider's token for `auth.provider`
// servers, per request (core wires ModelRegistry.GetApiKeyForProvider).
ProviderToken func(ctx context.Context, provider string) (string, error)
// ResolveConfigValue resolves `${env}` / `!command` values (core wires
// ResolveConfigValueOrThrow); used for oauth.clientSecret at flow time.
ResolveConfigValue func(server, raw string) (string, error)
}
ManagerOptions configures the Manager. All fields are optional.
type OAuthCallback ¶ added in v1.0.2
OAuthCallback is the authorization response delivered for one state.
type OAuthCallbackServer ¶ added in v1.0.2
type OAuthCallbackServer struct {
// contains filtered or unexported fields
}
OAuthCallbackServer serves the loopback redirect. waitForCallback must be called before the user is sent to the authorization URL.
func ListenOAuthCallback ¶ added in v1.0.2
func ListenOAuthCallback(host, redirectHost string, port int, path string, extraPaths []string) (*OAuthCallbackServer, error)
ListenOAuthCallback binds the loopback callback server. host serves the listener (localhost is served on 127.0.0.1; browsers fall back to it when ::1 refuses), redirectHost is the host name used in redirectURL.
func (*OAuthCallbackServer) Close ¶ added in v1.0.2
func (s *OAuthCallbackServer) Close() error
Close shuts the server down and fails every pending authorization. A browser may keep an unused connection to the callback port open (a preconnect or a spare keep-alive socket), so the remaining connections are dropped once shutdown starts instead of waiting for them to time out (pi 63ea042ce: closeAllConnections). By the time Close runs, the callback response has been sent.
func (*OAuthCallbackServer) Port ¶ added in v1.0.2
func (s *OAuthCallbackServer) Port() int
Port is the bound port.
func (*OAuthCallbackServer) RedirectURL ¶ added in v1.0.2
func (s *OAuthCallbackServer) RedirectURL() string
RedirectURL is the redirect URI the server serves (with the bound port).
func (*OAuthCallbackServer) ServeHTTP ¶ added in v1.0.2
func (s *OAuthCallbackServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*OAuthCallbackServer) WaitForCallback ¶ added in v1.0.2
func (s *OAuthCallbackServer) WaitForCallback(state string, path string, timeout time.Duration) <-chan OAuthCallback
WaitForCallback registers a pending authorization and resolves with the browser response, an error page fault, or the timeout (pi: waitForCallback; default 5 minutes).
type OAuthChallenge ¶ added in v1.0.2
type OAuthChallenge struct {
ResourceMetadataURL string
Scope string
Error string
ErrorDescription string
}
OAuthChallenge is the parsed WWW-Authenticate challenge of the 401/403 that asked for (re-)authorization (pi: OAuthChallenge).
type OAuthClientInformation ¶ added in v1.0.2
type OAuthClientInformation struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
TokenAuthMethod string `json:"token_auth_method,omitempty"` // "client_secret_basic" | "client_secret_post" | "none"
RedirectURIs []string `json:"redirect_uris,omitempty"`
ClientIDIssuedAt int64 `json:"client_id_issued_at,omitempty"`
}
OAuthClientInformation is the stored client registration (dynamic or pre-registered).
type OAuthConfig ¶ added in v1.0.2
type OAuthConfig struct {
// ClientID is a pre-registered client id. Without it, pig registers a
// client with the authorization server (dynamic client registration).
ClientID string `json:"clientId,omitempty"`
// ClientSecret may reference environment variables (`${NAME}`) or
// commands (`!cmd`); resolved at use time.
ClientSecret string `json:"clientSecret,omitempty"`
// CallbackPort pins the loopback callback server port, for clients
// registered with a fixed redirect URI.
CallbackPort int `json:"callbackPort,omitempty"`
// CallbackURL is the registered loopback redirect URI, sent exactly as
// written (http on localhost/127.0.0.1/[::1], no query or fragment).
CallbackURL string `json:"callbackUrl,omitempty"`
// Scope lists the scopes to request, separated by spaces. Default: the
// scopes the server advertises.
Scope string `json:"scope,omitempty"`
// ClientName is the `client_name` sent with dynamic client registration.
// Default: "pig".
ClientName string `json:"clientName,omitempty"`
// ClientRegistration selects how pig identifies itself without a
// clientId. "auto" (the default) behaves like "dcr" in pig: pi's "cimd"
// relies on pi.dev-hosted Client ID Metadata Documents, which identify
// pi and do not exist for pig, so "cimd" stays rejected (pi v1.5.0
// #11426).
ClientRegistration string `json:"clientRegistration,omitempty"`
// AuthServerMetadataURL overrides discovery with a configured
// authorization server metadata document (RFC 8414 / OIDC), for servers
// that advertise a wrong authorization server or none. Trusted as
// configured; must use https, except on loopback hosts.
AuthServerMetadataURL string `json:"authServerMetadataUrl,omitempty"`
}
OAuthConfig is the per-server OAuth client configuration.
type OAuthServerState ¶ added in v1.0.2
type OAuthServerState struct {
ServerURL string `json:"serverUrl"`
ClientInformation *OAuthClientInformation `json:"clientInformation,omitempty"`
Tokens *OAuthTokens `json:"tokens,omitempty"`
// TokensExpireAt is when the access token expires (ms since epoch), from
// ExpiresIn at save time.
TokensExpireAt int64 `json:"tokensExpireAt,omitempty"`
TokenEndpoint string `json:"tokenEndpoint,omitempty"` // refreshes reuse the discovered endpoint
Scope string `json:"scope,omitempty"` // scope granted/requested at last sign-in
Resource string `json:"resource,omitempty"` // RFC 8707 resource indicator sent with the flow
}
OAuthServerState is one server's stored OAuth state.
type OAuthSettings ¶ added in v1.0.2
type OAuthSettings struct {
ClientID string
ClientSecret string
// CallbackPort pins the loopback callback server's port (0 = free port).
CallbackPort int
// CallbackURL is a registered loopback redirect URI sent exactly as
// written; empty = the callback server's dynamic URL.
CallbackURL string
Scope string
ClientName string
// AuthServerMetadataURL overrides discovery (pi d850edee9): the document
// is trusted as configured and its issuer is not checked.
AuthServerMetadataURL string
}
OAuthSettings are the per-server oauth.* config values with the client secret already resolved.
type OAuthTokens ¶ added in v1.0.2
type OAuthTokens struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in,omitempty"`
Scope string `json:"scope,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
IDToken string `json:"id_token,omitempty"`
}
OAuthTokens is a token response (pi OAuthTokens).
type OAuthTransportHandler ¶ added in v1.0.2
type OAuthTransportHandler struct {
// contains filtered or unexported fields
}
OAuthTransportHandler implements github.com/modelcontextprotocol/go-sdk/auth OAuthHandler for one OAuth-protected server. It is safe for concurrent use.
func (*OAuthTransportHandler) Authorize ¶ added in v1.0.2
func (h *OAuthTransportHandler) Authorize(ctx context.Context, req *http.Request, resp *http.Response) error
Authorize implements auth.OAuthHandler: called by the transport on 401 (or a 403 with an insufficient_scope challenge) once per request. A nil return makes the transport retry the request with whatever credentials this left behind.
func (*OAuthTransportHandler) TokenSource ¶ added in v1.0.2
func (h *OAuthTransportHandler) TokenSource(ctx context.Context) (oauth2.TokenSource, error)
TokenSource implements auth.OAuthHandler: the token for outgoing requests. A nil source sends no Authorization header.
type ServerConfig ¶
type ServerConfig struct {
// stdio transport
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
Cwd string `json:"cwd,omitempty"`
// Streamable HTTP transport
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
// Lifecycle: "lazy" (default) | "eager" | "keep-alive" | "lazy-keep-alive".
// keep-alive variants are never reaped for idleness.
Lifecycle string `json:"lifecycle,omitempty"`
// IdleTimeoutMs overrides the idle reap delay (DefaultIdleTimeoutMs when 0).
IdleTimeoutMs int `json:"idleTimeoutMs,omitempty"`
// RequestTimeoutMs overrides the per-request timeout
// (DefaultRequestTimeoutMs when 0).
RequestTimeoutMs int `json:"requestTimeoutMs,omitempty"`
// IncludeTools/ExcludeTools are glob patterns matched against the raw tool
// name (path.Match semantics). Exclude wins.
IncludeTools []string `json:"includeTools,omitempty"`
ExcludeTools []string `json:"excludeTools,omitempty"`
// ToolPrefix is prepended to tool names for display (and accepted back on
// call). Empty = no prefix.
ToolPrefix string `json:"toolPrefix,omitempty"`
// Disabled turns the server off without deleting its entry (pig-only
// field; the /mcp panel toggles it and writes it back to the source
// file). Disabled servers never connect and contribute no tools.
Disabled bool `json:"disabled,omitempty"`
// OAuth configures the authorization-code flow for servers that do not
// support dynamic client registration or need specific scopes (pi:
// McpOAuthConfig). Only meaningful for HTTP servers.
OAuth *OAuthConfig `json:"oauth,omitempty"`
// Auth sends a /login provider's token instead of running the OAuth flow
// (pi 91f9f3b5d). Only allowed in global files, never project files.
Auth *MCPAuthConfig `json:"auth,omitempty"`
}
ServerConfig describes one MCP server. A server is stdio (Command set) or HTTP (URL set), never both.
type ServerStatus ¶
type ServerStatus struct {
Name string `json:"name"`
Transport string `json:"transport"` // "stdio" | "http"
Lifecycle string `json:"lifecycle"`
Status string `json:"status"` // "connected" | "disconnected" | "connecting" | "error" | "disabled"
ToolCount int `json:"toolCount,omitempty"`
PID int `json:"pid,omitempty"`
LastError string `json:"lastError,omitempty"`
IdleMs int64 `json:"idleMs,omitempty"` // ms since last use, when connected
Disabled bool `json:"disabled,omitempty"`
SourcePath string `json:"sourcePath,omitempty"` // winning config file (for the /mcp panel's write-back)
// OverridePath is the project file overriding this server (empty = none;
// #10277 — plain enable/disable then writes there, not the source).
OverridePath string `json:"overridePath,omitempty"`
// ProjectOverridable reports whether "toggle in this project" is offered
// for this server: a project mcp.json target exists, the server is not
// already overridden, and its definition does not live in the project
// file itself.
ProjectOverridable bool `json:"projectOverridable,omitempty"`
// OAuthURL is the server URL when the server authenticates with OAuth
// (S12-4; the /mcp panel offers sign-in for these).
OAuthURL string `json:"oauthUrl,omitempty"`
}
ServerStatus is a snapshot of one server's runtime state (for the `status` action of the proxy tool and future /mcp UI).
type SignInPrompt ¶ added in v1.0.2
type SignInPrompt interface {
ShowAuthorizationURL(url string)
PromptForRedirectURL(ctx context.Context) (string, error)
}
SignInPrompt is the user-interaction channel of a browser sign-in (pi: McpSignInPrompt). ShowAuthorizationURL displays the URL and opens the browser. PromptForRedirectURL asks for the browser-address-bar URL for when the browser cannot reach the loopback callback (SSH); it must return promptly once ctx is cancelled — the callback arrival cancels it.
type ToolCallOutput ¶
ToolCallOutput is the raw result of one tool invocation.
type ToolInfo ¶
type ToolInfo struct {
Server string `json:"server"`
Name string `json:"name"` // display name: ToolPrefix + raw name
RawName string `json:"rawName"` // name as the server knows it
Description string `json:"description"`
Schema any `json:"schema,omitempty"` // JSON Schema (map form)
}
ToolInfo describes one discovered tool, prefixed for display.