/** * Contract-as-Code Validator. * * Validates MCP server behavior against defined contract expectations. * Contracts define expected tools, parameters, and output constraints, * enabling CI/CD integration and regression detection. */ import type { MCPTool, MCPToolCallResult } from '../transport/types.js'; import type { ChangeSeverity } from '../baseline/types.js'; /** * A contract definition for an MCP server. */ export interface Contract { /** Contract schema version */ version: string; /** Server metadata */ server?: { /** Expected server name */ name?: string; /** Minimum required version */ minVersion?: string; }; /** Tool contracts */ tools: Record; /** Resource contracts */ resources?: Record; } /** * Contract for a single tool. */ export interface ToolContract { /** Whether this tool is required to exist */ required?: boolean; /** Input parameter contracts */ input?: Record; /** Output validation rules */ output?: OutputContract; /** Expected behavior description */ description?: string; } /** * Contract for a parameter. */ export interface ParameterContract { /** Whether this parameter is required */ required?: boolean; /** Expected type (string, number, boolean, array, object) */ type?: string; /** Expected format (date_iso8601, email, url, etc.) */ format?: string; /** Minimum value (for numbers) */ min?: number; /** Maximum value (for numbers) */ max?: number; /** Allowed enum values */ enum?: unknown[]; /** Regex pattern the value must match */ pattern?: string; } /** * Contract for tool output. */ export interface OutputContract { /** Paths that must be present in the output */ must_contain?: OutputAssertion[]; /** Paths that must not be present in the output */ must_not_contain?: OutputAssertion[]; /** Content type assertion */ content_type?: 'json' | 'text' | 'markdown'; } /** * A single output assertion. */ export interface OutputAssertion { /** JSONPath to check */ path: string; /** Expected type at path */ type?: string; /** Regex pattern the value must match */ pattern?: string; /** Expected exact value */ value?: unknown; } /** * Contract for a resource. */ export interface ResourceContract { /** Whether this resource is required */ required?: boolean; /** Expected MIME type */ mimeType?: string; } /** * A contract violation. */ export interface ContractViolation { /** Type of violation */ type: ViolationType; /** Severity level */ severity: ChangeSeverity; /** Tool name (if applicable) */ tool?: string; /** Parameter name (if applicable) */ parameter?: string; /** JSONPath (if applicable) */ path?: string; /** Expected value/state */ expected: string; /** Actual value/state */ actual: string; /** Human-readable message */ message: string; } /** * Types of contract violations. */ export type ViolationType = 'missing_tool' | 'unexpected_tool' | 'missing_parameter' | 'unexpected_parameter' | 'type_mismatch' | 'format_mismatch' | 'constraint_violation' | 'output_assertion_failed' | 'missing_output_field' | 'unexpected_output_field' | 'content_type_mismatch'; /** * Result of contract validation. */ export interface ContractValidationResult { /** Whether the contract passed */ passed: boolean; /** Overall severity of violations */ severity: ChangeSeverity; /** All violations found */ violations: ContractViolation[]; /** Summary counts */ summary: { totalViolations: number; breakingCount: number; warningCount: number; infoCount: number; toolsChecked: number; toolsPassed: number; }; /** Validation mode used */ mode: 'strict' | 'lenient' | 'report'; } /** * Options for contract validation. */ export interface ContractValidationOptions { /** Validation mode */ mode?: 'strict' | 'lenient' | 'report'; /** Whether to validate output assertions (requires calling tools) */ validateOutput?: boolean; /** Function to call tools for output validation */ callTool?: (toolName: string, args: Record) => Promise; /** Whether to fail on unexpected tools */ failOnUnexpectedTools?: boolean; } /** * Load a contract from a file. */ export declare function loadContract(filePath: string): Contract; /** * Find a contract file in the given directory. */ export declare function findContractFile(directory: string): string | null; /** * Validate an MCP server against a contract. */ export declare function validateContract(contract: Contract, tools: MCPTool[], options?: ContractValidationOptions): Promise; /** * Generate a contract from current server state. */ export declare function generateContract(tools: MCPTool[], serverName?: string): Contract; /** * Generate contract YAML from contract object. */ export declare function generateContractYaml(contract: Contract): string; /** * Generate markdown report for contract validation. */ export declare function generateContractValidationMarkdown(result: ContractValidationResult): string; //# sourceMappingURL=validator.d.ts.map