tools

package
v0.0.1-rc99 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetDataDirectoryInternal = getDataDirectory

GetDataDirectoryInternal is the internal function that can be overridden in tests

Functions

func EnsureDataDirectory

func EnsureDataDirectory() error

EnsureDataDirectory creates the data directory if it doesn't exist

func IsAutomationTool

func IsAutomationTool(name string) bool

IsAutomationTool returns true if the given tool name is an automation tool.

func NewJSONSchemaForAccessMode

func NewJSONSchemaForAccessMode[T any](accessMode string) *jsonschema.Schema

NewJSONSchemaForAccessMode creates a JSONSchema from a Go struct, filtering fields based on access mode

Access tag examples:

  • access:"local" - only available for local access mode
  • access:"remote" - only available for remote access mode
  • access:"local,remote" - available for both local and remote access modes
  • no access tag - available in all access modes

The function uses comma-separated parsing, so you can specify multiple access modes.

func RunBeforeHook

func RunBeforeHook(mcpCtx *MCPToolContext, toolName string, args any) error

RunBeforeHook is a no-op when no before-hook is registered for toolName. Otherwise it POSTs to the calling plugin and returns an error if the hook rejects or fails (fail-closed). args is the validated, decoded resolver argument struct; the hook receives its JSON form.

Types

type AIBotInfo

type AIBotInfo struct {
	ID          string `json:"id"`
	DisplayName string `json:"displayName"`
	Username    string `json:"username"`
}

AIBotInfo mirrors the api.AIBotInfo type for the fields we need.

type AIBotsResponse

type AIBotsResponse struct {
	Bots []AIBotInfo `json:"bots"`
}

AIBotsResponse mirrors the api.AIBotsResponse type.

type AIPromptActionConfig

type AIPromptActionConfig struct {
	SystemPrompt string                `json:"system_prompt,omitempty"`
	Prompt       string                `json:"prompt"`
	ProviderType string                `json:"provider_type"`
	ProviderID   string                `json:"provider_id"`
	AllowedTools []string              `json:"allowed_tools,omitempty"`
	Guardrails   *AutomationGuardrails `json:"guardrails,omitempty"`
	// RequestAs selects which user the AI completion request is attributed to.
	// Allowed values: "" or "triggerer" (default — the user who triggered the
	// automation, falling back to the flow creator when the trigger has no
	// associated user) or "creator" (always the flow creator).
	RequestAs string `json:"request_as,omitempty"`
}

AIPromptActionConfig holds config for the ai_prompt action type.

type AccessMode

type AccessMode string

AccessMode represents the security access level for MCP operations

const (
	// AccessModeLocal indicates the mode has local filesystem access and can execute local operations
	AccessModeLocal AccessMode = "local"
	// AccessModeRemote indicates the mode operates over network and has security restrictions
	AccessModeRemote AccessMode = "remote"
)

type AddUserToChannelArgs

type AddUserToChannelArgs struct {
	UserID    string `json:"user_id" jsonschema:"ID of the user to add"`
	ChannelID string `json:"channel_id" jsonschema:"ID of the channel to add user to"`
}

AddUserToChannelArgs represents arguments for the add_user_to_channel tool

type AddUserToTeamArgs

type AddUserToTeamArgs struct {
	UserID string `json:"user_id" jsonschema:"ID of the user to add"`
	TeamID string `json:"team_id" jsonschema:"ID of the team to add user to"`
}

AddUserToTeamArgs represents arguments for the add_user_to_team tool (dev mode only)

type Automation

type Automation struct {
	ID        string             `json:"id,omitempty"`
	Name      string             `json:"name"`
	Enabled   bool               `json:"enabled"`
	Trigger   AutomationTrigger  `json:"trigger"`
	Actions   []AutomationAction `json:"actions"`
	CreatedAt int64              `json:"created_at,omitempty"`
	UpdatedAt int64              `json:"updated_at,omitempty"`
	CreatedBy string             `json:"created_by,omitempty"`
}

Automation mirrors the channel-automation plugin's Automation model.

type AutomationAction

type AutomationAction struct {
	ID          string                   `json:"id"`
	SendMessage *SendMessageActionConfig `json:"send_message,omitempty"`
	AIPrompt    *AIPromptActionConfig    `json:"ai_prompt,omitempty"`
	SendDM      *SendDMActionConfig      `json:"send_dm,omitempty"`
}

AutomationAction defines a single step in an automation. Exactly one config pointer should be set.

type AutomationGuardrails

type AutomationGuardrails struct {
	ChannelIDs []string `json:"channel_ids,omitempty"`
}

AutomationGuardrails mirrors channel-automation guardrails that constrain where an automation may operate.

type AutomationTrigger

type AutomationTrigger struct {
	MessagePosted     *MessagePostedConfig     `json:"message_posted,omitempty"`
	Schedule          *ScheduleConfig          `json:"schedule,omitempty"`
	MembershipChanged *MembershipChangedConfig `json:"membership_changed,omitempty"`
	ChannelCreated    *ChannelCreatedConfig    `json:"channel_created,omitempty"`
	UserJoinedTeam    *UserJoinedTeamConfig    `json:"user_joined_team,omitempty"`
}

AutomationTrigger defines when an automation fires. Exactly one config pointer should be set.

type ChannelCreatedConfig

type ChannelCreatedConfig struct {
	TeamID string `json:"team_id"`
}

ChannelCreatedConfig holds trigger config for the channel_created trigger type.

type CombinedSearchArgs

type CombinedSearchArgs struct {
	Query          string `json:"query" jsonschema:"The search query,minLength=1,maxLength=4000"`
	TeamID         string `json:"team_id,omitempty" jsonschema:"Optional team ID to limit search scope,minLength=26,maxLength=26"`
	ChannelID      string `json:"channel_id,omitempty" jsonschema:"Optional channel ID to limit search to a specific channel,minLength=26,maxLength=26"`
	SemanticLimit  int    `json:"semantic_limit,omitempty" jsonschema:"Max results from semantic search (default 10; max 50),minimum=1,maximum=50"`
	SemanticOffset int    `json:"semantic_offset,omitempty" jsonschema:"Offset for semantic search pagination,minimum=0"`
	KeywordLimit   int    `json:"keyword_limit,omitempty" jsonschema:"Max results from keyword search (default 10; max 100),minimum=1,maximum=100"`
	KeywordOffset  int    `json:"keyword_offset,omitempty" jsonschema:"Offset for keyword search pagination,minimum=0"`
}

CombinedSearchArgs represents arguments for search_posts when both semantic and keyword search are available.

type CreateAutomationArgs

type CreateAutomationArgs struct {
	Name    string             `json:"name" jsonschema:"The name of the automation,minLength=1"`
	Enabled bool               `json:"enabled" jsonschema:"Whether the automation is enabled"`
	Trigger AutomationTrigger  `json:"trigger" jsonschema:"Set exactly one trigger type"`
	Actions []AutomationAction `json:"actions" jsonschema:"Ordered list of actions to perform when triggered"`
}

CreateAutomationArgs represents arguments for the create_automation tool.

type CreateChannelArgs

type CreateChannelArgs struct {
	Name        string `json:"name" jsonschema:"The channel name (URL-friendly),minLength=1,maxLength=64"`
	DisplayName string `json:"display_name" jsonschema:"The channel display name,minLength=1,maxLength=64"`
	Type        string `json:"type" jsonschema:"Channel type,enum=O,enum=P"`
	TeamID      string `json:"team_id" jsonschema:"The team ID where the channel will be created,minLength=26,maxLength=26"`
	Purpose     string `json:"purpose" jsonschema:"Optional channel purpose,maxLength=250"`
	Header      string `json:"header" jsonschema:"Optional channel header,maxLength=1024"`
}

CreateChannelArgs represents arguments for the create_channel tool

type CreatePostArgs

type CreatePostArgs struct {
	ChannelID          string   `json:"channel_id" jsonschema:"The ID of the channel to post in,minLength=26,maxLength=26"`
	ChannelDisplayName string   `json:"channel_display_name" jsonschema:"The display name of the channel (for context verification),minLength=1"`
	TeamDisplayName    string   `json:"team_display_name" jsonschema:"The display name of the team (for context verification),minLength=1"`
	Message            string   `json:"message" jsonschema:"The message content,minLength=1"`
	RootID             string   `json:"root_id,omitempty" jsonschema:"Optional root post ID for replies,minLength=26,maxLength=26"`
	Attachments        []string `json:"attachments,omitempty" access:"local" jsonschema:"Optional list of file paths or URLs to attach to the post"`
}

CreatePostArgs represents arguments for the create_post tool

type CreatePostAsUserArgs

type CreatePostAsUserArgs struct {
	Username    string   `json:"username" jsonschema:"Username to login as"`
	Password    string   `json:"password" jsonschema:"Password to login with"`
	ChannelID   string   `json:"channel_id" jsonschema:"The ID of the channel to post in"`
	Message     string   `json:"message" jsonschema:"The message content"`
	RootID      string   `json:"root_id" jsonschema:"Optional root post ID for replies"`
	Props       string   `json:"props" jsonschema:"Optional post properties (JSON string)"`
	Attachments []string `json:"attachments,omitempty" access:"local" jsonschema:"Optional list of file paths or URLs to attach to the post"`
}

