warnings

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInstructionsTooLarge         = "INSTRUCTIONS_TOO_LARGE"
	CodeMCPServerUnreachable         = "MCP_SERVER_UNREACHABLE"
	CodeMCPTooManyServers            = "MCP_TOO_MANY_SERVERS_ENABLED"
	CodeMCPTooManyToolsTotal         = "MCP_TOO_MANY_TOOLS_TOTAL"
	CodeMCPServerTooManyTools        = "MCP_SERVER_TOO_MANY_TOOLS"
	CodeMCPToolSchemaBloatTotal      = "MCP_TOOL_SCHEMA_BLOAT_TOTAL"
	CodeMCPToolSchemaBloatServer     = "MCP_TOOL_SCHEMA_BLOAT_SERVER"
	CodeMCPToolNameCollision         = "MCP_TOOL_NAME_COLLISION"
	CodeWarningNoiseModeInvalid      = "WARNING_NOISE_MODE_INVALID"
	CodePolicySecretInURL            = "POLICY_SECRET_IN_URL"
	CodePolicyCodexHeaderForm        = "POLICY_CODEX_HEADER_FORM_UNSUPPORTED"
	CodePolicyCapabilityMismatch     = "POLICY_CLIENT_CAPABILITY_MISMATCH"
	CodePolicyAgentSpecificOverrides = "POLICY_AGENT_SPECIFIC_OVERRIDES"
	CodePolicyClaudeReasoningUnknown = "POLICY_CLAUDE_REASONING_EFFORT_UNKNOWN"
)

Warning codes.

View Source
const (
	SourceInternal           = "internal"
	SourceNetwork            = "network"
	SourceExternalDependency = "external dependency"
)

Source labels where a warning originates.

View Source
const (
	SeverityWarning  = "warning"
	SeverityCritical = "critical"
)

Severity labels whether a warning should be considered critical.

View Source
const (
	// NoiseModeDefault keeps all warnings.
	NoiseModeDefault = "default"
	// NoiseModeReduce hides suppressible non-critical warnings.
	NoiseModeReduce = "reduce"
	// NoiseModeQuiet suppresses all warning output.
	NoiseModeQuiet = "quiet"
)

Variables

View Source
var NewMCPClientFunc = func(impl *mcp.Implementation, opts *mcp.ClientOptions) mcpClientInterface {
	return &realMCPClient{client: mcp.NewClient(impl, opts)}
}

NewMCPClientFunc is a mockable function for creating MCP clients.

Functions

func CheckMCPServers

func CheckMCPServers(ctx context.Context, cfg *config.ProjectConfig, connector Connector, statusFn MCPDiscoveryStatusFunc) ([]Warning, MCPSummary, error)

CheckMCPServers performs discovery on enabled MCP servers and checks against warning thresholds. cfg supplies the configured thresholds; nil thresholds disable the corresponding warnings. statusFn is an optional callback invoked with discovery events; it is safe to pass nil. It returns the emitted warnings plus an MCPSummary of the aggregate measurements from the same discovery pass (summary.Available is false when servers could not be resolved).

func EstimateTokens

func EstimateTokens(s string) int

EstimateTokens estimates the token count for a given UTF-8 string using a heuristic. Heuristic: T = max(ceil(B/3), ceil(R/4)) * 1.10 where B is the byte length and R is the rune count.

func MeasureInstructions added in v0.11.0

func MeasureInstructions(rootDir string) (int, string, error)

MeasureInstructions returns the estimated token count of the combined instruction payload along with the source subject (e.g. "AGENTS.md" or ".agent-layer/instructions/*"). It is the single source for instruction sizing used by both CheckInstructions and the doctor size summary. It returns an error only if the payload cannot be read.

Types

type Connector

type Connector interface {
	ConnectAndDiscover(ctx context.Context, server projection.ResolvedMCPServer) DiscoveryResult
}

Connector interface for mocking.

type DiscoveryResult

type DiscoveryResult struct {
	ServerID     string
	Tools        []ToolDef
	SchemaTokens int
	Error        error
}

DiscoveryResult contains the results of discovering tools from an MCP server.

type MCPDiscoveryEvent added in v0.5.7

type MCPDiscoveryEvent struct {
	ServerID string
	Status   MCPDiscoveryStatus
	Err      error
}

MCPDiscoveryEvent describes a discovery event for a single MCP server.

type MCPDiscoveryStatus added in v0.5.7

type MCPDiscoveryStatus string

MCPDiscoveryStatus is the status of a discovery event for an MCP server.

const (
	// MCPDiscoveryStatusStart indicates a server discovery has started.
	MCPDiscoveryStatusStart MCPDiscoveryStatus = "start"
	// MCPDiscoveryStatusDone indicates a server discovery completed successfully.
	MCPDiscoveryStatusDone MCPDiscoveryStatus = "done"
	// MCPDiscoveryStatusError indicates a server discovery completed with an error.
	MCPDiscoveryStatusError MCPDiscoveryStatus = "error"
)

type MCPDiscoveryStatusFunc added in v0.5.7

type MCPDiscoveryStatusFunc func(event MCPDiscoveryEvent)

MCPDiscoveryStatusFunc handles a discovery event emitted during MCP server discovery. The function may be invoked concurrently from multiple goroutines.

type MCPSummary added in v0.11.0

type MCPSummary struct {
	// Available is false when enabled servers could not be resolved at all (in which case
	// the remaining counts are meaningless and should not be reported).
	Available bool
	// EnabledServers is the count of enabled, resolvable servers.
	EnabledServers int
	// ReachableServers is the count of servers discovery succeeded for. When it is less
	// than EnabledServers, the tool/schema totals exclude the unreachable servers.
	ReachableServers int
	// TotalTools is the number of tools discovered across reachable servers.
	TotalTools int
	// TotalSchemaTokens is the estimated tool-schema token count across reachable servers.
	TotalSchemaTokens int
}

MCPSummary holds aggregate MCP discovery measurements for reporting (e.g. the doctor size summary). It is produced by the same single discovery pass that emits warnings.

type RealConnector

type RealConnector struct{}

RealConnector implements Connector using the SDK.

func (*RealConnector) ConnectAndDiscover

func (r *RealConnector) ConnectAndDiscover(ctx context.Context, server projection.ResolvedMCPServer) DiscoveryResult

ConnectAndDiscover connects to an MCP server and discovers its tools.

type ToolDef

type ToolDef struct {
	Name   string
	Tokens int
}

ToolDef represents a discovered tool from an MCP server.

type Warning

type Warning struct {
	Code     string
	Subject  string
	Message  string
	Fix      string
	Details  []string
	Source   string
	Severity string
	// NoiseSuppressible marks warnings that can be hidden by conservative noise controls.
	// Critical warnings are never suppressed even if this flag is true.
	NoiseSuppressible bool
}

Warning represents a warning message.

func ApplyNoiseControl added in v0.8.0

func ApplyNoiseControl(items []Warning, mode string) []Warning

ApplyNoiseControl applies a conservative noise filter to warning output. mode is the warnings.noise_mode value from config.

func CheckInstructions

func CheckInstructions(rootDir string, threshold *int) ([]Warning, error)

CheckInstructions checks if the combined instruction payload exceeds the threshold. rootDir is the project root directory; threshold is the max token count (nil disables warnings). It returns any warnings and an error if the payload cannot be read.

func CheckPolicy added in v0.8.0

func CheckPolicy(project *config.ProjectConfig) []Warning

CheckPolicy returns static policy warnings that do not require network calls.

func (Warning) String

func (w Warning) String() string

Jump to

Keyboard shortcuts

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