mcp

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 58 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")
)

Functions

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
}

func (*Client) Capabilities

func (c *Client) Capabilities() nmcp.ServerCapabilities

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"`
	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"`
}

type ServerConfig

type ServerConfig struct {
	DisableInstruction bool     `json:"disableInstruction"`
	Command            string   `json:"command"`
	Args               []string `json:"args"`
	Env                []string `json:"env"`
	URL                string   `json:"url"`
	Headers            []string `json:"headers"`
	Scope              string   `json:"scope"`
	AllowedTools       []string `json:"allowedTools"`

	Files          []File        `json:"files"`
	ContainerImage string        `json:"containerImage"`
	ContainerPort  int           `json:"containerPort"`
	ContainerPath  string        `json:"containerPath"`
	Runtime        types.Runtime `json:"runtime"`
}

func ProjectServerToConfig

func ProjectServerToConfig(tokenService *ephemeral.TokenService, projectMCPServer v1.ProjectMCPServer, baseURL, userID string, userIsAdmin bool, allowedTools ...string) (ServerConfig, error)

func ServerToServerConfig

func ServerToServerConfig(mcpServer v1.MCPServer, scope string, credEnv map[string]string, allowedTools ...string) (ServerConfig, []string, error)

type SessionManager

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

func NewSessionManager

func NewSessionManager(ctx context.Context, tokenStorage GlobalTokenStore, baseURL string, opts Options, localK8sConfig *rest.Config) (*SessionManager, error)

func (*SessionManager) ClientForMCPServer

func (sm *SessionManager) ClientForMCPServer(ctx context.Context, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig) (*Client, error)

func (*SessionManager) ClientForMCPServerWithOptions

func (sm *SessionManager) ClientForMCPServerWithOptions(ctx context.Context, clientScope string, mcpServer v1.MCPServer, serverConfig ServerConfig, opts ...nmcp.ClientOption) (*Client, error)

func (*SessionManager) ClientForServer

func (sm *SessionManager) ClientForServer(ctx context.Context, userID, mcpServerDisplayName, mcpServerName string, serverConfig ServerConfig) (*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, tokenService *ephemeral.TokenService, projectMCPServer v1.ProjectMCPServer, userID, mcpServerDisplayName, serverURL string, userIsAdmin bool, 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, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig, name string, args map[string]string) ([]mcp.PromptMessage, string, error)

func (*SessionManager) GetServerDetails

func (sm *SessionManager) GetServerDetails(ctx context.Context, mcpServerDisplayName, mcpServerName string, 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) ListPrompts

func (sm *SessionManager) ListPrompts(ctx context.Context, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig) ([]mcp.Prompt, error)

func (*SessionManager) ListResources

func (sm *SessionManager) ListResources(ctx context.Context, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig) ([]mcp.Resource, error)

func (*SessionManager) ListTools

func (sm *SessionManager) ListTools(ctx context.Context, userID string, mcpServer v1.MCPServer, 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, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig) (*nmcp.PingResult, error)

func (*SessionManager) ReadResource

func (sm *SessionManager) ReadResource(ctx context.Context, userID string, mcpServer v1.MCPServer, 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<- types.CompletionStatus, tool types.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, userID string, mcpServer v1.MCPServer, serverConfig ServerConfig) (nmcp.ServerCapabilities, error)

func (*SessionManager) ShutdownServer

func (sm *SessionManager) ShutdownServer(ctx context.Context, server ServerConfig) 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, mcpServerDisplayName, mcpServerName string, 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 Webhook

type Webhook struct {
	URL, Secret string
}

type WebhookHelper

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

func NewWebhookHelper

func NewWebhookHelper(indexer cache.Indexer) *WebhookHelper

func (*WebhookHelper) GetWebhooksForMCPServer

func (wh *WebhookHelper) GetWebhooksForMCPServer(ctx context.Context, gptClient *gptscript.GPTScript, mcpServerNamespace, mcpServerName, mcpServerCatalogEntryName, mcpServerCatalogName, method, identifier string) ([]Webhook, error)

Jump to

Keyboard shortcuts

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