hash

package
v0.73.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesHash

func BytesHash(input []byte) string

BytesHash computes SHA-256 hash of byte slice

func ComputeToolHash

func ComputeToolHash(serverName, toolName, description string, inputSchema interface{}) string

ComputeToolHash computes a SHA256 hash for a tool (alias for ToolHash that doesn't return error)

func ComputeToolHashWithOutputSchema added in v0.33.4

func ComputeToolHashWithOutputSchema(serverName, toolName, description string, inputSchema interface{}, outputSchemaJSON string) string

ComputeToolHashWithOutputSchema computes a SHA256 hash for a tool including output schema.

func NormalizeJSON added in v0.33.4

func NormalizeJSON(s string) string

NormalizeJSON parses s and re-serializes it with object keys sorted, so that semantically identical JSON with different key order or whitespace produces a stable, comparable string. It also canonicalizes JSON Schema draft-07 local references (see canonicalizeSchemaRefs). Empty or non-JSON input is returned unchanged.

This is the single canonical JSON normalizer shared by the upstream tool capture (internal/upstream/core) and the tool-approval hash (internal/runtime), so a schema hashes identically no matter which path observed it — or which version of the MCP library decoded it.

func StringHash

func StringHash(input string) string

StringHash computes SHA-256 hash of a string

func ToolContractDigest added in v0.71.0

func ToolContractDigest(description, schemaJSON, outputSchemaJSON string) string

ToolContractDigest is the output-aware successor of ToolDefinitionDigest: a stable digest of every part of a tool contract a security scan reads — description, input schema AND output schema (scanners analyse output schemas since RT-06). It is versioned so it can never equal a ToolDefinitionDigest, and an absent or null output schema counts as "".

func ToolDefinitionDigest added in v0.71.0

func ToolDefinitionDigest(description, schemaJSON string) string

ToolDefinitionDigest returns a stable digest of the parts of a tool definition a security scan reads: its description and input schema. The tool name is the lookup key on both sides, and the output schema is not exported to scanners, so neither is folded in. A missing, null or empty schema counts as "{}" so every producer agrees.

func ToolHash

func ToolHash(serverName, toolName, description string, parametersSchema interface{}) (string, error)

ToolHash computes SHA-256 hash for tool change detection. Format: sha256(canonical JSON of serverName, toolName, description, input schema)

func ToolHashWithOutputSchema added in v0.33.4

func ToolHashWithOutputSchema(serverName, toolName, description string, parametersSchema interface{}, outputSchemaJSON string) (string, error)

ToolHashWithOutputSchema computes SHA-256 hash for the full tool contract. Output schema is included because it describes the data shape returned to the agent and therefore belongs to the human-approved tool contract. Format: sha256(canonical JSON of serverName, toolName, description, input schema, output schema)

func VerifyToolHash

func VerifyToolHash(serverName, toolName, description string, parametersSchema interface{}, storedHash string) (bool, error)

VerifyToolHash verifies if the current tool matches the stored hash

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL