MCP

Aegisv1

Cross-Field Patterns

Validate relationships and comparisons between fields in the same object.

Cross-field patterns enable sophisticated validation of field-to-field relationships within the same response object. Perfect for business rule validation, data consistency checks, and ensuring logical relationships between related data points.

Cross-Field Pattern Syntax

Use "match:crossField": "field1 operator field2" to compare fields within the same object. Supports <, <=, >, >=, =, and != operators.

Basic Cross-Field Validation

Cross-field patterns validate relationships between fields at the root level of your response object. These patterns are essential for ensuring data consistency and business rule compliance.

Numeric Comparisons

yaml
# Basic numeric field comparisons
expect:
  response:
    result:
      # Price validation
      "match:crossField": "discountPrice < originalPrice"
      
      # Quantity validation  
      "match:crossField": "currentStock >= minStock"
      
      # Capacity validation
      "match:crossField": "currentParticipants <= maxParticipants"
      
      # Range validation
      "match:crossField": "minPrice <= maxPrice"

Date & Time Comparisons

yaml
# Date field relationships
expect:
  response:
    result:
      # Event timing
      "match:crossField": "startDate < endDate"
      
      # Registration periods
      "match:crossField": "registrationStart < registrationEnd"
      
      # Account history
      "match:crossField": "lastLoginDate > accountCreatedDate"
      
      # Delivery scheduling
      "match:crossField": "nextDelivery > lastRestocked"

Equality & Inequality

yaml
# Field equality and inequality checks
expect:
  response:
    result:
      # Equality validation
      "match:crossField": "retailPrice = originalPrice"
      
      # Inequality validation  
      "match:crossField": "discountPrice != originalPrice"
      
      # Threshold validation
      "match:crossField": "age >= minAge"
      
      # Limit validation
      "match:crossField": "accountBalance <= creditLimit"

Business Rule Validation Examples

Real-world examples demonstrating how cross-field patterns validate complex business logic and data relationships.

Event Management

yaml
# Event timing and capacity validation
- it: "should validate event business rules"
  request:
    jsonrpc: "2.0"
    id: "event-validation"
    method: "tools/call"
    params:
      name: "get_event_data"
      arguments:
        eventId: "conference-2024"
  expect:
    response:
      jsonrpc: "2.0"
      id: "event-validation"
      result:
        # Event must end after it starts
        "match:crossField": "startDate < endDate"
        
        # Registration must close before event starts
        "match:crossField": "registrationEnd < startDate"
        
        # Current participants within limits
        "match:crossField": "currentParticipants <= maxParticipants"
        
        # Minimum viable participant count
        "match:crossField": "minParticipants <= currentParticipants"

Financial Validation

yaml
# Financial business rules and constraints
- it: "should validate financial transaction rules"
  request:
    jsonrpc: "2.0" 
    id: "financial-check"
    method: "tools/call"
    params:
      name: "get_transaction_data"
      arguments:
        accountId: "acc-12345"
  expect:
    response:
      jsonrpc: "2.0"
      id: "financial-check"
      result:
        # Transaction amount within limits
        "match:crossField": "amount >= minAmount"
        
        # Credit requirements
        "match:crossField": "creditScore >= minCreditScore"
        
        # Debt-to-income ratio compliance
        "match:crossField": "debtToIncomeRatio <= maxDebtToIncomeRatio"
        
        # Net amount calculation
        "match:crossField": "netAmount < amount"

Inventory Management

yaml
# Inventory and stock management validation
- it: "should validate inventory business rules"
  request:
    jsonrpc: "2.0"
    id: "inventory-check"
    method: "tools/call"
    params:
      name: "get_inventory_status"
      arguments:
        productId: "prod-789"
  expect:
    response:
      jsonrpc: "2.0"
      id: "inventory-check"
      result:
        # Stock level validation
        "match:crossField": "currentStock > minStock"
        
        # Available stock calculation
        "match:crossField": "availableStock <= currentStock"
        
        # Delivery scheduling
        "match:crossField": "nextDelivery > lastRestocked"
        
        # Warehouse capacity
        "match:crossField": "currentStock <= maxCapacity"

Nested Object Validation

Cross-field patterns support dot notation for validating relationships between fields in nested objects, enabling complex structural validation.

Nested Field Syntax

Use dot notation to access nested fields: object.field, parent.child.grandchild

yaml
# Nested object field comparisons
expect:
  response:
    result:
      # Event object validation
      "match:crossField": "event.startTime < event.endTime"
      
      # Pricing object validation
      "match:crossField": "pricing.discount <= pricing.maxDiscount"
      
      # User configuration validation
      "match:crossField": "user.age >= config.minimumAge"
      
      # Deep nested validation
      "match:crossField": "user.profile.maxConnections <= config.system.connectionLimit"

Complex Nested Examples