CreatePostAsUserArgs represents arguments for the create_post_as_user tool (dev mode only)

type CreateTeamArgs

type CreateTeamArgs struct {
	Name        string `json:"name" jsonschema:"URL name for the team,minLength=1,maxLength=64"`
	DisplayName string `json:"display_name" jsonschema:"Display name for the team,minLength=1,maxLength=64"`
	Type        string `json:"type" jsonschema:"Team type,enum=O,enum=I"`
	Description string `json:"description" jsonschema:"Team description,maxLength=255"`
	TeamIcon    string `` /* 126-byte string literal not displayed */
}

CreateTeamArgs represents arguments for the create_team tool (dev mode only)

type CreateUserArgs

type CreateUserArgs struct {
	Username     string `json:"username" jsonschema:"Username for the new user"`
	Email        string `json:"email" jsonschema:"Email address for the new user"`
	Password     string `json:"password" jsonschema:"Password for the new user"`
	FirstName    string `json:"first_name" jsonschema:"First name of the user"`
	LastName     string `json:"last_name" jsonschema:"Last name of the user"`
	Nickname     string `json:"nickname" jsonschema:"Nickname for the user"`
	ProfileImage string `` /* 136-byte string literal not displayed */
}

CreateUserArgs represents arguments for the create_user tool (dev mode only)

type DMArgs

type DMArgs struct {
	Username    string   `json:"username,omitempty" jsonschema:"Target username. If omitted the message is sent to yourself."`
	Message     string   `json:"message" jsonschema:"The message content to send,minLength=1"`
	Attachments []string `json:"attachments,omitempty" access:"local" jsonschema:"Optional list of file paths or URLs to attach"`
}

DMArgs represents arguments for the dm tool

type DeleteAutomationArgs

type DeleteAutomationArgs struct {
	AutomationID string `json:"automation_id" jsonschema:"The ID of the automation to delete,minLength=1"`
}

DeleteAutomationArgs represents arguments for the delete_automation tool.

type GetChannelInfoArgs

type GetChannelInfoArgs struct {
	ChannelID   string `json:"channel_id,omitempty" jsonschema:"The exact channel ID (fastest, most reliable method),maxLength=26"`
	ChannelName string `` /* 178-byte string literal not displayed */
	TeamID      string `` /* 153-byte string literal not displayed */
}

GetChannelInfoArgs represents arguments for the get_channel_info tool

type GetChannelMembersArgs

type GetChannelMembersArgs struct {
	ChannelID   string `json:"channel_id" jsonschema:"ID of the channel to get members for,minLength=26,maxLength=26"`
	Limit       int    `json:"limit,omitempty" jsonschema:"Number of members to return (default: 50, max: 200),minimum=1,maximum=200"`
	Page        int    `json:"page,omitempty" jsonschema:"Page number for pagination (default: 0),minimum=0"`
	ExcludeBots *bool  `json:"exclude_bots,omitempty" jsonschema:"Exclude bot accounts from results (default: true)"`
}

GetChannelMembersArgs represents arguments for the get_channel_members tool

type GetTeamInfoArgs

type GetTeamInfoArgs struct {
	TeamID   string `json:"team_id,omitempty" jsonschema:"The exact team ID (fastest, most reliable method)"`
	TeamName string `` /* 159-byte string literal not displayed */
}

GetTeamInfoArgs represents arguments for the get_team_info tool

type GetTeamMembersArgs

type GetTeamMembersArgs struct {
	TeamID      string `json:"team_id" jsonschema:"ID of the team to get members for,minLength=26,maxLength=26"`
	Limit       int    `json:"limit,omitempty" jsonschema:"Number of members to return (default: 50, max: 200),minimum=1,maximum=200"`
	Page        int    `json:"page,omitempty" jsonschema:"Page number for pagination (default: 0),minimum=0"`
	ExcludeBots *bool  `json:"exclude_bots,omitempty" jsonschema:"Exclude bot accounts from results (default: true)"`
}

GetTeamMembersArgs represents arguments for the get_team_members tool

type GetUserChannelsArgs

type GetUserChannelsArgs struct {
	TeamID  string `json:"team_id,omitempty" jsonschema:"Optional team ID to filter channels by team,maxLength=26"`
	Page    int    `json:"page,omitempty" jsonschema:"Page number for pagination (default: 0),minimum=0"`
	PerPage int    `json:"per_page,omitempty" jsonschema:"Number of channels per page (default: 60, max: 200),minimum=1,maximum=200"`
}

