Documentation
¶
Index ¶
- func FormatResponse(response interface{}, err error) (interface{}, error)
- func FromError(err error) (interface{}, error)
- type BaseToolType
- type ExecuteTool
- type ListDatabasesTool
- type PerformanceTool
- type QueryTool
- type Response
- type SchemaTool
- type ServerWrapper
- type TextContent
- type ToolRegistry
- type ToolType
- type ToolTypeFactory
- type TransactionTool
- type UseCaseProvider
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatResponse ¶ added in v1.5.0
FormatResponse converts any response type to a properly formatted MCP response
Types ¶
type BaseToolType ¶ added in v1.5.0
type BaseToolType struct {
// contains filtered or unexported fields
}
BaseToolType provides common functionality for tool types
func (*BaseToolType) GetDescription ¶ added in v1.5.0
func (b *BaseToolType) GetDescription(dbID string) string
GetDescription returns a description for the tool type
func (*BaseToolType) GetName ¶ added in v1.5.0
func (b *BaseToolType) GetName() string
GetName returns the name of the tool type
type ExecuteTool ¶ added in v1.5.0
type ExecuteTool struct {
BaseToolType
}
ExecuteTool handles SQL statement execution
func NewExecuteTool ¶ added in v1.5.0
func NewExecuteTool() *ExecuteTool
NewExecuteTool creates a new execute tool type
func (*ExecuteTool) CreateTool ¶ added in v1.5.0
func (t *ExecuteTool) CreateTool(name string, dbID string) interface{}
CreateTool creates an execute tool
func (*ExecuteTool) HandleRequest ¶ added in v1.5.0
func (t *ExecuteTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles execute tool requests
type ListDatabasesTool ¶ added in v1.5.0
type ListDatabasesTool struct {
BaseToolType
}
ListDatabasesTool handles listing available databases
func NewListDatabasesTool ¶ added in v1.5.0
func NewListDatabasesTool() *ListDatabasesTool
NewListDatabasesTool creates a new list databases tool type
func (*ListDatabasesTool) CreateTool ¶ added in v1.5.0
func (t *ListDatabasesTool) CreateTool(name string, dbID string) interface{}
CreateTool creates a list databases tool
func (*ListDatabasesTool) HandleRequest ¶ added in v1.5.0
func (t *ListDatabasesTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles list databases tool requests
type PerformanceTool ¶ added in v1.5.0
type PerformanceTool struct {
BaseToolType
}
PerformanceTool handles query performance analysis
func NewPerformanceTool ¶ added in v1.5.0
func NewPerformanceTool() *PerformanceTool
NewPerformanceTool creates a new performance tool type
func (*PerformanceTool) CreateTool ¶ added in v1.5.0
func (t *PerformanceTool) CreateTool(name string, dbID string) interface{}
CreateTool creates a performance analysis tool
func (*PerformanceTool) HandleRequest ¶ added in v1.5.0
func (t *PerformanceTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles performance tool requests
type QueryTool ¶ added in v1.5.0
type QueryTool struct {
BaseToolType
}
QueryTool handles SQL query operations
func NewQueryTool ¶ added in v1.5.0
func NewQueryTool() *QueryTool
NewQueryTool creates a new query tool type
func (*QueryTool) CreateTool ¶ added in v1.5.0
CreateTool creates a query tool
func (*QueryTool) HandleRequest ¶ added in v1.5.0
func (t *QueryTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles query tool requests
type Response ¶ added in v1.5.0
type Response struct {
Content []TextContent `json:"content"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Response is a standardized response format for MCP tools
func FromString ¶ added in v1.5.0
FromString creates a response from a string
func NewResponse ¶ added in v1.5.0
func NewResponse() *Response
NewResponse creates a new empty Response
Example ¶
// Create a new response with text content
resp := NewResponse().WithText("Hello, world!")
// Add metadata
resp.WithMetadata("source", "example")
// Convert to map for JSON serialization
output, err := json.Marshal(resp)
if err != nil {
// This is an example, but we should still check
fmt.Println("Error marshaling:", err)
return
}
fmt.Println(string(output))
Output: {"content":[{"type":"text","text":"Hello, world!"}],"metadata":{"source":"example"}}
func (*Response) WithMetadata ¶ added in v1.5.0
WithMetadata adds metadata to the response
type SchemaTool ¶ added in v1.5.0
type SchemaTool struct {
BaseToolType
}
SchemaTool handles database schema exploration
func NewSchemaTool ¶ added in v1.5.0
func NewSchemaTool() *SchemaTool
NewSchemaTool creates a new schema tool type
func (*SchemaTool) CreateTool ¶ added in v1.5.0
func (t *SchemaTool) CreateTool(name string, dbID string) interface{}
CreateTool creates a schema tool
func (*SchemaTool) HandleRequest ¶ added in v1.5.0
func (t *SchemaTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles schema tool requests
type ServerWrapper ¶ added in v1.5.0
type ServerWrapper struct {
// contains filtered or unexported fields
}
ServerWrapper provides a wrapper around server.MCPServer to handle type assertions
func NewServerWrapper ¶ added in v1.5.0
func NewServerWrapper(mcpServer *server.MCPServer) *ServerWrapper
NewServerWrapper creates a new ServerWrapper
type TextContent ¶ added in v1.5.0
TextContent represents a text content item in a response
type ToolRegistry ¶
type ToolRegistry struct {
// contains filtered or unexported fields
}
ToolRegistry structure to handle tool registration
func NewToolRegistry ¶
func NewToolRegistry(mcpServer *server.MCPServer) *ToolRegistry
NewToolRegistry creates a new tool registry
func (*ToolRegistry) RegisterAllTools ¶
func (tr *ToolRegistry) RegisterAllTools(ctx context.Context, useCase UseCaseProvider) error
RegisterAllTools registers all tools with the server
func (*ToolRegistry) RegisterCursorCompatibleTools ¶ added in v1.5.0
func (tr *ToolRegistry) RegisterCursorCompatibleTools(ctx context.Context) error
RegisterCursorCompatibleTools is kept for backward compatibility but does nothing as we now register tools with simple names directly
func (*ToolRegistry) RegisterMockTools ¶ added in v1.4.1
func (tr *ToolRegistry) RegisterMockTools(ctx context.Context) error
RegisterMockTools registers mock tools with the server when no db connections available
type ToolType ¶ added in v1.5.0
type ToolType interface {
// GetName returns the base name of the tool type (e.g., "query", "execute")
GetName() string
// GetDescription returns a description for this tool type
GetDescription(dbID string) string
// CreateTool creates a tool with the specified name
// The returned tool must be compatible with server.MCPServer.AddTool's first parameter
CreateTool(name string, dbID string) interface{}
// HandleRequest handles tool requests for this tool type
HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
}
ToolType interface defines the structure for different types of database tools
type ToolTypeFactory ¶ added in v1.5.0
type ToolTypeFactory struct {
// contains filtered or unexported fields
}
ToolTypeFactory creates and manages tool types
func NewToolTypeFactory ¶ added in v1.5.0
func NewToolTypeFactory() *ToolTypeFactory
NewToolTypeFactory creates a new tool type factory with all registered tool types
func (*ToolTypeFactory) GetAllToolTypes ¶ added in v1.5.0
func (f *ToolTypeFactory) GetAllToolTypes() []ToolType
GetAllToolTypes returns all registered tool types
func (*ToolTypeFactory) GetToolType ¶ added in v1.5.0
func (f *ToolTypeFactory) GetToolType(name string) (ToolType, bool)
GetToolType returns a tool type by name
func (*ToolTypeFactory) GetToolTypeForSourceName ¶ added in v1.5.0
func (f *ToolTypeFactory) GetToolTypeForSourceName(sourceName string) (ToolType, string, bool)
GetToolTypeForSourceName finds the appropriate tool type for a source name
func (*ToolTypeFactory) Register ¶ added in v1.5.0
func (f *ToolTypeFactory) Register(toolType ToolType)
Register adds a tool type to the factory
type TransactionTool ¶ added in v1.5.0
type TransactionTool struct {
BaseToolType
}
TransactionTool handles database transactions
func NewTransactionTool ¶ added in v1.5.0
func NewTransactionTool() *TransactionTool
NewTransactionTool creates a new transaction tool type
func (*TransactionTool) CreateTool ¶ added in v1.5.0
func (t *TransactionTool) CreateTool(name string, dbID string) interface{}
CreateTool creates a transaction tool
func (*TransactionTool) HandleRequest ¶ added in v1.5.0
func (t *TransactionTool) HandleRequest(ctx context.Context, request server.ToolCallRequest, dbID string, useCase UseCaseProvider) (interface{}, error)
HandleRequest handles transaction tool requests
type UseCaseProvider ¶ added in v1.5.0
type UseCaseProvider interface {
ExecuteQuery(ctx context.Context, dbID, query string, params []interface{}) (string, error)
ExecuteStatement(ctx context.Context, dbID, statement string, params []interface{}) (string, error)
ExecuteTransaction(ctx context.Context, dbID, action string, txID string, statement string, params []interface{}, readOnly bool) (string, map[string]interface{}, error)
GetDatabaseInfo(dbID string) (map[string]interface{}, error)
ListDatabases() []string
GetDatabaseType(dbID string) (string, error)
}
UseCaseProvider interface abstracts database use case operations