Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package server implements the MCP (Model Context Protocol) server for database operations.

Index

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

func NewMCPServer(name, version string) *MCPServer

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

func (ms *MCPServer) AddSource(name string, src core.Source, readOnly bool)

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

func (ms *MCPServer) GetSchemaContext() string

GetSchemaContext returns the pre-built schema context for use in AI prompts.

func (*MCPServer) LoadSchemas added in v0.2.0

func (ms *MCPServer) LoadSchemas(ctx context.Context) error

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

func (ms *MCPServer) StartStdio() error

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

Jump to

Keyboard shortcuts

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