mcp

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHealthCheckTimeout     = errors.New("timed out waiting for MCP server to be ready")
	ErrHealthCheckFailed      = errors.New("MCP server is not healthy")
	ErrPodCrashLoopBackOff    = errors.New("pod is in CrashLoopBackOff state")
	ErrImagePullFailed        = errors.New("failed to pull container image")
	ErrPodSchedulingFailed    = errors.New("pod could not be scheduled")
	ErrPodConfigurationFailed = errors.New("pod configuration is invalid")
)

Functions

func ApplyToolOverrides added in v0.15.0

func ApplyToolOverrides(tools []otypes.MCPServerTool, toolOverrides []otypes.ToolOverride) []otypes.MCPServerTool

ApplyToolOverrides applies ToolOverrides to a component's tool array, filtering out disabled tools and applying name/description overrides. If overrides are present, they act as an allowlist - only tools explicitly listed are included.

func ComputeK8sSettingsHash added in v0.13.0

func ComputeK8sSettingsHash(settings v1.K8sSettingsSpec) string

ComputeK8sSettingsHash computes a hash of K8s settings for change detection

func ConvertTools added in v0.9.0

func ConvertTools(tools []mcp.Tool, allowedTools, unsupportedTools []string) ([]otypes.MCPServerTool, error)

Types

type Client

type Client struct {
	*nmcp.Client
	ID     string
	Config ServerConfig
	// contains filtered or unexported fields
}

type ComponentServer added in v0.15.0

type ComponentServer struct {
	Name  string               `json:"name"`
	URL   string               `json:"url"`
	Tools []types.ToolOverride `json:"tools"`
}

type Config

type Config struct {
	MCPServers map[string]ServerConfig `json:"mcpServers"`
}

type ErrNotSupportedByBackend added in v0.9.0

type ErrNotSupportedByBackend struct {
	Feature, Backend string
}

func (*ErrNotSupportedByBackend) Error added in v0.9.0

func (e *ErrNotSupportedByBackend) Error() string

type File

type File struct {
	Data   string `json:"data"`
	EnvKey string `json:"envKey"`
}

type GlobalTokenStore

type GlobalTokenStore interface {
	ForUserAndMCP(userID, mcpID string) nmcp.TokenStorage
}

type Options

type Options struct {
	MCPBaseImage            string   `usage:"The base image to use for MCP containers" default:"ghcr.io/obot-platform/mcp-images/phat:main"`
	MCPHTTPWebhookBaseImage string   `` /* 138-byte string literal not displayed */
	MCPRemoteShimBaseImage  string   `usage:"The base image to use for MCP remote shim containers" default:"ghcr.io/nanobot-ai/nanobot:v0.0.45"`
	MCPNamespace            string   `usage:"The namespace to use for MCP containers" default:"obot-mcp"`
	MCPClusterDomain        string   `usage:"The cluster domain to use for MCP containers" default:"cluster.local"`
	DisallowLocalhostMCP    bool     `usage:"Allow MCP containers to run on localhost"`
	MCPRuntimeBackend       string   `` /* 126-byte string literal not displayed */
	MCPImagePullSecrets     []string `usage:"The name of the image pull secret to use for pulling MCP images"`

	// Kubernetes settings from Helm
	MCPK8sSettingsAffinity    string `usage:"Affinity rules for MCP server pods (JSON)" env:"OBOT_SERVER_MCPK8S_SETTINGS_AFFINITY"`
	MCPK8sSettingsTolerations string `usage:"Tolerations for MCP server pods (JSON)" env:"OBOT_SERVER_MCPK8S_SETTINGS_TOLERATIONS"`
	MCPK8sSettingsResources   string `usage:"Resource requests/limits for MCP server pods (JSON)" env:"OBOT_SERVER_MCPK8S_SETTINGS_RESOURCES"`

	// Obot service configuration for constructing internal service FQDN
	ServiceName      string `usage:"The Kubernetes service name for the obot server" env:"OBOT_SERVER_SERVICE_NAME"`
	ServiceNamespace string `usage:"The Kubernetes namespace where the obot server runs" env:"OBOT_SERVER_SERVICE_NAMESPACE"`

	// Audit log configuration
	MCPAuditLogPersistIntervalSeconds int `usage:"The interval in seconds to persist MCP audit logs to the database" default:"5"`
	MCPAuditLogsPersistBatchSize      int `usage:"The number of MCP audit logs to persist in a single batch" default:"1000"`
}

type ServerConfig

type ServerConfig struct {
	Runtime types.Runtime `json:"runtime"`

	// uvx/npx based configuration.
	Command string   `json:"command"`
	Args    []string `json:"args"`
	Env     []string `json:"env"`
	Files   []File   `json:"files"`

	// Remote configuration.
	URL     string   `json:"url"`
	Headers []string `json:"headers"`

	// Containerized configuration.
	ContainerImage string `json:"containerImage"`
	ContainerPort  int    `json:"containerPort"`
	ContainerPath  string `json:"containerPath"`

	// Composite configuration.
	Components []ComponentServer `json:"components"`

	Scope                string `json:"scope"`
	UserID               string `json:"userID"`
	MCPServerNamespace   string `json:"mcpServerNamespace"`
	MCPServerName        string `json:"mcpServerName"`
	MCPCatalogName       string `json:"mcpCatalogName"`
	MCPCatalogEntryName  string `json:"mcpCatalogEntryName"`
	MCPServerDisplayName string `json:"mcpServerDisplayName"`

	ProjectMCPServer   bool `json:"projectMCPServer"`
	ComponentMCPServer bool `json:"componentMCPServer"`

	Issuer    string   `json:"issuer"`
	JWKS      string   `json:"jwks"`
	Audiences []string `json:"audiences"`

	TokenExchangeEndpoint     string `json:"tokenExchangeEndpoint"`
	TokenExchangeClientID     string `json:"tokenExchangeClientID"`
	TokenExchangeClientSecret string `json:"tokenExchangeClientSecret"`

	AuditLogToken    string `json:"auditLogToken"`
	AuditLogEndpoint string `json:"auditLogEndpoint"`
	AuditLogMetadata string `json:"auditLogMetadata"`
}

func CompositeServerToServerConfig added in v0.15.0

func CompositeServerToServerConfig(mcpServer v1.MCPServer, components []v1.MCPServer, instances []v1.MCPServerInstance, audiences []string, issuer, jwks, userID, scope, mcpCatalogName string, credEnv, tokenExchangeCredEnv map[string]string) (ServerConfig, []string, error)

func ProjectServerToConfig

func ProjectServerToConfig(projectMCPServer v1.ProjectMCPServer, publicBaseURL, internalBaseURL, userID string) (ServerConfig, error)

func ServerToServerConfig

func ServerToServerConfig(mcpServer v1.MCPServer, audiences []string, issuer, jwks, userID, scope, mcpCatalogName string, credEnv, secretsCred map[string]string) (ServerConfig, []string, error)

func SystemServerToServerConfig added in v0.15.0

func SystemServerToServerConfig(systemServer v1.SystemMCPServer, credEnv map[string]string) (ServerConfig, []string, error)

SystemServerToServerConfig converts a v1.SystemMCPServer to a ServerConfig for deployment

type SessionManager

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

func NewSessionManager

func NewSessionManager(ctx context.Context, tokenService TokenService, baseURL string, httpListenPort int, opts Options, localK8sConfig *rest.Config, obotStorageClient storage.Client) (*SessionManager, error)

func (*SessionManager) ClientForMCPServerForOAuthCheck added in v0.15.0

func (sm *SessionManager) ClientForMCPServerForOAuthCheck(ctx context.Context, clientScope string, serverConfig ServerConfig, opt nmcp.ClientOption) (*Client, error)

func (*SessionManager) Close

func (sm *SessionManager) Close() error

Close does nothing with the deployments and services. It just closes the local session. This should return an error to satisfy the GPTScript loader interface.

func (*SessionManager) CloseClient

func (sm *SessionManager) CloseClient(ctx context.Context, server ServerConfig, clientScope string) error

CloseClient will close the client for this MCP server, but leave the deployment running.

func (*SessionManager) GPTScriptTools

func (sm *SessionManager) GPTScriptTools(ctx context.Context, projectMCPServer v1.ProjectMCPServer, userID, mcpServerDisplayName, internalServerURL, serverURL string, allowedTools []string) ([]gptscript.ToolDef, error)

func (*SessionManager) GenerateToolPreviews added in v0.9.0

func (sm *SessionManager) GenerateToolPreviews(ctx context.Context, tempMCPServer v1.MCPServer, serverConfig ServerConfig) ([]otypes.MCPServerTool, error)

GenerateToolPreviews creates a temporary MCP server from a catalog entry, lists its tools, then shuts it down and returns the tool preview data.

