Documentation
¶
Overview ¶
Package mcp provides a client for the Model Control Protocol (MCP) that allows the AI plugin to access external tools provided by MCP servers.
The UserClient represents a single user's connection to multiple MCP servers. The UserClient currents only supports authentication via Mattermost user ID header X-Mattermost-UserID. In the future it will support our OAuth implementation.
The ClientManager manages multiple UserClients, allowing for efficient mangement of connections. It is responsible for creating and closing UserClients as needed.
The organization reflects the need for each user to have their own connection to the MCP server given the design of MCP.
Index ¶
Constants ¶
const MMUserIDHeader = "X-Mattermost-UserID"
Variables ¶
This section is empty.
Functions ¶
func ConvertPropertiesToOrderedMap ¶
func ConvertPropertiesToOrderedMap(source map[string]any) (*orderedmap.OrderedMap[string, *jsonschema.Schema], error)
ConvertPropertiesToOrderedMap converts a map of properties to an OrderedMap using JSON marshaling
Types ¶
type ClientManager ¶
type ClientManager struct {
// contains filtered or unexported fields
}
ClientManager manages MCP clients for multiple users
func NewClientManager ¶
func NewClientManager(config Config, log pluginapi.LogService) *ClientManager
NewClientManager creates a new MCP client manager
func (*ClientManager) Close ¶
func (m *ClientManager) Close()
Close closes the client manager and all managed clients The client manger should not be used after Close is called
func (*ClientManager) GetToolsForUser ¶
func (m *ClientManager) GetToolsForUser(userID string) ([]llm.Tool, error)
GetToolsForUser returns the tools available for a specific user
func (*ClientManager) ReInit ¶
func (m *ClientManager) ReInit(config Config)
ReInit re-initializes the client manager with a new configuration
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Servers map[string]ServerConfig `json:"servers"`
IdleTimeoutMinutes int `json:"idleTimeoutMinutes"`
}
Config contains the configuration for the MCP clients
type ServerConfig ¶
type ServerConfig struct {
BaseURL string `json:"baseURL"`
Headers map[string]string `json:"headers,omitempty"`
}
ServerConfig contains the configuration for a single MCP server
type ServerConnection ¶
type ServerConnection struct {
// contains filtered or unexported fields
}
ServerConnection represents the connection to a single MCP server
type ToolDefinition ¶
type ToolDefinition struct {
// contains filtered or unexported fields
}
ToolDefinition represents a tool provided by an MCP server
type UserClient ¶
type UserClient struct {
// contains filtered or unexported fields
}
UserClient represents a per-user MCP client with multiple server connections
func (*UserClient) Close ¶
func (c *UserClient) Close()
Close closes all server connections for a user client
func (*UserClient) ConnectToAllServers ¶
func (c *UserClient) ConnectToAllServers(servers map[string]ServerConfig) error
ConnectToAllServers initializes connections to all provided servers
func (*UserClient) GetTools ¶
func (c *UserClient) GetTools() []llm.Tool
GetTools returns the tools available from the client