sys_hash
Compute hash values for text using MD5, SHA1, SHA256, or SHA512 algorithms. Output as hex or base64.
Instructions
计算字符串或文本的哈希值。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 要计算哈希的文本 | |
| algorithm | No | 哈希算法(默认 sha256) | sha256 |
| encoding | No | 输出编码:hex(默认)或 base64 | hex |
Implementation Reference
- The _sys_hash function executes the sys_hash tool logic: takes text, algorithm (md5/sha1/sha256/sha512), and encoding (hex/base64) parameters, computes the hash using hashlib, and returns the result.
def _sys_hash(args: dict) -> list[types.TextContent]: text = args["text"] algorithm = args.get("algorithm", "sha256") encoding = args.get("encoding", "hex") h = hashlib.new(algorithm, text.encode("utf-8")) if encoding == "base64": result = base64.b64encode(h.digest()).decode() else: result = h.hexdigest() return [types.TextContent(type="text", text=( f"算法: {algorithm.upper()}\n" f"编码: {encoding}\n" f"输入: {text[:80]}{'...' if len(text) > 80 else ''}\n" f"结果: {result}" ))] - The sys_hash tool registration with its input schema: requires 'text' (string), optional 'algorithm' (enum: md5/sha1/sha256/sha512, default sha256), optional 'encoding' (enum: hex/base64, default hex).
types.Tool( name="sys_hash", description="计算字符串或文本的哈希值。", inputSchema={ "type": "object", "properties": { "text": { "type": "string", "description": "要计算哈希的文本", }, "algorithm": { "type": "string", "description": "哈希算法(默认 sha256)", "enum": ["md5", "sha1", "sha256", "sha512"], "default": "sha256", }, "encoding": { "type": "string", "description": "输出编码:hex(默认)或 base64", "enum": ["hex", "base64"], "default": "hex", }, }, "required": ["text"], }, - src/onion_mcp_server/tools/system.py:175-187 (registration)The handle_system dispatcher maps tool names to handler functions. For sys_hash, it routes to _sys_hash via 'sys_hash': _sys_hash entry.
async def handle_system(name: str, arguments: dict) -> list[types.TextContent]: handlers = { "sys_time": _sys_time, "sys_uuid": _sys_uuid, "sys_hash": _sys_hash, "sys_base64": _sys_base64, "sys_url_encode": _sys_url_encode, "sys_json_valid": _sys_json_valid, } fn = handlers.get(name) if fn is None: raise ValueError(f"未知 system 工具: {name}") return fn(arguments) - src/onion_mcp_server/server.py:60-61 (registration)In the main server registration, SYSTEM_TOOLS tools (including sys_hash) are mapped to handle_system dispatcher, which routes to _sys_hash.
for _t in SYSTEM_TOOLS: _HANDLERS[_t.name] = handle_system - src/onion_mcp_server/server.py:39-46 (registration)SYSTEM_TOOLS (which includes sys_hash) is included in the ALL_TOOLS list returned by list_tools for MCP capability discovery.
ALL_TOOLS: list[types.Tool] = [ *AI_TOOLS, *CODE_TOOLS, *TEXT_TOOLS, *DATA_TOOLS, *WEB_TOOLS, *SYSTEM_TOOLS, ]