mcpserver

package
v0.158.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcpserver exposes selected reads of a separately running local DataTug agent over MCP. It owns neither the agent process nor its policy session.

Index

Constants

View Source
const AgentHeader = "X-DataTug-Agent"

AgentHeader declares an agent context to the local agent. The context is self-declared: local masking is accident prevention for honest agents.

View Source
const (
	DefaultAgentURL = "http://127.0.0.1:8989"
)

Variables

This section is empty.

Functions

func New

func New(client *Client, version string) *mcp.Server

New builds the MCP server. The SDK handles protocol negotiation and framing.

func Run

func Run(ctx context.Context, client *Client, version string, in io.ReadCloser, out io.WriteCloser) error

Run serves newline-delimited protocol JSON until stdin closes or ctx ends. The caller owns these streams; no startup text or agent links are printed.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client deliberately has no exported HTTP passthrough or configurable transport.

func NewClient

func NewClient(address string) (*Client, error)

NewClient is the MCP client: MCP is always an agent context, so every request it makes carries AgentHeader.

func NewCommandClient added in v0.142.0

func NewCommandClient(address string, agent bool) (*Client, error)

NewCommandClient is NewClient for CLI commands, which declare an agent context only when asked to (agent is true).

It accepts only a literal loopback address or localhost, with no path, credentials, query or fragment. Proxies and redirects are disabled: a redirect to another port must never receive the original agent's bearer token.

func (*Client) ChangeLabel added in v0.142.0

func (c *Client) ChangeLabel(ctx context.Context, scope MeaningScope, ifRevision string, change meaninglabels.Change) (LabelChangeResult, error)

ChangeLabel applies one label change at ifRevision. With an agent context the local agent accepts only propose.

func (*Client) Close

func (c *Client) Close()

Close releases idle HTTP connections; the separately owned agent keeps running.

func (*Client) DescribeMeaning added in v0.142.0

func (c *Client) DescribeMeaning(ctx context.Context, scope MeaningScope) (MeaningDescription, error)

DescribeMeaning answers what a source's tables and columns mean, how they join and which are sensitive, in one call. It never returns values.

func (*Client) FindMeaning added in v0.142.0

func (c *Client) FindMeaning(ctx context.Context, scope MeaningScope, text string) (MeaningMatches, error)

FindMeaning finds the tables and columns whose names, entities or fields match text (1–200 characters).

func (*Client) MeaningLabels added in v0.142.0

func (c *Client) MeaningLabels(ctx context.Context, scope MeaningScope) (LabelsList, error)

MeaningLabels lists every effective label of a source, with the stored label document and its revision.

func (*Client) ReadTable added in v0.142.0

func (c *Client) ReadTable(ctx context.Context, in TableReadRequest) (TableRead, error)

ReadTable reads one table through the agent's structured read boundary: labelled columns come back masked (null cells) with their protection.

type Condition added in v0.142.0

type Condition struct {
	Column string `json:"column" jsonschema:"Column name from datatug_describe_meaning; a masked column is refused"`
	Op     string `json:"op" jsonschema:"One of =, !=, <, <=, >, >="`
	Value  any    `json:"value" jsonschema:"A JSON string, number or boolean"`
}

Condition is one structured-read filter; Value is a JSON string, number or boolean.

type EffectiveLabel added in v0.142.0

type EffectiveLabel struct {
	Class         string `json:"class,omitempty"`
	Kind          string `json:"kind,omitempty"`
	Origin        string `json:"origin,omitempty"`
	State         string `json:"state,omitempty"`
	Rule          string `json:"rule,omitempty"`
	Revealable    bool   `json:"revealable"`
	NonRevealable bool   `json:"nonRevealable"`
}

EffectiveLabel is a column's effective sensitivity label.

type FieldMeaning added in v0.142.0

type FieldMeaning struct {
	Entity      string `json:"entity,omitempty"`
	Field       string `json:"field,omitempty"`
	Title       string `json:"title,omitempty"`
	Provenance  string `json:"provenance,omitempty"`
	Description string `json:"description,omitempty"`
}

FieldMeaning is the semantic-layer meaning a table or column maps to.

type ForeignKey added in v0.142.0

type ForeignKey struct {
	Columns    []string `json:"columns"`
	RefTable   TableRef `json:"refTable"`
	RefColumns []string `json:"refColumns"`
}

ForeignKey is a declared foreign key of a described table.

type JoinEnd added in v0.142.0

type JoinEnd struct {
	Table   string   `json:"table"`
	Columns []string `json:"columns"`
}

JoinEnd is one side of a join.

type LabelChangeResult added in v0.142.0

type LabelChangeResult struct {
	Revision string              `json:"revision"`
	Event    meaninglabels.Event `json:"event"`
}

LabelChangeResult is the meanings/labels/change answer.

type LabelsColumn added in v0.142.0

