-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimits.go
More file actions
51 lines (48 loc) · 1.52 KB
/
limits.go
File metadata and controls
51 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mcp
// Default per-call limits. Mirror McpLimitsConfig defaults in the Java
// side (ConfigDefaults.builtIn): perToolTimeoutMs=15000, maxResults=500,
// maxPayloadBytes=2_000_000, ratePerMinute=300, maxDepth=10. The Go side
// owns its own defaults today and will read codeiq.yml `mcp.limits.*`
// once the unified config port lands.
const (
DefaultMaxResults = 500
DefaultMaxDepth = 10
DefaultQueryTimeout = 30 // seconds — DBMS-level wall-clock cap, mirrors Neo4jConfig
)
// CapResults clamps a caller-supplied result-count to [1, hardCap].
// Mirrors Java McpTools `Math.min(limit, maxResults)` with a positive
// floor. The cap is enforced in each tool's iteration loop (NOT injected
// as `LIMIT N` into Cypher), per the spec §8 gotcha.
//
// hardCap <= 0 falls back to DefaultMaxResults so callers that haven't
// loaded a config yet still get sane behaviour.
func CapResults(requested, hardCap int) int {
if hardCap <= 0 {
hardCap = DefaultMaxResults
}
if requested < 1 {
return 1
}
if requested > hardCap {
return hardCap
}
return requested
}
// CapDepth clamps a traversal-depth to [1, hardCap]. Mirrors Java
// `Math.min(depth, maxDepth)` with a positive floor. Phase 3 default
// hardCap is McpLimitsConfig.MaxDepth (10) loaded from codeiq.yml at
// server boot.
//
// hardCap <= 0 falls back to DefaultMaxDepth.
func CapDepth(requested, hardCap int) int {
if hardCap <= 0 {
hardCap = DefaultMaxDepth
}
if requested < 1 {
return 1
}
if requested > hardCap {
return hardCap
}
return requested
}