func (*SessionManager) GetPrompt

func (sm *SessionManager) GetPrompt(ctx context.Context, serverConfig ServerConfig, name string, args map[string]string) ([]mcp.PromptMessage, string, error)

func (*SessionManager) GetServerDetails

func (sm *SessionManager) GetServerDetails(ctx context.Context, serverConfig ServerConfig) (types.MCPServerDetails, error)

GetServerDetails will get the details of a specific MCP server based on its configuration, if the backend supports it. If the server is remote, it will return an error as remote servers do not support this operation. If the backend does not support the operation, it will return an ErrNotSupportedByBackend error.

func (*SessionManager) Init added in v0.15.0

func (sm *SessionManager) Init(gptClient *gptscript.GPTScript, webhookHelper *WebhookHelper)

Init must be called before the session manager is used.

func (*SessionManager) LaunchServer added in v0.15.0

func (sm *SessionManager) LaunchServer(ctx context.Context, serverConfig ServerConfig) (string, error)

LaunchServer will ensure that the server is deployed

func (*SessionManager) ListPrompts

func (sm *SessionManager) ListPrompts(ctx context.Context, serverConfig ServerConfig) ([]mcp.Prompt, error)

func (*SessionManager) ListResources

func (sm *SessionManager) ListResources(ctx context.Context, serverConfig ServerConfig) ([]mcp.Resource, error)

func (*SessionManager) ListTools

func (sm *SessionManager) ListTools(ctx context.Context, serverConfig ServerConfig) ([]mcp.Tool, error)

func (*SessionManager) Load

func (sm *SessionManager) Load(_ context.Context, t types.Tool) ([]types.Tool, error)

Load is used by GPTScript to load tools from dynamic MCP server tool definitions. Obot is responsible for loading these tools and managing the clients and sessions. Error here to catch any server tools that slipped through. This should never be called.

func (*SessionManager) PingServer

func (sm *SessionManager) PingServer(ctx context.Context, serverConfig ServerConfig) (*nmcp.PingResult, error)

func (*SessionManager) ReadResource

func (sm *SessionManager) ReadResource(ctx context.Context, serverConfig ServerConfig, uri string) ([]mcp.ResourceContent, error)

func (*SessionManager) RestartServerDeployment added in v0.9.0

func (sm *SessionManager) RestartServerDeployment(ctx context.Context, server ServerConfig) error

RestartServerDeployment restarts the server in the currently used backend, if the backend supports it. If the backend does not support restarts, then an ErrNotSupportedByBackend error is returned.

func (*SessionManager) Run

func (sm *SessionManager) Run(ctx engine.Context, _ chan<- gtypes.CompletionStatus, tool gtypes.Tool, input string) (string, error)

Run is responsible for calling MCP tools when the LLM requests their execution. This method is called by GPTScript.

func (*SessionManager) ServerCapabilities

func (sm *SessionManager) ServerCapabilities(ctx context.Context, serverConfig ServerConfig) (nmcp.ServerCapabilities, error)

func (*SessionManager) ShutdownServer

func (sm *SessionManager) ShutdownServer(ctx context.Context, serverName string) error

ShutdownServer will close the connections to the MCP server and remove the Kubernetes objects.

func (*SessionManager) StreamServerLogs

func (sm *SessionManager) StreamServerLogs(ctx context.Context, serverConfig ServerConfig) (io.ReadCloser, error)

StreamServerLogs will stream the logs of a specific MCP server based on its configuration, if the backend supports it. If the server is remote, it will return an error as remote servers do not support this operation. If the backend does not support the operation, it will return an ErrNotSupportedByBackend error.

type TokenService added in v0.15.0

type TokenService interface {
	NewTokenWithClaims(context.Context, jwt.MapClaims) (*jwt.Token, string, error)
}

type Webhook

type Webhook struct {
	Name, DisplayName  string
	URL, Secret, Image string
	Definitions        []string
}

type WebhookHelper

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

func NewWebhookHelper

func NewWebhookHelper(indexer cache.Indexer, defaultBaseImage string) *WebhookHelper

func (*WebhookHelper) GetWebhooksForMCPServer

func (wh *WebhookHelper) GetWebhooksForMCPServer(ctx context.Context, gptClient *gptscript.GPTScript, serverConfig ServerConfig) ([]Webhook, error)

Jump to

Keyboard shortcuts

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