Numeric Patterns
Advanced numeric comparison and validation patterns.
MCP Aegis provides comprehensive numeric comparison patterns for validating numeric values, counts, scores, measurements, and calculations returned by MCP servers. These patterns support both integer and floating-point numbers.
Important Note
All numeric patterns automatically parse string values to numbers. If the value cannot be parsed as a number, the pattern will return false.
Comparison Patterns
Greater Than
Use "match:greaterThan:N" to validate that a numeric value is greater than the specified threshold.
# Validate that a count is greater than expected minimum
expect:
response:
result:
count: "match:greaterThan:10" # Must be > 10
score: "match:greaterThan:95.5" # Must be > 95.5
percentage: "match:greaterThan:0" # Must be positiveGreater Than or Equal
Use "match:greaterThanOrEqual:N" to validate that a numeric value is greater than or equal to the threshold.
# Validate minimum values (inclusive)
expect:
response:
result:
rating: "match:greaterThanOrEqual:1" # Must be >= 1
progress: "match:greaterThanOrEqual:0" # Must be >= 0 (non-negative)
temperature: "match:greaterThanOrEqual:-273.15" # Above absolute zeroLess Than
Use "match:lessThan:N" to validate that a numeric value is less than the specified threshold.
# Validate maximum limits
expect:
response:
result:
errorRate: "match:lessThan:0.01" # Must be < 1%
responseTime: "match:lessThan:1000" # Must be < 1000ms
usage: "match:lessThan:100" # Must be < 100%Less Than or Equal
Use "match:lessThanOrEqual:N" to validate that a numeric value is less than or equal to the threshold.
# Validate maximum values (inclusive)
expect:
response:
result:
percentage: "match:lessThanOrEqual:100" # Must be <= 100%
priority: "match:lessThanOrEqual:10" # Must be <= 10
fileSize: "match:lessThanOrEqual:1024" # Must be <= 1KBRange Patterns
Between (Inclusive Range)
Use "match:between:MIN:MAX" to validate that a numeric value falls within a specific range (inclusive).
# Validate values within acceptable ranges
expect:
response:
result:
httpStatus: "match:between:200:299" # Success status codes (200-299)
temperature: "match:between:-10:40" # Temperature range (-10°C to 40°C)
rating: "match:between:1:5" # Rating scale (1 to 5 stars)
percentage: "match:between:0:100" # Percentage (0% to 100%)Range (Alias for Between)
Use "match:range:MIN:MAX" as an alias for between. Both patterns work identically.
# Same functionality as between, different syntax preference
expect:
response:
result:
score: "match:range:0:100" # Score range (0 to 100)
port: "match:range:1024:65535" # Valid port range
latitude: "match:range:-90:90" # Valid latitude rangeProduction Examples
Here are real-world examples adapted from MCP Aegis's test suite:
API Response Validation
# Validate API response contains numeric data within expected ranges
- it: "should validate API response metrics are within acceptable ranges"
request:
jsonrpc: "2.0"
id: "api-metrics"
method: "tools/call"
params:
name: "get_api_metrics"
arguments: {}
expect:
response:
jsonrpc: "2.0"
id: "api-metrics"
result:
responseTime: "match:lessThan:500" # Must be < 500ms
successRate: "match:greaterThan:99" # Must be > 99%
errorCount: "match:lessThanOrEqual:10" # Must be <= 10 errors
uptime: "match:between:99:100" # 99-100% uptime
requestCount: "match:greaterThanOrEqual:0" # Non-negative
averageLatency: "match:range:0:1000" # 0-1000ms rangeFile System Validation
# Example from filesystem server testing numeric file properties
- it: "should validate file statistics are within reasonable bounds"
request:
jsonrpc: "2.0"
id: "file-stats"
method: "tools/call"
params:
name: "get_file_stats"
arguments:
path: "./large-file.txt"
expect:
response:
jsonrpc: "2.0"
id: "file-stats"
result:
sizeBytes: "match:greaterThan:0" # File must have content
maxSizeBytes: "match:lessThan:10485760" # Must be < 10MB
lineCount: "match:between:1:1000" # Reasonable line count
modifiedTimestamp: "match:greaterThan:0" # Valid timestampMathematical Calculation Validation
# Example from multi-tool server calculator testing
- it: "should validate calculation results are mathematically correct"
request:
jsonrpc: "2.0"
id: "calc-validation"
method: "tools/call"
params:
name: "calculator"
arguments:
operation: "divide"
a: 100
b: 3
expect:
response:
jsonrpc: "2.0"
id: "calc-validation"
result:
result: "match:between:33:34" # 100/3 ≈ 33.33
precision: "match:greaterThan:2" # At least 2 decimal places
isExact: "match:type:boolean" # Type validation
# Combining numeric with other patterns:
formatted: "match:contains:33.33" # String representationCombining with Pattern Negation
All numeric patterns work with pattern negation using "match:not:":
expect:
response:
result:
errorRate: "match:not:greaterThan:5" # NOT > 5 (i.e., <= 5)
status: "match:not:between:400:599" # NOT 4xx-5xx (i.e., success)
timeout: "match:not:lessThan:1000" # NOT < 1000 (i.e., >= 1000)
score: "match:not:range:0:50" # NOT 0-50 (i.e., > 50)Error Handling
Numeric patterns handle edge cases gracefully:
- Non-numeric strings: Return
false - Null/undefined values: Return
false - Invalid range syntax: Return
false - String numbers: Automatically parsed (e.g.,
"42"becomes42)
# These will all evaluate to false:
invalidValue: "match:greaterThan:10" # When actual is "abc"
nullValue: "match:between:1:10" # When actual is null
malformedRange: "match:between:invalid" # Invalid range formatCommon Use Cases
- Performance Testing: Response times, throughput, memory usage
- API Validation: HTTP status codes, pagination counts, rate limits
- Data Quality: Score ranges, percentages, measurement bounds
- Business Logic: Price ranges, quantity limits, rating scales
- System Metrics: CPU usage, disk space, error rates
- Mathematical Operations: Calculation results, statistical measures
Best Practice
Combine numeric patterns with other pattern types for comprehensive validation. For example, use type validation first, then numeric ranges for robust testing.