Help us shape the future of Go! Take the 2026 Go Developer Survey

mcp

package
v0.19.11 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 43 Imported by: 0

README

Bundled MCP extension

An MCP client built on the official Go SDK and registered through the same native ExtensionAPI as every other extension, following pi 1.0's built-in MCP integration. MCP does not enter the agent loop, provider layer, or built-in tool registry directly. goExtensions.mcp: false or --no-extensions turns it off.

mcp.json

Servers are configured in mcp.json in the agent directory (~/.orb/agent/mcp.json) and, once the project is trusted, .orb/mcp.json in the project, whose entries replace global ones of the same name. The mcpServers shape is the one other MCP clients use, so their configurations copy over. orb mcp add|remove|list edits and checks the files without starting a session.

{
  "mcpServers": {
    "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] },
    "docs": {
      "url": "https://example.com/mcp",
      "headers": { "Authorization": "Bearer ${DOCS_TOKEN}" },
      "exposure": "direct",
      "description": "Product documentation search"
    },
    "off": { "command": "another-server", "enabled": false }
  }
}

command selects stdio and takes args, env and cwd (relative to the session's directory; ~ expands); url selects streamable HTTP and takes headers. Header and env values may be ${NAME} or !command. timeout is the per-request timeout in seconds (default 60), reset by progress notifications. Server names use letters, digits, _ and -; names that differ only in - and _ would share a tool namespace and are rejected. Invalid entries are reported once (and by /mcp) while the others load.

exposure says how the model reaches a server's tools, and toolExposure overrides it per tool, by exact name or * pattern:

  • codemode (default): Orb has no codemode, so these behave as deferred.
  • deferred: declared once tool_search loads them, then called directly.
  • direct: declared like built-in tools.
  • hidden: registered but unreachable.

Sign-in

An HTTP server without an Authorization header signs in with OAuth when it answers 401. Connections never open a browser: they send the stored token and refresh it near expiry or after a 401, and otherwise the server shows "needs sign-in" until /mcp login [server] or orb mcp login <server> runs the authorization code flow: protected resource and authorization server discovery, dynamic client registration (client_name from oauth.clientName, default orb), PKCE, the RFC 8707 resource and the RFC 9207 iss check, against a loopback callback whose redirect URL can also be pasted when the browser runs elsewhere. A server that asks for more scope (insufficient_scope) gets a new sign-in that keeps the scope granted so far. oauth.clientId and clientSecret use a pre-registered client, callbackPort/callbackUrl fix the redirect URI, scope sets the scopes, and authServerMetadataUrl replaces discovery for servers that advertise the wrong authorization server. Credentials live in mcp-auth.json in the agent directory, keyed by server name and URL in the shape pi writes, so both share them; refreshes are serialized across processes, and sign-ins done in another process (say orb mcp login run by the agent) are picked up on the next turn. /mcp logout and orb mcp logout delete them.

"auth": {"provider": "<p>"} sends the token of an orb login provider instead. Only the global mcp.json may use it, so a repository cannot pick where a credential goes, and the URL must be https (http only on loopback).

Lifecycle and tools

Servers connect in the background when a session starts. The first prompt waits up to 10 seconds for servers with direct tools; tool_search waits for every server still connecting. Each prompt carries an mcp_servers system prompt section listing the servers whose tools are not declared, with their descriptions (or instructions) cut to fit 4096 characters. A server that fails is reported once; /mcp shows every server and /mcp reconnect [server] reconnects. A call that finds the connection dead marks the server failed and the next call reconnects.

Tools are named mcp__<server>__<tool> with everything but [A-Za-z0-9_] turned into _; names over 64 characters or shared by several tools get an 8-hex hash suffix. Each tool carries its server's namespace, its annotations' hints, and a CallToolResult output schema: the result's structuredContent is the whole MCP result without _meta, and isError results are error results. Tools a server stops offering are re-registered hidden.

tool_search (the tool-search row) is registered for every session and activated when a server has deferred tools. It ranks the deferred tools that are not active with BM25 over their names, descriptions, schema text and namespace, and activates the matches, so the transcript records them and resume restores them; tools of a restored loadout that register late (servers still connecting) turn on when they register. Providers with native tool search receive later additions as deferred declarations.

Serving a session's tools

serve/ is the other direction: an MCP server offering a session's tools to another agent harness (claude-sessions today). The harness integration offers the tools its harness lacks and carries the messages, over its own channel with a Pipe or over any go-sdk transport; the list follows the session's tools with tools/list_changed. Each call runs through engine.RunToolCall, so argument validation and the session's tool-call hooks, the permission policy among them, apply as in Orb's own loop. It depends on engine and the go-sdk only.

Documentation

Overview

Package mcp implements orb's bundled, settings-driven MCP extension. It is dormant when no enabled servers are configured and exposes remote tools only through the native extension API.

Index

Constants

View Source
const (

	// MCPServersSection is the system prompt section listing servers whose tools are not declared.
	MCPServersSection = "mcp_servers"
)
View Source
const ToolSearchName = "tool_search"

ToolSearchName is the tool that loads deferred tools, such as MCP servers'.

Variables

View Source
var ErrSignInCancelled = errSignInCancelled

ErrSignInCancelled reports a sign-in the user abandoned or did not finish in time.

Functions

func AddServer added in v0.14.0

func AddServer(path, name string, config ServerConfig) (bool, error)

AddServer adds or replaces a server in an mcp.json, creating the file, and reports whether it replaced one.

func Extension added in v0.14.0

func Extension(agentDir string, supplied ...Entry) extensions.Factory

Extension is the MCP integration. When a session starts it reads mcp.json (the agent directory's, and the project's once trusted), adds the servers its client supplied, and connects them in the background.

func GlobalPath added in v0.14.0

func GlobalPath(agentDir string) string

GlobalPath and ProjectPath are the mcp.json files.

func Login added in v0.14.0

func Login(ctx context.Context, cwd, agentDir string, entry Entry, show func(string), paste func(context.Context) (string, error)) (tools int, already bool, err error)

Login signs a server in outside a session, unless it already accepts the stored credentials, and reports the tools it then offers. show receives the authorization URL; paste asks for the redirect URL and ends with ctx.

func Namespace added in v0.14.0

func Namespace(server string) string

Namespace is the namespace of a server's tools: mcp__<server> with - as _.

func ProjectPath added in v0.14.0

func ProjectPath(cwd string) string

func RemoveCredentials added in v0.14.0

func RemoveCredentials(agentDir, name, serverURL string) (bool, error)

RemoveCredentials deletes a server's stored OAuth credentials outside a session.

func RemoveServer added in v0.14.0

func RemoveServer(path, name string) (bool, error)

RemoveServer removes a server and reports whether the file defined it.

func ToolSearchExtension added in v0.14.0

func ToolSearchExtension() extensions.Factory

ToolSearchExtension registers tool_search inactive; the MCP integration activates it when servers have deferred tools. Loading a tool activates it, so the transcript records it and resume restores it.

func Validate added in v0.14.0

func Validate(name string, config *ServerConfig) error

Validate checks one server entry, aliases resolved, against the mcpServers shape.

Types

type Entry added in v0.14.0

type Entry struct {
	Name   string
	Config ServerConfig
	// Source is the mcp.json that defines the entry; Scope is "global" or "project".
	Source string
	Scope  string
}

Entry is a configured server and where it came from.

func Load added in v0.14.0

func Load(agentDir, cwd string, projectTrusted bool) ([]Entry, []string)

Load reads the global and, when trusted, the project mcp.json. Disabled servers are included so they can be enabled again; problems come back as messages while the valid entries still load.

type Exposure added in v0.14.0

type Exposure string

Exposure is how the model reaches a server's tools:

  • codemode (default): Orb has no codemode, so these are reached as deferred.
  • deferred: declared once tool_search loads them, then called directly.
  • direct: declared like built-in tools.
  • hidden: registered but unreachable.
const (
	ExposureCodemode Exposure = "codemode"
	ExposureDeferred Exposure = "deferred"
	ExposureDirect   Exposure = "direct"
	ExposureHidden   Exposure = "hidden"
)

type Manager

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

Manager owns all MCP client sessions for one coding-agent session.

func (*Manager) Close

func (manager *Manager) Close() error

Close stops every MCP session. It is idempotent.

func (*Manager) Reconnect

func (manager *Manager) Reconnect(ctx context.Context, name string) error

Reconnect closes and recreates one server session. An empty name reconnects all enabled servers in name order.

func (*Manager) SignIn added in v0.14.0

func (manager *Manager) SignIn(ctx context.Context, name string, prompt signInPrompt) error

SignIn signs a server in through the browser and reconnects it.

func (*Manager) SignOut added in v0.14.0

func (manager *Manager) SignOut(name string) (bool, error)

SignOut deletes a server's stored credentials and disconnects it; it reports whether there were any.

func (*Manager) Status

func (manager *Manager) Status() []ServerStatus

type OAuthConfig added in v0.14.0

type OAuthConfig struct {
	// ClientID is a pre-registered client; without it Orb registers one.
	ClientID string `json:"clientId,omitempty"`
	// ClientSecret may reference ${NAME} or !command.
	ClientSecret string `json:"clientSecret,omitempty"`
	// CallbackPort fixes the loopback port; without CallbackURL the redirect
	// URI is http://127.0.0.1:<port>/callback.
	CallbackPort int `json:"callbackPort,omitempty"`
	// CallbackURL is the redirect URI registered for ClientID: http on
	// localhost, 127.0.0.1 or [::1]; without a port, CallbackPort or a free one.
	CallbackURL string `json:"callbackUrl,omitempty"`
	// Scope is the space-separated scopes to request; default the advertised ones.
	Scope string `json:"scope,omitempty"`
	// ClientName is sent with dynamic client registration. Default: orb.
	ClientName string `json:"clientName,omitempty"`
	// AuthServerMetadataURL replaces discovery through the server; trusted as
	// configured, https except on loopback hosts.
	AuthServerMetadataURL string `json:"authServerMetadataUrl,omitempty"`
}

OAuthConfig configures OAuth for servers without dynamic client registration.

type ProviderAuth added in v0.14.0

type ProviderAuth struct {
	Provider string `json:"provider"`
}

ProviderAuth sends the token of an `orb login` provider.

type ServerConfig

type ServerConfig struct {
	Type    string            `json:"type,omitempty"`
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	// CWD resolves relative paths against the session's working directory.
	CWD     string            `json:"cwd,omitempty"`
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	OAuth   *OAuthConfig      `json:"oauth,omitempty"`
	Auth    *ProviderAuth     `json:"auth,omitempty"`
	// Exposure defaults to codemode.
	Exposure Exposure `json:"exposure,omitempty"`
	// ToolExposure overrides Exposure for single tools, by the name the server
	// offers or a pattern where * matches anything; an exact name wins, then
	// the first matching pattern.
	ToolExposure ToolExposures `json:"toolExposure,omitempty"`
	// Description says what the server offers: the mcp_servers prompt section
	// lists it and tool search ranks the server's tools by it.
	Description string `json:"description,omitempty"`
	Enabled     *bool  `json:"enabled,omitempty"`
	// Timeout is the per-request timeout in seconds; progress resets it. Default 60.
	Timeout float64 `json:"timeout,omitempty"`
}

ServerConfig is one entry of mcpServers.

func (ServerConfig) ExposureOf added in v0.14.0

func (config ServerConfig) ExposureOf() Exposure

ExposureOf is a server's exposure, the default codemode when unset.

func (ServerConfig) IsEnabled added in v0.14.0

func (config ServerConfig) IsEnabled() bool

IsEnabled reports a server that connects; enabled false keeps the entry.

func (ServerConfig) IsHTTP added in v0.14.0

func (config ServerConfig) IsHTTP() bool

IsHTTP reports a streamable HTTP server.

func (ServerConfig) ToolExposureOf added in v0.14.0

func (config ServerConfig) ToolExposureOf(tool string) Exposure

ToolExposureOf is the exposure of one tool: its toolExposure entry, else the server's.

func (ServerConfig) UsesOAuth added in v0.14.0

func (config ServerConfig) UsesOAuth() bool

UsesOAuth reports a server that signs in with OAuth: HTTP without an Authorization header or auth.provider.

type ServerState

type ServerState string
const (
	ServerConnecting ServerState = "connecting"
	ServerConnected  ServerState = "connected"
	ServerFailed     ServerState = "failed"
	ServerNeedsAuth  ServerState = "needs-auth"
	ServerDisabled   ServerState = "disabled"
	ServerStopped    ServerState = "stopped"
)

type ServerStatus

type ServerStatus struct {
	Name      string
	Transport string
	Target    string // the command line or URL the server was configured with
	Exposure  Exposure
	Scope     string
	State     ServerState
	Tools     []string
	Error     string
}

func Probe added in v0.14.0

func Probe(ctx context.Context, cwd, agentDir string, entries []Entry) []ServerStatus

Probe connects each enabled server once, outside a session, and reports the servers with the tools they offer.

type ToolExposureRule added in v0.14.0

type ToolExposureRule struct {
	Tool     string
	Exposure Exposure
}

type ToolExposures added in v0.14.0

type ToolExposures []ToolExposureRule

ToolExposures keeps toolExposure's entries in file order, which decides among patterns.

func (ToolExposures) MarshalJSON added in v0.14.0

func (rules ToolExposures) MarshalJSON() ([]byte, error)

func (*ToolExposures) UnmarshalJSON added in v0.14.0

func (rules *ToolExposures) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
Package cli is `orb mcp`: it configures and checks MCP servers and signs in to OAuth servers without starting a session.
Package cli is `orb mcp`: it configures and checks MCP servers and signs in to OAuth servers without starting a session.
Package serve offers an Orb session's tools to another agent harness over MCP, the protocol harnesses take outside tools through.
Package serve offers an Orb session's tools to another agent harness over MCP, the protocol harnesses take outside tools through.

Jump to

Keyboard shortcuts

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