Skip to main content

ToolDigest

Struct ToolDigest 

Source
pub struct ToolDigest(/* private fields */);
Expand description

A stable digest of the discovered tool list (names, descriptions, and input/output schemas) at generation time, recorded so a later comparison can detect that the server’s tool surface changed.

Newtype over a 64-character lowercase-hex String — see ConfigFingerprint’s doc comment for why this is a newtype rather than a bare String, and for the TryFrom<String>/ DigestFormatError validation its Deserialize is routed through.

§Examples

use mcp_execution_core::provenance::{ToolDigest, ToolDigestEntry};
use serde_json::json;

let schema = json!({"type": "object"});
let entries = vec![ToolDigestEntry {
    name: "create_issue",
    description: "Creates a new issue",
    input_schema: &schema,
    output_schema: None,
}];

let digest = ToolDigest::compute(&entries);
assert_eq!(digest.as_str().len(), 64);

Implementations§

Source§

impl ToolDigest

Source

pub fn compute(entries: &[ToolDigestEntry<'_>]) -> Self

Computes an aggregate digest of entries, insensitive to input order (including two tools sharing the same name in swapped order) but sensitive to any schema/name/ description edit, tool addition, or tool removal.

Two-level construction: each entry is hashed on its own (domain tag, framed name, framed description, then input_schema/output_schema via the recursive hash_value_into walk — output_schema’s presence is tagged explicitly, so None and Some(Value::Null) hash differently), the resulting 32-byte digests are sorted, and the sorted sequence is hashed into the final aggregate. Sorting digests rather than tool names gives a total order even for duplicate tool names, which name-sorting alone would leave ambiguous.

§Examples

Reordering the input tool list does not change the digest:

use mcp_execution_core::provenance::{ToolDigest, ToolDigestEntry};
use serde_json::json;

let schema_a = json!({"type": "object"});
let schema_b = json!({"type": "string"});
let a = ToolDigestEntry { name: "a", description: "", input_schema: &schema_a, output_schema: None };
let b = ToolDigestEntry { name: "b", description: "", input_schema: &schema_b, output_schema: None };

assert_eq!(
    ToolDigest::compute(&[a, b]),
    ToolDigest::compute(&[b, a]),
);
Source

pub fn as_str(&self) -> &str

Returns the digest as a 64-character lowercase-hex string slice.

§Examples
use mcp_execution_core::provenance::{ToolDigest, ToolDigestEntry};

let digest = ToolDigest::compute(&[] as &[ToolDigestEntry<'_>]);
assert!(!digest.as_str().is_empty());

Trait Implementations§

Source§

impl Clone for ToolDigest

Source§

fn clone(&self) -> ToolDigest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolDigest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ToolDigest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ToolDigest

Source§

impl PartialEq for ToolDigest

Source§

fn eq(&self, other: &ToolDigest) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ToolDigest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ToolDigest

Source§

impl TryFrom<String> for ToolDigest

Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Delegates to validate_digest_string — the sole entry point Deserialize uses.

Source§

type Error = DigestFormatError

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.