merry_runtime/tool_admission.rs
1//! Runtime admission for provider-visible tools.
2//!
3//! A tool can remain part of the stable model contract while runtime policy
4//! decides whether a particular call is executable. This keeps phase, role,
5//! workspace scope, and permission changes out of provider-visible tool
6//! schemas and ordering.
7
8use merry_core::ToolName;
9use std::collections::BTreeSet;
10
11/// Runtime-owned allowlist for tool execution.
12///
13/// Admission does not change the advertised tool surface. A denied call is
14/// resolved as a structured tool failure by the runtime before input
15/// validation or executor dispatch.
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct ToolAdmission {
18 allowed_tools: BTreeSet<ToolName>,
19}
20
21impl ToolAdmission {
22 /// Creates an admission policy that allows exactly the supplied names.
23 #[must_use]
24 pub fn allow_only<I>(tools: I) -> Self
25 where
26 I: IntoIterator<Item = ToolName>,
27 {
28 Self {
29 allowed_tools: tools.into_iter().collect(),
30 }
31 }
32
33 /// Returns whether a tool call is admitted for execution.
34 #[must_use]
35 pub fn allows(&self, tool_name: &ToolName) -> bool {
36 self.allowed_tools.contains(tool_name)
37 }
38
39 /// Returns the admitted tool names in deterministic order.
40 #[must_use]
41 pub fn allowed_tools(&self) -> &BTreeSet<ToolName> {
42 &self.allowed_tools
43 }
44}