MCPcopy Create free account
hub / github.com/MetapriseAI/OrgKernel / check_scope

Method check_scope

src/orgkernel/schemas/execution_token.py:204–231  ·  view source on GitHub ↗

Validate a proposed tool call against this token's scope. Called by Tool Gateway before every external call. Returns ScopeCheckResult — never raises.

(self, tool: str, params: dict)

Source from the content-addressed store, hash-verified

202 return True
203
204 def check_scope(self, tool: str, params: dict) -> ScopeCheckResult:
205 """
206 Validate a proposed tool call against this token's scope.
207 Called by Tool Gateway before every external call.
208 Returns ScopeCheckResult — never raises.
209 """
210 violations: list[str] = []
211
212 if tool not in self.execution_scope:
213 violations.append(f"tool_not_in_scope: {tool}")
214
215 for key, expected in self.immutable_params.items():
216 actual = params.get(key)
217 if actual != expected:
218 violations.append(
219 f"immutable_param_mismatch: {key} "
220 f"(expected={expected!r}, got={actual!r})"
221 )
222
223 for bp in self.bounded_params:
224 actual = params.get(bp.param_name)
225 if actual is not None and not bp.check(float(actual)):
226 violations.append(
227 f"bounded_param_violation: {bp.param_name}={actual} "
228 f"(bounds: [{bp.lower_bound}, {bp.upper_bound}])"
229 )
230
231 return ScopeCheckResult(passed=len(violations) == 0, violations=violations)
232
233 def invalidate(self, reason: str) -> ExecutionToken:
234 """Return a new invalidated token."""

Callers

nothing calls this directly

Calls 3

ScopeCheckResultClass · 0.85
checkMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected