Skip to main content
Glama

CipherHUB Cryptography Toolkit

cbor_encode

[structured_message] 把 JSON 载荷编码为 CBOR 字节流(RFC 8949)。 【算法】CBOR 规范编码(RFC 8949 §4.2.1)或不定长教学编码(§3.2.2)。 【参数】

  • json_payload:待编码的 JSON 文本(≤65536 字符),支持两类教学标记: {"$bytes": ""} 渲染为 byte string(major type 2); {"$tag": , "value": …} 渲染为 tagged value(major type 6)

  • canonical:True=规范形式(定长最短,map 键按长度+字节序排序)

  • prefer_indefinite:True=字符串/数组/map 用不定长编码(0x5f/0x7f/0x9f/0xbf + 0xff break)

  • coerce_integer_keys:True 时形如 "-35"/"0" 的十进制字符串键转整数键(复刻 Nitro attestation 的 protected 头 {1:-35}) 【输出】encoded_in_hex、encoded_length、canonical、structure_tree(逐字段拆解树)、truncated、warnings。 【注意】canonical 与 prefer_indefinite 互斥;JSON 对象键天然是字符串,需要整数键时用 coerce_integer_keys=true。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
canonicalNoTrue=RFC 8949 §4.2.1 规范编码(定长最短、map 键排序);与 prefer_indefinite 互斥
json_payloadNo待编码的结构化消息 JSON 文本(≤65536 字符)。CBOR:{"$bytes":"<hex>"} 渲染 byte string、{"$tag":n,"value":…} 渲染 tagged value;DER:ASN.1 节点 DSL(一节点一主键,如 {"sequence":[{"oid":"1.2…"}]},形态清单见 der_encode 工具描述)
prefer_indefiniteNoTrue=不定长教学编码(字符串/数组/map 用 0x5f/0x7f/0x9f/0xbf + 0xff break)
coerce_integer_keysNoTrue 时形如 "-35"/"0" 的十进制字符串键渲染为 CBOR 整数键(如 Nitro protected 头 {1:-35})

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / json_payload / description
      Previous value: -"待编码为 CBOR 的 JSON 文本(≤65536 字符;{\"$bytes\":\"<hex>\"} 渲染 byte string,{\"$tag\":n,\"value\":…} 渲染 tagged value)"New value: +"待编码的结构化消息 JSON 文本(≤65536 字符)。CBOR:{\"$bytes\":\"<hex>\"} 渲染 byte string、{\"$tag\":n,\"value\":…} 渲染 tagged value;DER:ASN.1 节点 DSL(一节点一主键,如 {\"sequence\":[{\"oid\":\"1.2…\"}]},形态清单见 der_encode 工具描述)"
  2. Added

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses the two encoding algorithms (canonical vs indefinite), the teaching markers, the mutual-exclusion constraint, and the output fields. It does not explicitly state that the operation is pure/read-only, but the absence of side effects is strongly implied by 'encode' and the output list. The main gap is not describing error behavior or the meaning of 'truncated' and 'warnings'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and front-loaded with the core purpose, followed by algorithm, parameters, output, and caveats. The parameter section is a bit dense with inline examples, but every sentence earns its place. The structure is logical and scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 4-parameter encoding tool with no output schema, the description covers the input format, the two encoding modes, the integer-key coercion, and the output fields. It does not explain the structure_tree output or the meaning of truncated/warnings, but the core calling contract is complete. The sibling context (cbor_decode, der_encode) is implicitly handled by the description's references.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds value by explaining the teaching markers ($bytes, $tag) and the coerce_integer_keys use case (Nitro attestation protected header {1:-35}) beyond the schema's terse descriptions. It also clarifies the ≤65536 character limit. This is meaningful added semantics, though not exhaustive.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: '把 JSON 载荷编码为 CBOR 字节流(RFC 8949)' (encode a JSON payload into a CBOR byte stream per RFC 8949). It clearly distinguishes this from the sibling cbor_decode (the inverse operation) and from der_encode (which is explicitly referenced for the DER DSL). The scope is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states the mutual exclusivity of canonical and prefer_indefinite, and explains when to use coerce_integer_keys (to replicate Nitro attestation protected headers). It also references der_encode for the DER variant, giving an agent a clear routing cue. This is explicit when/when-not guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.