mcp

package
v0.107.42 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UIResourceScheme prefixes every UI resource URI.
	UIResourceScheme = "ui://"
	// MaxUIResourceBytes bounds the HTML read for one UI resource.
	MaxUIResourceBytes = 4 << 20
)
View Source
const (
	ToolSearchName = "ToolSearch"
)

Variables

View Source
var (
	// ErrUIResourceNotFound: no usable server or tool declares the resource.
	ErrUIResourceNotFound = errors.New("MCP UI resource not found")
	// ErrUIResourceInvalid: the server's reply is not a usable HTML resource.
	ErrUIResourceInvalid = errors.New("MCP UI resource is not usable HTML")
)

Functions

func FilterRequestTools added in v0.107.0

func FilterRequestTools(activation *ToolActivation) func([]tools.Tool) []tools.Tool

func FromConfigMap

func FromConfigMap(in map[string]config.MCPServer) map[string]ServerConfig

func ParseToolName

func ParseToolName(name string) (srvKey, tool string, ok bool)

func Serve

func Serve(ctx context.Context, version string) error

func ToolName

func ToolName(server, tool string) string

Types

type CredentialBridge added in v0.107.0

type CredentialBridge func(context.Context, string) (string, error)

CredentialBridge resolves a native-host credential without moving the secret into the K-brain settings file or HTTP API.

type LiveAuth added in v0.107.0

type LiveAuth struct {
	Type          string `json:"type"`
	Scope         string `json:"scope,omitempty"`
	ClientID      string `json:"clientId,omitempty"`
	CredentialRef string `json:"credentialRef,omitempty"`
}

type LiveManager added in v0.107.0

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

func NewLiveManager added in v0.107.0

func NewLiveManager(ctx context.Context, path string, settings LiveSettings) (*LiveManager, error)

func OpenLiveManager added in v0.107.0

func OpenLiveManager(ctx context.Context, path string, fallback map[string]ServerConfig) (*LiveManager, error)

func (*LiveManager) Close added in v0.107.0

func (m *LiveManager) Close()

func (*LiveManager) ReadUIResource added in v0.107.42

func (m *LiveManager) ReadUIResource(ctx context.Context, cwd, serverID, uri string) (UIResource, error)

ReadUIResource reads the UI resource uri from server serverID for a session in cwd. Only a resource that one of the server's tools declares, and whose policy does not deny that tool, is read: the route cannot be used to read arbitrary resources.

func (*LiveManager) Reload added in v0.107.0

func (m *LiveManager) Reload() error

func (*LiveManager) Replace added in v0.107.0

func (m *LiveManager) Replace(ctx context.Context, settings LiveSettings) error

func (*LiveManager) Search added in v0.107.0

func (m *LiveManager) Search(ctx context.Context, query string, cwd string, selected []string, limit int) []tools.Tool

func (*LiveManager) SetCredentialBridge added in v0.107.0

func (m *LiveManager) SetCredentialBridge(bridge CredentialBridge)

func (*LiveManager) SetOnChange added in v0.107.0

func (m *LiveManager) SetOnChange(fn func())

func (*LiveManager) SetSave added in v0.107.0

func (m *LiveManager) SetSave(fn func(LiveSettings) error)

func (*LiveManager) Settings added in v0.107.0

func (m *LiveManager) Settings() LiveSettings

func (*LiveManager) Statuses added in v0.107.0

func (m *LiveManager) Statuses() []LiveStatus

func (*LiveManager) ToolUI added in v0.107.42

func (m *LiveManager) ToolUI(cwd, toolName string) (ToolUI, bool)

ToolUI returns the UI resource the model-facing MCP tool toolName declares, when its server is enabled and allowed from cwd and its policy does not deny the tool.

func (*LiveManager) ToolUIs added in v0.107.42

func (m *LiveManager) ToolUIs(cwd string, names []string) map[string]ToolUI

ToolUIs maps the model-facing names of the tools in list that declare a UI resource (see ToolUI) to that resource.

func (*LiveManager) ToolsFor added in v0.107.0

func (m *LiveManager) ToolsFor(ctx context.Context, cwd string, selected []string) []tools.Tool

func (*LiveManager) ToolsForTurn added in v0.107.0

func (m *LiveManager) ToolsForTurn(ctx context.Context, cwd string, selected []string, activation *ToolActivation) ([]tools.Tool, func([]tools.Tool) []tools.Tool)

type LiveServer added in v0.107.0