GetUserChannelsArgs represents arguments for the get_user_channels tool

type GroupMessageArgs

type GroupMessageArgs struct {
	Usernames   []string `json:"usernames" jsonschema:"Target usernames (must be at least 2)."`
	Message     string   `json:"message" jsonschema:"The message content to send,minLength=1"`
	Attachments []string `json:"attachments,omitempty" access:"local" jsonschema:"Optional list of file paths or URLs to attach"`
}

GroupMessageArgs represents arguments for the group_message tool

type HTTPSemanticSearchService

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

HTTPSemanticSearchService provides semantic search by calling back to the plugin API. This allows external MCP servers (HTTP, Stdio) to access semantic search capabilities.

func NewHTTPSemanticSearchService

func NewHTTPSemanticSearchService(pluginURL string) *HTTPSemanticSearchService

NewHTTPSemanticSearchService creates a new HTTP-based semantic search service. pluginURL should be the base URL to the plugin, e.g., "https://mattermost.example.com/plugins/mattermost-ai"

func (*HTTPSemanticSearchService) Enabled

func (s *HTTPSemanticSearchService) Enabled() bool

Enabled returns true since this service is always available when created. The actual availability check happens at the plugin endpoint.

func (*HTTPSemanticSearchService) Search

Search performs a semantic search by calling the plugin's MCP semantic search endpoint

type KeywordOnlySearchArgs

type KeywordOnlySearchArgs struct {
	Query         string `json:"query" jsonschema:"The search query,minLength=1,maxLength=4000"`
	TeamID        string `json:"team_id,omitempty" jsonschema:"Optional team ID to limit search scope,minLength=26,maxLength=26"`
	ChannelID     string `json:"channel_id,omitempty" jsonschema:"Optional channel ID to limit search to a specific channel,minLength=26,maxLength=26"`
	KeywordLimit  int    `json:"keyword_limit,omitempty" jsonschema:"Max results from keyword search (default 10; max 100),minimum=1,maximum=100"`
	KeywordOffset int    `json:"keyword_offset,omitempty" jsonschema:"Offset for keyword search pagination,minimum=0"`
}

KeywordOnlySearchArgs represents arguments for search_posts when only keyword search is available.

type ListAgentsArgs

type ListAgentsArgs struct{}

ListAgentsArgs represents arguments for the list_agents tool.

type ListAutomationsArgs

type ListAutomationsArgs struct {
	AutomationID string `json:"automation_id,omitempty" jsonschema:"The ID of a specific automation to retrieve"`
	ChannelID    string `json:"channel_id,omitempty" jsonschema:"Filter automations by trigger channel ID"`
}

ListAutomationsArgs represents arguments for the list_automations tool.

type MCPTool

type MCPTool struct {
	Name        string
	Description string
	Schema      *jsonschema.Schema
	Resolver    MCPToolResolver
}

MCPTool represents a tool specifically for MCP use with our custom context

type MCPToolContext

type MCPToolContext struct {
	Ctx        context.Context
	Client     *model.Client4
	AccessMode AccessMode
	BotUserID  string // User ID for AI-generated content tracking: Bot ID (embedded) or authenticated user ID (external servers)

	// UserID is the Mattermost user ID of the user the Client is authenticated as.
	// Empty when the auth provider cannot resolve an authenticated user.
	UserID string

	// MMServerURL is the Mattermost server base URL (same as API Client4 origin) for resolving hook keys and firing callbacks.
	MMServerURL        string
	BeforeHookResolver auth.BeforeHookResolver
	ToolHooks          map[string]ToolHookConfig
}

MCPToolContext provides MCP-specific functionality with the authenticated client.

type MCPToolResolver

type MCPToolResolver func(*MCPToolContext, llm.ToolArgumentGetter) (string, error)

MCPToolResolver defines the signature for MCP tool resolvers

type MattermostToolProvider

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

MattermostToolProvider provides Mattermost tools following the mmtools pattern

func NewMattermostToolProvider

func NewMattermostToolProvider(authProvider auth.AuthenticationProvider, logger logger.Logger, config types.ServerConfig, accessMode AccessMode, searchService SemanticSearchService) *MattermostToolProvider

NewMattermostToolProvider creates a new tool provider Now accepts a ServerConfig interface to avoid circular dependencies searchService is optional and can be nil if semantic search is not available

func (*MattermostToolProvider) ProvideTools