yaml
# Advanced nested object validation
- it: "should validate complex nested object relationships"
  request:
    jsonrpc: "2.0"
    id: "nested-validation"
    method: "tools/call"
    params:
      name: "get_complex_data"
  expect:
    response:
      jsonrpc: "2.0"
      id: "nested-validation"
      result:
        # Multi-level pricing validation
        "match:crossField": "pricing.wholesale.price < pricing.retail.price"
        
        # Resource usage validation
        "match:crossField": "stats.memory.used <= stats.memory.allocated"
        
        # Permission hierarchy validation
        "match:crossField": "user.level >= access.required"
        
        # Deep organizational structure
        "match:crossField": "company.division.team.member.clearanceLevel >= project.security.requirements.minClearance"

Financial Nested Validation

yaml
# Complex financial object validation
- it: "should validate nested financial structures"
  expect:
    response:
      result:
        # Account balance validation
        "match:crossField": "transaction.amount <= account.balance"
        
        # Credit limit validation
        "match:crossField": "account.credit.used < account.credit.limit"
        
        # Order processing validation
        "match:crossField": "order.items.total.price <= customer.account.creditLimit"
        
        # Shipping timeline validation
        "match:crossField": "order.shipping.estimatedDelivery > order.processing.completedDate"

Mixed Data Types

Cross-field patterns automatically handle type conversion for common scenarios, enabling flexible validation across different data types.

String-Number Conversion

yaml
# Automatic type conversion for numeric strings
expect:
  response:
    result:
      # String numbers compared as numbers
      "match:crossField": "config.performance.timeout > config.performance.retryDelay"
      
      # Mixed string/number comparison
      timeout: "5000"      # String
      maxTimeout: 10000    # Number
      "match:crossField": "timeout < maxTimeout"    # Converts "5000" to 5000

Date String Handling

yaml
# Date string comparisons
expect:
  response:
    result:
      # ISO date string comparison
      "match:crossField": "schedule.meeting.startTime < schedule.meeting.endTime"
      
      # Date strings with time zones
      startDate: "2024-03-15T09:00:00Z"
      endDate: "2024-03-15T17:00:00Z"
      "match:crossField": "startDate < endDate"

Special Field Names

Cross-field patterns support field names with hyphens, underscores, and other special characters common in API responses.

yaml
# Field names with special characters
expect:
  response:
    result:
      # Hyphenated field names
      "match:crossField": "user-data.max-count > current-usage.active-count"
      
      # Underscore field names
      "match:crossField": "max_concurrent_users >= current_active_sessions"
      
      # Mixed naming conventions
      "match:crossField": "apiResponse.max-timeout > currentRequest.retry_delay"

Combining with Other Patterns

Cross-field patterns work seamlessly with other MCP Aegis patterns for comprehensive validation scenarios.

yaml
# Combine cross-field with other patterns
expect:
  response:
    result:
      # Cross-field validation
      "match:crossField": "metrics.performance.score >= metrics.baseline.minimum"
      
      # Combined with other pattern types
      status: "match:contains:active"           # String pattern
      dataPoints: "match:arrayLength:5"         # Array pattern
      lastUpdated: "match:dateValid"            # Date pattern
      errorRate: "match:between:0:5"            # Numeric pattern
      
      # Type validation alongside cross-field
      score: "match:type:number"
      baseline: "match:type:object"

Common Use Cases

Validation Scenarios

  • Time Range Validation: Ensure start times are before end times
  • Capacity Management: Validate current usage against limits
  • Financial Compliance: Check transaction amounts against account balances
  • Pricing Logic: Ensure discounted prices are less than original prices
  • Permission Hierarchies: Validate user levels meet access requirements
  • Resource Allocation: Check allocated resources don't exceed available capacity
  • Data Consistency: Ensure related fields maintain logical relationships
  • Business Rules: Validate complex multi-field business constraints

Best Practices

Cross-Field Pattern Guidelines

  • Field Names: Use exact field names as they appear in the response
  • Operators: Supported operators are <, <=, >, >=, =, !=
  • Data Types: Automatic conversion for strings containing numbers and dates
  • Nested Fields: Use dot notation for accessing nested object properties
  • Error Handling: Missing fields will cause validation failure with clear error messages
  • Combination: Combine with other patterns for comprehensive validation

Troubleshooting

Common Errors

text
# Field not found error
Error: Field 'nonexistentField' not found in object for cross-field comparison

# Type conversion error  
Error: Cannot compare field 'description' (string) with field 'count' (number)

# Invalid operator error
Error: Invalid operator '~=' in cross-field pattern. Supported: <, <=, >, >=, =, !=

# Nested field access error
Error: Cannot access nested field 'user.profile.age' - intermediate object 'profile' is null

Debugging Tips

  • Use --debug flag to see the actual values being compared
  • Verify field names match exactly (case-sensitive)
  • Check that both fields exist in the response object
  • Ensure nested field paths are valid (no null intermediate objects)
  • Confirm data types are compatible for comparison

Production Ready

Cross-field patterns are extensively tested and production-ready for validating complex business rules and data relationships in MCP server responses.