Documentation
¶
Overview ¶
Package server implements the MCP (Model Context Protocol) server for database operations.
Index ¶
- type MCPServer
- func (ms *MCPServer) AddCustomTool(name, description, sourceName, query string, parameters []ToolParam) error
- func (ms *MCPServer) AddSource(name string, src core.Source, readOnly bool)
- func (ms *MCPServer) ConfigureSecurity(maxRowLimit int, enablePIIMasking bool, piiPatterns []security.MaskPattern, ...) error
- func (ms *MCPServer) GetSchemaContext() string
- func (ms *MCPServer) LoadSchemas(ctx context.Context) error
- func (ms *MCPServer) StartStdio() error
- type ToolParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer represents the MCP server instance that handles database queries.
func NewMCPServer ¶
NewMCPServer creates a new MCP server instance with the specified name and version. It automatically registers the query_database tool for executing SQL queries.
func (*MCPServer) AddCustomTool ¶ added in v0.2.0
func (ms *MCPServer) AddCustomTool(name, description, sourceName, query string, parameters []ToolParam) error
AddCustomTool registers a custom tool with a predefined query. Each parameter carries a Type that determines the validation applied before the value is interpolated into the query template — see ToolParam for details.
func (*MCPServer) AddSource ¶
AddSource registers a database source with the given name. This makes the source available for query execution via the MCP protocol.
func (*MCPServer) ConfigureSecurity ¶ added in v0.2.0
func (ms *MCPServer) ConfigureSecurity(maxRowLimit int, enablePIIMasking bool, piiPatterns []security.MaskPattern, allowedKeywords, blockedKeywords []string) error
ConfigureSecurity initializes security components with config values.
func (*MCPServer) GetSchemaContext ¶ added in v0.2.0
GetSchemaContext returns the pre-built schema context for use in AI prompts.
func (*MCPServer) LoadSchemas ¶ added in v0.2.0
LoadSchemas loads database schemas from all sources and builds the context prompt. This should be called after all sources are added and connected.
func (*MCPServer) StartStdio ¶
StartStdio starts the MCP server using stdio transport. This is the standard transport for Claude Desktop integration.
type ToolParam ¶ added in v0.4.4
type ToolParam struct {
Name string
Type string // "string" | "integer" | "number" | "date" | "identifier"
Required bool
Default string
}
ToolParam describes a single typed parameter accepted by a custom tool. Type drives the validation applied before the value is interpolated into the query template, providing the strongest protection against SQL injection.
Supported types:
- "integer" — value must parse as a 64-bit integer; interpolated bare (no quotes needed)
- "number" — value must parse as a 64-bit float; interpolated bare
- "date" — value must match YYYY-MM-DD; interpolated bare (use quotes in template)
- "identifier" — value must match ^[A-Za-z0-9_]+$; safe for unquoted interpolation
- "string" — default; single quotes are escaped ('→”) for safe interpolation inside SQL string literals — always wrap {{param}} in quotes in the template