Documentation
¶
Overview ¶
Package prompt provides prompt management functionality.
Package prompt is a generated GoMock package.
Index ¶
- Variables
- type MCPServerProvider
- type Manager
- func (pm *Manager) AddPrompt(prompt Prompt)
- func (pm *Manager) ClearPromptsForService(serviceID string)
- func (pm *Manager) GetPrompt(name string) (Prompt, bool)
- func (pm *Manager) ListPrompts() []Prompt
- func (pm *Manager) SetMCPServer(mcpServer MCPServerProvider)
- func (pm *Manager) UpdatePrompt(prompt Prompt)
- type ManagerInterface
- type MockManagerInterface
- func (m *MockManagerInterface) AddPrompt(prompt Prompt)
- func (m *MockManagerInterface) Clear()
- func (m *MockManagerInterface) ClearPromptsForService(serviceID string)
- func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
- func (m *MockManagerInterface) GetPrompt(name string) (Prompt, bool)
- func (m *MockManagerInterface) ListPrompts() []Prompt
- func (m *MockManagerInterface) SetMCPServer(mcpServer MCPServerProvider)
- func (m *MockManagerInterface) UpdatePrompt(prompt Prompt)
- type MockManagerInterfaceMockRecorder
- func (mr *MockManagerInterfaceMockRecorder) AddPrompt(prompt any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ClearPromptsForService(serviceID any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) GetPrompt(name any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ListPrompts() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) SetMCPServer(mcpServer any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) UpdatePrompt(prompt any) *gomock.Call
- type Prompt
- type Service
- type TemplatedPrompt
Constants ¶
This section is empty.
Variables ¶
var ErrPromptNotFound = errors.New("prompt not found")
ErrPromptNotFound is returned when a requested prompt is not found.
Summary: Represents a ErrPromptNotFound.
Functions ¶
This section is empty.
Types ¶
type MCPServerProvider ¶
type MCPServerProvider interface {
// Server returns the underlying MCP server instance.
//
// Returns:
// - *mcp.Server: The MCP server instance.
Server() *mcp.Server
}
MCPServerProvider defines an interface for components that can provide an instance of an *mcp.Server.
Summary: Interface for providing an MCP server instance.
This is used to decouple the Manager from the concrete server implementation.
func NewMCPServerProvider ¶
func NewMCPServerProvider(server *mcp.Server) MCPServerProvider
NewMCPServerProvider creates a new MCPServerProvider.
Summary: Initializes a provider for the MCP server.
Parameters:
- server: *mcp.Server. The server instance to wrap.
Returns:
- MCPServerProvider: The initialized provider.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a thread-safe manager for registering and retrieving prompts.
It supports concurrent access and uses caching for efficient list operations.
Summary: Represents a Manager.
func NewManager ¶
func NewManager() *Manager
NewManager creates and returns a new, empty Manager.
Returns:
- *Manager: A pointer to the newly created Manager.
Summary: Initializes NewManager operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) AddPrompt ¶
AddPrompt registers a new prompt with the manager.
If a prompt with the same name already exists, it will be overwritten, and a warning will be logged.
Parameters:
- prompt: Prompt. The prompt to add.
Side Effects:
- Updates the internal prompt registry.
- Invalidates the list cache.
Summary: Executes AddPrompt operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) ClearPromptsForService ¶
ClearPromptsForService removes all prompts associated with a given service.
Parameters:
- serviceID: string. The unique identifier of the service.
Side Effects:
- Removes matching prompts from the registry.
- Invalidates the list cache.
Summary: Executes ClearPromptsForService operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) GetPrompt ¶
GetPrompt retrieves a prompt from the manager by its name.
Parameters:
- name: string. The name of the prompt.
Returns:
- Prompt: The prompt instance.
- bool: True if found, false otherwise.
Summary: Retrieves GetPrompt operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) ListPrompts ¶
ListPrompts returns a slice containing all the prompts currently registered.
It uses a read-through cache to improve performance.
Returns:
- []Prompt: A slice of currently registered prompts.
Summary: Executes ListPrompts operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) SetMCPServer ¶
func (pm *Manager) SetMCPServer(mcpServer MCPServerProvider)
SetMCPServer provides the Manager with a reference to the MCP server.
Parameters:
- mcpServer: MCPServerProvider. The MCP server provider.
Summary: Updates SetMCPServer operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*Manager) UpdatePrompt ¶
UpdatePrompt updates an existing prompt in the manager.
If the prompt does not exist, it will be added.
Parameters:
- prompt: Prompt. The prompt definition to update.
Side Effects:
- Updates the internal prompt registry.
- Invalidates the list cache.
Summary: Executes UpdatePrompt operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
type ManagerInterface ¶
type ManagerInterface interface {
// AddPrompt registers a new prompt.
//
// Parameters:
// - prompt: Prompt. The prompt definition to add.
AddPrompt(prompt Prompt)
// UpdatePrompt updates an existing prompt.
//
// Parameters:
// - prompt: Prompt. The prompt with updated information.
UpdatePrompt(prompt Prompt)
// GetPrompt retrieves a prompt by its name.
//
// Parameters:
// - name: string. The unique name of the prompt.
//
// Returns:
// - Prompt: The prompt instance.
// - bool: True if the prompt was found, false otherwise.
GetPrompt(name string) (Prompt, bool)
// ListPrompts returns all registered prompts.
//
// Returns:
// - []Prompt: A slice of all registered prompts.
ListPrompts() []Prompt
// ClearPromptsForService removes all prompts associated with a specific service.
//
// Parameters:
// - serviceID: string. The unique identifier of the service.
ClearPromptsForService(serviceID string)
// SetMCPServer sets the MCP server provider.
//
// Parameters:
// - mcpServer: MCPServerProvider. The provider interface.
SetMCPServer(mcpServer MCPServerProvider)
}
ManagerInterface defines the interface for a prompt manager.
It manages the lifecycle, registration, and retrieval of prompts within the system.
Summary: Represents a ManagerInterface.
type MockManagerInterface ¶
type MockManagerInterface struct {
// contains filtered or unexported fields
}
MockManagerInterface is a mock of ManagerInterface interface.
Summary: Mock implementation of the Prompt Manager Interface for testing.
func NewMockManagerInterface ¶
func NewMockManagerInterface(ctrl *gomock.Controller) *MockManagerInterface
NewMockManagerInterface creates a new mock instance.
Summary: Initializes a new mock controller.
Parameters:
- ctrl: *gomock.Controller. The controller to use.
Returns:
- *MockManagerInterface: The initialized mock.
func (*MockManagerInterface) AddPrompt ¶
func (m *MockManagerInterface) AddPrompt(prompt Prompt)
AddPrompt mocks base method.
Summary: Mocks AddPrompt.
Parameters:
- prompt: Prompt. The prompt to add.
func (*MockManagerInterface) Clear ¶
func (m *MockManagerInterface) Clear()
Clear mocks base method. Summary: Mocks Clear.
Parameters:
- None
Returns:
- None
Errors:
- None
Side Effects:
- None
Summary: Executes Clear operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) ClearPromptsForService ¶
func (m *MockManagerInterface) ClearPromptsForService(serviceID string)
ClearPromptsForService mocks base method.
Summary: Mocks ClearPromptsForService.
Parameters:
- serviceID: string. The service ID.
func (*MockManagerInterface) EXPECT ¶
func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
Summary: Returns the recorder for setting expectations.
Returns:
- *MockManagerInterfaceMockRecorder: The recorder.
func (*MockManagerInterface) GetPrompt ¶
func (m *MockManagerInterface) GetPrompt(name string) (Prompt, bool)
GetPrompt mocks base method.
Summary: Mocks GetPrompt.
Parameters:
- name: string. The prompt name.
Returns:
- Prompt: The returned prompt.
- bool: True if found.
func (*MockManagerInterface) ListPrompts ¶
func (m *MockManagerInterface) ListPrompts() []Prompt
ListPrompts mocks base method.
Summary: Mocks ListPrompts.
Returns:
- []Prompt: A list of prompts.
func (*MockManagerInterface) SetMCPServer ¶
func (m *MockManagerInterface) SetMCPServer(mcpServer MCPServerProvider)
SetMCPServer mocks base method.
Summary: Mocks SetMCPServer.
Parameters:
- mcpServer: MCPServerProvider. The MCP server provider.
func (*MockManagerInterface) UpdatePrompt ¶
func (m *MockManagerInterface) UpdatePrompt(prompt Prompt)
UpdatePrompt mocks base method.
Summary: Mocks UpdatePrompt.
Parameters:
- prompt: Prompt. The prompt to update.
type MockManagerInterfaceMockRecorder ¶
type MockManagerInterfaceMockRecorder struct {
// contains filtered or unexported fields
}
MockManagerInterfaceMockRecorder is the mock recorder for MockManagerInterface.
Summary: Recorder for mock call expectations.
func (*MockManagerInterfaceMockRecorder) AddPrompt ¶
func (mr *MockManagerInterfaceMockRecorder) AddPrompt(prompt any) *gomock.Call
AddPrompt indicates an expected call of AddPrompt.
Summary: Records an expectation for AddPrompt.
Parameters:
- prompt: any. The expected prompt argument.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) Clear ¶
func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
Clear indicates an expected call of Clear.
Summary: Records an expectation for Clear.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) ClearPromptsForService ¶
func (mr *MockManagerInterfaceMockRecorder) ClearPromptsForService(serviceID any) *gomock.Call
ClearPromptsForService indicates an expected call of ClearPromptsForService.
Summary: Records an expectation for ClearPromptsForService.
Parameters:
- serviceID: any. The expected service ID.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) GetPrompt ¶
func (mr *MockManagerInterfaceMockRecorder) GetPrompt(name any) *gomock.Call
GetPrompt indicates an expected call of GetPrompt.
Summary: Records an expectation for GetPrompt.
Parameters:
- name: any. The expected name.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) ListPrompts ¶
func (mr *MockManagerInterfaceMockRecorder) ListPrompts() *gomock.Call
ListPrompts indicates an expected call of ListPrompts.
Summary: Records an expectation for ListPrompts.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) SetMCPServer ¶
func (mr *MockManagerInterfaceMockRecorder) SetMCPServer(mcpServer any) *gomock.Call
SetMCPServer indicates an expected call of SetMCPServer.
Summary: Records an expectation for SetMCPServer.
Parameters:
- mcpServer: any. The expected provider.
Returns:
- *gomock.Call: The mock call object.
func (*MockManagerInterfaceMockRecorder) UpdatePrompt ¶
func (mr *MockManagerInterfaceMockRecorder) UpdatePrompt(prompt any) *gomock.Call
UpdatePrompt indicates an expected call of UpdatePrompt.
Summary: Records an expectation for UpdatePrompt.
Parameters:
- prompt: any. The expected prompt.
Returns:
- *gomock.Call: The mock call object.
type Prompt ¶
type Prompt interface {
// Prompt returns the MCP prompt definition.
//
// Returns:
// - *mcp.Prompt: The MCP prompt definition.
Prompt() *mcp.Prompt
// Service returns the ID of the service that provides this prompt.
//
// Returns:
// - string: The service ID.
Service() string
// Definition returns the raw configuration definition of the prompt.
//
// Returns:
// - *configv1.PromptDefinition: The prompt definition.
Definition() *configv1.PromptDefinition
// Get executes the prompt with the provided arguments.
//
// Parameters:
// - ctx: The context for the request.
// - args: The arguments for the prompt as a raw JSON message.
//
// Returns:
// - *mcp.GetPromptResult: The result of the prompt execution.
// - error: An error if the operation fails.
Get(ctx context.Context, args json.RawMessage) (*mcp.GetPromptResult, error)
}
Prompt is the fundamental interface for any executable prompt in the system.
Summary: Interface for defining and executing prompts.
func NewPromptFromConfig ¶
func NewPromptFromConfig(definition *configv1.PromptDefinition, serviceID string) (Prompt, error)
NewPromptFromConfig creates a new Prompt from a configuration definition.
Summary: Creates a Prompt from configuration.
Parameters:
- definition: The prompt definition from configuration.
- serviceID: The ID of the service providing the prompt.
Returns:
- Prompt: The created Prompt instance.
- error: An error if the prompt cannot be created.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles the business logic for the prompts feature. It provides methods for listing available prompts and retrieving a specific prompt by name.
Summary: Represents a Service.
func NewService ¶
func NewService(promptManager ManagerInterface) *Service
NewService creates and returns a new Service instance.
Summary: Initializes a new Prompt Service.
Parameters:
- promptManager: ManagerInterface. The manager handling prompt lifecycle.
Returns:
- *Service: The initialized service.
func (*Service) GetPrompt ¶
func (s *Service) GetPrompt( ctx context.Context, req *mcp.GetPromptRequest, ) (*mcp.GetPromptResult, error)
GetPrompt handles the "prompts/get" MCP request.
Summary: Retrieves and executes a specific prompt.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.GetPromptRequest. The request containing the prompt name and arguments.
Returns:
- *mcp.GetPromptResult: The result of the prompt execution.
- error: An error if the prompt is not found or execution fails.
Throws/Errors:
- ErrPromptNotFound: If the prompt does not exist.
func (*Service) ListPrompts ¶
func (s *Service) ListPrompts( _ context.Context, _ *mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPrompts handles the "prompts/list" MCP request.
Summary: Lists all available prompts.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.ListPromptsRequest. The request object.
Returns:
- *mcp.ListPromptsResult: The list of prompts.
- error: An error if the operation fails.
func (*Service) SetMCPServer ¶
SetMCPServer sets the MCP server instance for the service.
Summary: Configures the underlying MCP server.
Parameters:
- mcpServer: *mcp.Server. The MCP server instance.
Returns:
None.
type TemplatedPrompt ¶
type TemplatedPrompt struct {
// contains filtered or unexported fields
}
TemplatedPrompt implements the Prompt interface for a prompt that is defined by a template.
Summary: Prompt implementation using templates.
func NewTemplatedPrompt ¶
func NewTemplatedPrompt(definition *configv1.PromptDefinition, serviceID string) (*TemplatedPrompt, error)
NewTemplatedPrompt creates a new TemplatedPrompt instance.
Summary: Initializes a new TemplatedPrompt.
Parameters:
- definition: The prompt definition from configuration.
- serviceID: The ID of the service providing the prompt.
Returns:
- *TemplatedPrompt: The initialized TemplatedPrompt.
- error: An error if the prompt templates cannot be compiled.
Errors:
- Returns error if template parsing fails.
Side Effects:
- Compiles all message templates.
func (*TemplatedPrompt) Definition ¶
func (p *TemplatedPrompt) Definition() *configv1.PromptDefinition
Definition returns the raw configuration definition of the prompt.
Summary: Retrieves the prompt configuration definition.
Returns:
- *configv1.PromptDefinition: The definition proto.
func (*TemplatedPrompt) Get ¶
func (p *TemplatedPrompt) Get(_ context.Context, args json.RawMessage) (*mcp.GetPromptResult, error)
Get executes the prompt with the provided arguments.
Summary: Executes the prompt.
It renders the prompt template using the provided arguments.
Parameters:
- _: The context (unused in this implementation).
- args: The arguments for the prompt as a raw JSON message.
Returns:
- *mcp.GetPromptResult: The result of the prompt execution.
- error: An error if the operation fails (e.g., template rendering error).
Errors:
- Returns error if args cannot be unmarshaled.
- Returns error if template rendering fails.
func (*TemplatedPrompt) Prompt ¶
func (p *TemplatedPrompt) Prompt() *mcp.Prompt
Prompt returns the MCP prompt definition.
Summary: Retrieves the MCP prompt definition.
Returns:
- *mcp.Prompt: The MCP prompt definition.
func (*TemplatedPrompt) Service ¶
func (p *TemplatedPrompt) Service() string
Service returns the ID of the service that provides this prompt.
Summary: Retrieves the service ID.
Returns:
- string: The service ID.