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.
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.
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.
func NewManager ¶
func NewManager() *Manager
NewManager creates and returns a new, empty Manager.
Returns:
- *Manager: A pointer to the newly created Manager.
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.
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.
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.
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.
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.
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.
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.
type MockManagerInterface ¶
type MockManagerInterface struct {
// contains filtered or unexported fields
}
MockManagerInterface is a mock of ManagerInterface interface.
func NewMockManagerInterface ¶
func NewMockManagerInterface(ctrl *gomock.Controller) *MockManagerInterface
NewMockManagerInterface creates a new mock instance.
ctrl is the ctrl.
Returns the result.
func (*MockManagerInterface) AddPrompt ¶
func (m *MockManagerInterface) AddPrompt(prompt Prompt)
AddPrompt mocks base method.
prompt is the prompt.
func (*MockManagerInterface) Clear ¶
func (m *MockManagerInterface) Clear()
Clear mocks base method.
func (*MockManagerInterface) ClearPromptsForService ¶
func (m *MockManagerInterface) ClearPromptsForService(serviceID string)
ClearPromptsForService mocks base method.
serviceID is the serviceID.
func (*MockManagerInterface) EXPECT ¶
func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
Returns the result.
func (*MockManagerInterface) GetPrompt ¶
func (m *MockManagerInterface) GetPrompt(name string) (Prompt, bool)
GetPrompt mocks base method.
name is the name of the resource.
Returns the result. Returns true if successful.
func (*MockManagerInterface) ListPrompts ¶
func (m *MockManagerInterface) ListPrompts() []Prompt
ListPrompts mocks base method.
Returns the result.
func (*MockManagerInterface) SetMCPServer ¶
func (m *MockManagerInterface) SetMCPServer(mcpServer MCPServerProvider)
SetMCPServer mocks base method.
mcpServer is the mcpServer.
func (*MockManagerInterface) UpdatePrompt ¶
func (m *MockManagerInterface) UpdatePrompt(prompt Prompt)
UpdatePrompt mocks base method.
prompt is the prompt.
type MockManagerInterfaceMockRecorder ¶
type MockManagerInterfaceMockRecorder struct {
// contains filtered or unexported fields
}
MockManagerInterfaceMockRecorder is the mock recorder for MockManagerInterface.
func (*MockManagerInterfaceMockRecorder) AddPrompt ¶
func (mr *MockManagerInterfaceMockRecorder) AddPrompt(prompt any) *gomock.Call
AddPrompt indicates an expected call of AddPrompt.
prompt is the prompt.
Returns the result.
func (*MockManagerInterfaceMockRecorder) Clear ¶
func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
Clear indicates an expected call of Clear.
Returns the result.
func (*MockManagerInterfaceMockRecorder) ClearPromptsForService ¶
func (mr *MockManagerInterfaceMockRecorder) ClearPromptsForService(serviceID any) *gomock.Call
ClearPromptsForService indicates an expected call of ClearPromptsForService.
serviceID is the serviceID.
Returns the result.
func (*MockManagerInterfaceMockRecorder) GetPrompt ¶
func (mr *MockManagerInterfaceMockRecorder) GetPrompt(name any) *gomock.Call
GetPrompt indicates an expected call of GetPrompt.
name is the name of the resource.
Returns the result.
func (*MockManagerInterfaceMockRecorder) ListPrompts ¶
func (mr *MockManagerInterfaceMockRecorder) ListPrompts() *gomock.Call
ListPrompts indicates an expected call of ListPrompts.
Returns the result.
func (*MockManagerInterfaceMockRecorder) SetMCPServer ¶
func (mr *MockManagerInterfaceMockRecorder) SetMCPServer(mcpServer any) *gomock.Call
SetMCPServer indicates an expected call of SetMCPServer.
mcpServer is the mcpServer.
Returns the result.
func (*MockManagerInterfaceMockRecorder) UpdatePrompt ¶
func (mr *MockManagerInterfaceMockRecorder) UpdatePrompt(prompt any) *gomock.Call
UpdatePrompt indicates an expected call of UpdatePrompt.
prompt is the prompt.
Returns the result.
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
// 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.
func NewPromptFromConfig ¶
func NewPromptFromConfig(definition *configv1.PromptDefinition, serviceID string) (Prompt, error)
NewPromptFromConfig creates a new Prompt from a configuration definition.
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.
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.
func NewTemplatedPrompt ¶
func NewTemplatedPrompt(definition *configv1.PromptDefinition, serviceID string) *TemplatedPrompt
NewTemplatedPrompt creates a new TemplatedPrompt instance.
Parameters:
- definition: The prompt definition from configuration.
- serviceID: The ID of the service providing the prompt.
Returns:
- *TemplatedPrompt: The initialized TemplatedPrompt.
func (*TemplatedPrompt) Get ¶
func (p *TemplatedPrompt) Get(_ context.Context, args json.RawMessage) (*mcp.GetPromptResult, error)
Get executes the prompt with the provided arguments.
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).
func (*TemplatedPrompt) Prompt ¶
func (p *TemplatedPrompt) Prompt() *mcp.Prompt
Prompt returns 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.
Returns:
- string: The service ID.