type LabelsColumn struct {
	Name  string          `json:"name"`
	Type  string          `json:"type"`
	Label *EffectiveLabel `json:"label,omitempty"`
}

LabelsColumn is one column in the meanings/labels answer.

type LabelsList added in v0.142.0

type LabelsList struct {
	Revision string                 `json:"revision"`
	Tables   []LabelsTable          `json:"tables"`
	Stored   meaninglabels.Document `json:"stored"`
}

LabelsList is the meanings/labels answer.

type LabelsTable added in v0.142.0

type LabelsTable struct {
	Schema   string         `json:"schema"`
	Name     string         `json:"name"`
	Kind     string         `json:"kind"`
	Reviewed bool           `json:"reviewed"`
	Columns  []LabelsColumn `json:"columns"`
}

LabelsTable is one table in the meanings/labels answer.

type MeaningColumn added in v0.142.0

type MeaningColumn struct {
	Name     string          `json:"name"`
	Type     string          `json:"type"`
	Nullable *bool           `json:"nullable,omitempty"`
	Meaning  *FieldMeaning   `json:"meaning,omitempty"`
	Label    *EffectiveLabel `json:"label,omitempty"`
}

MeaningColumn is one column of a described table.

type MeaningDescription added in v0.142.0

type MeaningDescription struct {
	Source         string         `json:"source"`
	LabelsRevision string         `json:"labelsRevision"`
	Notice         string         `json:"notice,omitempty"`
	Tables         []MeaningTable `json:"tables"`
	Joins          []MeaningJoin  `json:"joins"`
}

MeaningDescription is the meanings/describe answer. It contains no values.

type MeaningJoin added in v0.142.0

type MeaningJoin struct {
	From       JoinEnd `json:"from"`
	To         JoinEnd `json:"to"`
	Provenance string  `json:"provenance"`
}

MeaningJoin is a join implied by a foreign key or by shared meaning.

type MeaningMatch added in v0.142.0

type MeaningMatch struct {
	Table   string          `json:"table"`
	Column  string          `json:"column,omitempty"`
	Type    string          `json:"type,omitempty"`
	Label   *EffectiveLabel `json:"label,omitempty"`
	Meaning *FieldMeaning   `json:"meaning,omitempty"`
}

MeaningMatch is one meanings/find match.

type MeaningMatches added in v0.142.0

type MeaningMatches struct {
	Matches []MeaningMatch `json:"matches"`
}

MeaningMatches is the meanings/find answer.

type MeaningScope added in v0.142.0

type MeaningScope struct {
	Project     string
	Environment string
	Source      string
	Tables      []string
}

MeaningScope names one source and, optionally, the tables to narrow to.

type MeaningTable added in v0.142.0

type MeaningTable struct {
	Schema      string          `json:"schema"`
	Name        string          `json:"name"`
	Kind        string          `json:"kind"`
	Reviewed    bool            `json:"reviewed"`
	Meanings    []FieldMeaning  `json:"meanings"`
	PrimaryKey  []string        `json:"primaryKey"`
	Columns     []MeaningColumn `json:"columns"`
	ForeignKeys []ForeignKey    `json:"foreignKeys"`
}

MeaningTable is one table or view of a described source.

type Order added in v0.142.0

type Order struct {
	Column string `json:"column" jsonschema:"Column name; a masked column is refused"`
	Desc   bool   `json:"desc,omitempty" jsonschema:"Sort descending"`
}

Order is one structured-read sort key.

type RawRecordset added in v0.142.0

type RawRecordset struct {
	Columns []apicontract.Column `json:"columns"`
	Rows    [][]json.RawMessage  `json:"rows"`
}

RawRecordset keeps every cell exactly as the agent returned it. A masked column's cells are null.

type TableRead added in v0.142.0

type TableRead struct {
	Recordset   RawRecordset                        `json:"recordset"`
	Limitations []apicontract.Limitation            `json:"limitations"`
	Provenance  apicontract.Provenance              `json:"provenance"`
	Truncated   bool                                `json:"truncated"`
	Protection  map[string]meaninglabels.Protection `json:"protection,omitempty"`
	Notice      string                              `json:"notice,omitempty"`
}

TableRead is the records/read answer.

type TableReadRequest added in v0.142.0

type TableReadRequest struct {
	Project     string
	Environment string
	Source      string
	Schema      string
	Table       string
	Columns     []string
	Where       []Condition
	OrderBy     []Order
	Limit       int
	// Reveal names revealable columns a person reveals for this read only
	// ("*" for every revealable column). The agent refuses it for an agent.
	Reveal []string
}

TableReadRequest is a structured table read through the masking boundary.

type TableRef added in v0.142.0

type TableRef struct {
	Schema string `json:"schema"`
	Name   string `json:"name"`
}

TableRef names a table.

Jump to

Keyboard shortcuts

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