mcpapi

package
v0.8.1 Latest Latest
Warning

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

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

README

MCP Interface Module

Thin MCP adapter for exposing DeltaScope audit and rule-discovery capabilities to agent clients.

Files

File Responsibility
audit_tool.go Implements the MCP audit_sql tool on top of the shared DeltaScope audit path
connection.go Validates and resolves direct and referenced metadata-aware connection inputs
connection_test.go Verifies MCP connection normalization and safety rules
output_schema.go Publishes explicit success output schemas for official MCP tools
rule_tools.go Builds structured payloads for MCP rule-discovery tools
rule_tools_test.go Verifies describe_rule, list_rules, and get_capabilities behavior
server.go Builds the MCP server and registers the official DeltaScope tools
server_test.go Verifies MCP bootstrap metadata and core tool registration
tool_errors.go Shapes stable structured MCP tool errors and error-code mapping

Exports

  • AuditSQLParams
  • Config
  • NewServer(config)
  • ResolveAuditConnection(params, options)

Notes

  • The MCP layer stays thin and reuses shared DeltaScope audit, rule-catalog, and metadata-preparation logic.
  • The current scope supports stdio MCP bootstrap, offline audit, metadata-aware audit context, and rule-discovery tools.
  • get_capabilities is MCP-client-facing and summarizes transport, official tool names, audit result fields, connection inputs, and stable structured error codes.

Dependencies

  • Upstream: cmd/deltascope-mcp
  • Downstream: shared audit and rule-catalog layers under pkg/deltascope and internal/...

Update Rule

  • If members/interfaces/dependencies change, update this file in same change.

Documentation

Overview

Package mcpapi exposes the MCP adapter for DeltaScope. input: audit_sql MCP requests, shared DeltaScope public audit API, and resolved run-context metadata output: structured MCP audit_sql responses that preserve DeltaScope's public audit result body pos: MCP audit tool adapter between tool invocations and the shared audit engine note: if this file changes, update this header and module README.md.

Package mcpapi exposes the MCP adapter for DeltaScope. input: audit tool connection parameters, local connection config files, and password lookup sources output: normalized metadata-aware connection settings for MCP audit requests pos: MCP connection resolution layer between tool inputs and metadata provider wiring note: if this file changes, update this header and module README.md.

Package mcpapi exposes the MCP adapter for DeltaScope. input: MCP success payload types that need explicit output-schema publication output: resolved JSON Schema objects for official DeltaScope MCP tool outputs pos: schema publication helpers for MCP tool registration metadata note: if this file changes, update this header and module README.md.

Package mcpapi exposes the MCP adapter for DeltaScope. input: shipped rule catalog entries and DeltaScope capability metadata for MCP rule tools output: structured payload builders for describe_rule, list_rules, and get_capabilities pos: MCP rule-discovery helpers above the domain rule catalog note: if this file changes, update this header and module README.md.

Package mcpapi exposes the MCP adapter for DeltaScope. input: MCP server construction inputs, DeltaScope version metadata, and tool registration definitions output: ready-to-run MCP server instances that expose the official DeltaScope tool surface pos: interface adapter between the Go MCP SDK and DeltaScope audit/rule capabilities note: if this file changes, update this header and module README.md.

Package mcpapi exposes the MCP adapter for DeltaScope. input: adapter and audit errors arising during MCP tool execution output: stable MCP tool error payloads with machine-readable codes and human-readable messages pos: shared error-shaping helpers for MCP tool handlers note: if this file changes, update this header and module README.md.

Index

Constants

View Source
const DefaultConnectionsPath = "~/.config/deltascope/connections.yaml"

DefaultConnectionsPath is the default local path used to resolve MCP connection_ref names.

Variables

This section is empty.

Functions

func NewServer

func NewServer(config Config) *sdkmcp.Server

NewServer returns a configured MCP server with the core DeltaScope tools registered.

Types

type AuditContext

type AuditContext struct {
	Mode           string         `json:"mode,omitempty"`
	Dialect        string         `json:"dialect,omitempty"`
	DialectSource  string         `json:"dialect_source,omitempty"`
	Schema         string         `json:"schema,omitempty"`
	SchemaSource   string         `json:"schema_source,omitempty"`
	MetadataSource MetadataSource `json:"metadata_source,omitempty"`
}

AuditContext describes how one MCP audit_sql result was produced.

type AuditSQLParams

type AuditSQLParams struct {
	SQL           string           `json:"sql"`
	Dialect       string           `json:"dialect,omitempty"`
	ConfigPath    string           `json:"config_path,omitempty"`
	ConnectionRef string           `json:"connection_ref,omitempty"`
	Connection    *ConnectionInput `json:"connection,omitempty"`
}

AuditSQLParams describes the MCP-facing audit_sql request contract.

type AuditSQLResult

type AuditSQLResult struct {
	publicapi.Result
	Context AuditContext `json:"context"`
}

AuditSQLResult preserves the public DeltaScope result body and adds MCP context.

type Config

type Config struct {
	Version         string
	ConnectionsPath string
}

Config configures the DeltaScope MCP server bootstrap.

type ConnectionInput

type ConnectionInput struct {
	Host         string `json:"host,omitempty" yaml:"host"`
	Port         int    `json:"port,omitempty" yaml:"port"`
	Socket       string `json:"socket,omitempty" yaml:"socket"`
	User         string `json:"user,omitempty" yaml:"user"`
	Schema       string `json:"schema,omitempty" yaml:"schema"`
	Dialect      string `json:"dialect,omitempty" yaml:"dialect"`
	Password     string `json:"password,omitempty" yaml:"password"`
	PasswordEnv  string `json:"password_env,omitempty" yaml:"password_env"`
	PasswordFile string `json:"password_file,omitempty" yaml:"password_file"`
}

ConnectionInput describes one direct or referenced metadata-aware connection.

type MetadataSource

type MetadataSource string

MetadataSource identifies how one metadata-aware audit connection was selected.

const (
	// MetadataSourceNone indicates the request stayed offline.
	MetadataSourceNone MetadataSource = "none"
	// MetadataSourceConnectionRef indicates the request used a named connection reference.
	MetadataSourceConnectionRef MetadataSource = "connection_ref"
	// MetadataSourceDirect indicates the request used direct inline connection settings.
	MetadataSourceDirect MetadataSource = "direct"
)

type ResolveConnectionOptions

type ResolveConnectionOptions struct {
	ConnectionsPath string
	LookupEnv       func(string) (string, bool)
	ReadFile        func(string) ([]byte, error)
}

ResolveConnectionOptions configures connection resolution dependencies.

type ResolvedConnection

type ResolvedConnection struct {
	Enabled  bool
	Source   MetadataSource
	RefName  string
	RefPath  string
	Host     string
	Port     int
	Socket   string
	User     string
	Schema   string
	Dialect  string
	Password string
}

ResolvedConnection is the normalized metadata-aware connection used by MCP audit flows.

func ResolveAuditConnection

func ResolveAuditConnection(params AuditSQLParams, options ResolveConnectionOptions) (ResolvedConnection, error)

ResolveAuditConnection validates and normalizes the MCP audit_sql connection inputs.

Jump to

Keyboard shortcuts

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