func (p *MattermostToolProvider) ProvideTools(mcpServer *mcp.Server)

ProvideTools registers all available MCP tools with the server.

func (*MattermostToolProvider) ToolNames

func (p *MattermostToolProvider) ToolNames() []string

ToolNames returns the names of the tools this provider will register.

type MembershipChangedConfig

type MembershipChangedConfig struct {
	ChannelID string `json:"channel_id"`
	Action    string `json:"action,omitempty"`
}

MembershipChangedConfig holds trigger config for the membership_changed trigger type.

type MessagePostedConfig

type MessagePostedConfig struct {
	ChannelID            string `json:"channel_id"`
	IncludeThreadReplies bool   `json:"include_thread_replies,omitempty"`
}

MessagePostedConfig holds trigger config for the message_posted trigger type.

type ReadChannelArgs

type ReadChannelArgs struct {
	ChannelID string `json:"channel_id" jsonschema:"The ID of the channel to read from,minLength=26,maxLength=26"`
	Limit     int    `json:"limit,omitempty" jsonschema:"Number of posts to retrieve (default: 20, max: 100),minimum=1,maximum=100"`
	Since     string `json:"since,omitempty" jsonschema:"Only get posts since this timestamp (ISO 8601 format),format=date-time"`
}

ReadChannelArgs represents arguments for the read_channel tool

type ReadPostArgs

type ReadPostArgs struct {
	PostID        string `json:"post_id" jsonschema:"The ID of the post to read,minLength=26,maxLength=26"`
	IncludeThread bool   `json:"include_thread,omitempty" jsonschema:"Whether to include the entire thread (default: true)"`
}

ReadPostArgs represents arguments for the read_post tool

type ScheduleConfig

type ScheduleConfig struct {
	ChannelID string `json:"channel_id"`
	Interval  string `json:"interval" jsonschema:"Go duration string, minimum 5m. Examples: 1h (hourly) 24h (daily) 168h (weekly)"`
	StartAt   int64  `` /* 160-byte string literal not displayed */
}

ScheduleConfig holds trigger config for the schedule trigger type.

type SearchUsersArgs

type SearchUsersArgs struct {
	Term  string `json:"term" jsonschema:"Search term (username, email, first name, or last name),minLength=1,maxLength=64"`
	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of results to return (default: 20, max: 100),minimum=1,maximum=100"`
}

SearchUsersArgs represents arguments for the search_users tool.

type SemanticSearchService

type SemanticSearchService interface {
	Enabled() bool
	Search(ctx context.Context, query string, opts search.Options) ([]search.RAGResult, error)
}

SemanticSearchService provides semantic search capabilities for the MCP server. *search.Search implements this interface directly for embedded servers. HTTPSemanticSearchService implements it for external servers via HTTP callbacks.

type SendDMActionConfig

type SendDMActionConfig struct {
	UserID  string `json:"user_id"`
	Body    string `json:"body"`
	AsBotID string `json:"as_bot_id"`
}

SendDMActionConfig holds config for the send_dm action type.

type SendMessageActionConfig

type SendMessageActionConfig struct {
	ChannelID     string `json:"channel_id"`
	ReplyToPostID string `json:"reply_to_post_id,omitempty"`
	AsBotID       string `json:"as_bot_id,omitempty"`
	Body          string `json:"body"`
}

SendMessageActionConfig holds config for the send_message action type.

type ToolHookConfig

type ToolHookConfig struct {
	BeforeHookKey string `json:"before_hook_key,omitempty"`
}

ToolHookConfig holds an optional opaque before-hook key for a tool.

type ToolProvider

type ToolProvider interface {
	ProvideTools(*mcp.Server)
}

type UpdateAutomationArgs

type UpdateAutomationArgs struct {
	AutomationID string             `json:"automation_id" jsonschema:"The ID of the automation to update,minLength=1"`
	Name         string             `json:"name" jsonschema:"The name of the automation,minLength=1"`
	Enabled      bool               `json:"enabled" jsonschema:"Whether the automation is enabled"`
	Trigger      AutomationTrigger  `json:"trigger" jsonschema:"Set exactly one trigger type"`
	Actions      []AutomationAction `json:"actions" jsonschema:"Ordered list of actions to perform when triggered"`
}

UpdateAutomationArgs represents arguments for the update_automation tool.

type UserJoinedTeamConfig

type UserJoinedTeamConfig struct {
	TeamID   string `json:"team_id"`
	UserType string `json:"user_type,omitempty"`
}

UserJoinedTeamConfig holds trigger config for the user_joined_team trigger type.

Jump to

Keyboard shortcuts

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