type LiveServer struct {
	ID             string            `json:"id"`
	Description    string            `json:"description,omitempty"`
	DocsURL        string            `json:"docsUrl,omitempty"`
	Enabled        bool              `json:"enabled"`
	Transport      string            `json:"transport"`
	Command        string            `json:"command,omitempty"`
	Args           []string          `json:"args,omitempty"`
	URL            string            `json:"url,omitempty"`
	Env            map[string]string `json:"env,omitempty"`
	Cwd            string            `json:"cwd,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	TimeoutMs      int               `json:"timeoutMs,omitempty"`
	WorkspaceRoots []string          `json:"workspaceRoots,omitempty"`
	Policy         map[string]string `json:"policy,omitempty"`
	Auth           *LiveAuth         `json:"auth,omitempty"`
}

type LiveSettings added in v0.107.0

type LiveSettings struct {
	Servers  []LiveServer `json:"servers"`
	Selected []string     `json:"selected,omitempty"`
}

type LiveStatus added in v0.107.0

type LiveStatus struct {
	LiveServer
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
	Tools  int    `json:"tools"`
}

type Manager

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

func NewManager

func NewManager(cfgs map[string]ServerConfig) *Manager

func (*Manager) AddServers

func (m *Manager) AddServers(ctx context.Context, cfgs map[string]ServerConfig)

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Config

func (m *Manager) Config(name string) (ServerConfig, bool)

func (*Manager) Disable

func (m *Manager) Disable(name string) bool

func (*Manager) Enable

func (m *Manager) Enable(name string) bool

func (*Manager) EnableElicitation added in v0.107.26

func (m *Manager) EnableElicitation()

EnableElicitation makes the manager declare the MCP elicitation capability (form mode) and route servers' elicitations to the front end in the tool call's context (internal/elicit). Call it before Start; a manager without it declares no elicitation capability, so servers cannot ask.

func (*Manager) FireOnChangeForTest

func (m *Manager) FireOnChangeForTest()

func (*Manager) InstructionsBlock

func (m *Manager) InstructionsBlock() string

func (*Manager) Reconnect

func (m *Manager) Reconnect(name string) bool

func (*Manager) RemoveServers

func (m *Manager) RemoveServers(names ...string)

func (*Manager) SetOnChange

func (m *Manager) SetOnChange(fn func())

func (*Manager) Start

func (m *Manager) Start(ctx context.Context)

func (*Manager) Statuses

func (m *Manager) Statuses() []Server

func (*Manager) Tools

func (m *Manager) Tools() []tools.Tool

type ProbeResult

type ProbeResult struct {
	Server
	Elapsed   time.Duration
	ToolNames []string
}

func Probe

func Probe(ctx context.Context, name string, cfg ServerConfig) ProbeResult

type Server

type Server struct {
	Name   string
	Status Status
	Note   string
	Err    string
	Tools  int
	Source string
}

type ServerConfig

type ServerConfig struct {
	Command []string          `json:"command,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"`

	Enabled        *bool  `json:"enabled,omitempty"`
	Note           string `json:"note,omitempty"`
	StartupTimeout int    `json:"startupTimeout,omitempty"`
	ToolTimeout    int    `json:"toolTimeout,omitempty"`

	Source string `json:"-"`
}

func (ServerConfig) Disabled

func (c ServerConfig) Disabled() bool

func (ServerConfig) Remote

func (c ServerConfig) Remote() bool

func (ServerConfig) StartupTimeoutDuration

func (c ServerConfig) StartupTimeoutDuration() time.Duration

func (ServerConfig) ToolTimeoutDuration

func (c ServerConfig) ToolTimeoutDuration() time.Duration

func (ServerConfig) Valid

func (c ServerConfig) Valid() string

type Status

type Status int
const (
	StatusDisabled Status = iota
	StatusConnecting
	StatusReady
	StatusFailed
)

func (Status) String

func (s Status) String() string

type ToolActivation added in v0.107.0

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

func NewToolActivation added in v0.107.0

func NewToolActivation() *ToolActivation

func (*ToolActivation) Add added in v0.107.0

func (a *ToolActivation) Add(name string)

func (*ToolActivation) Has added in v0.107.0

func (a *ToolActivation) Has(name string) bool

type ToolUI added in v0.107.42

type ToolUI struct {
	// ServerID is the configured server (LiveServer.ID).
	ServerID string
	// URI is the ui:// resource.
	URI string
}

ToolUI is the UI resource a model-facing MCP tool declares.

type UIResource added in v0.107.42

type UIResource struct {
	URI      string
	MIMEType string
	HTML     string
	// ConnectDomains and ResourceDomains are the https origins the resource's
	// _meta.ui.csp asks to reach (fetch/WebSocket) and to load scripts,
	// styles, images, fonts and media from. Entries that are not plain https
	// origins are dropped.
	ConnectDomains  []string
	ResourceDomains []string
}

UIResource is a UI resource's HTML as read from its server.

Directories

Path Synopsis
Package mcptest provides a minimal MCP server for tests that need to control the exact bytes a server sends, such as an elicitation's requestedSchema with its property order or a schema outside the subset.
Package mcptest provides a minimal MCP server for tests that need to control the exact bytes a server sends, such as an elicitation's requestedSchema with its property order or a schema outside the subset.

Jump to

Keyboard shortcuts

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