sys_url_encode
Encode or decode URL text, with option to convert spaces to plus signs or percent encoding.
Instructions
URL 编码或解码文本。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 要处理的文本 | |
| action | No | encode(编码)或 decode(解码) | encode |
| quote_plus | No | 是否将空格编码为 +(默认 false,编码为 %20) |
Implementation Reference
- The actual handler function for sys_url_encode tool. Takes text, action (encode/decode), and quote_plus params. Uses urllib.parse.quote/quote_plus for encoding and unquote/unquote_plus for decoding.
def _sys_url_encode(args: dict) -> list[types.TextContent]: text = args["text"] action = args.get("action", "encode") quote_plus = bool(args.get("quote_plus", False)) try: if action == "encode": result = ( urllib.parse.quote_plus(text) if quote_plus else urllib.parse.quote(text, safe="") ) else: result = ( urllib.parse.unquote_plus(text) if quote_plus else urllib.parse.unquote(text) ) except Exception as e: return [types.TextContent(type="text", text=f"❌ {action} 失败: {e}")] return [types.TextContent(type="text", text=result)] - The schema definition (types.Tool) for sys_url_encode, specifying the inputSchema with text (required), action (encode/decode enum, default encode), and quote_plus (boolean, default false) parameters.
types.Tool( name="sys_url_encode", description="URL 编码或解码文本。", inputSchema={ "type": "object", "properties": { "text": { "type": "string", "description": "要处理的文本", }, "action": { "type": "string", "description": "encode(编码)或 decode(解码)", "enum": ["encode", "decode"], "default": "encode", }, "quote_plus": { "type": "boolean", "description": "是否将空格编码为 +(默认 false,编码为 %20)", "default": False, }, }, "required": ["text"], }, ), - src/onion_mcp_server/tools/system.py:175-181 (registration)The dispatch handler (handle_system) that routes the tool name 'sys_url_encode' to the _sys_url_encode function via a handlers dictionary.
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, - src/onion_mcp_server/server.py:60-61 (registration)Registration of all SYSTEM_TOOLS (including sys_url_encode) in the _HANDLERS routing table, mapping each tool name to the handle_system function.
for _t in SYSTEM_TOOLS: _HANDLERS[_t.name] = handle_system - src/onion_mcp_server/server.py:39-46 (registration)SYSTEM_TOOLS (including sys_url_encode) are aggregated into ALL_TOOLS, which is returned by the list_tools() handler.
ALL_TOOLS: list[types.Tool] = [ *AI_TOOLS, *CODE_TOOLS, *TEXT_TOOLS, *DATA_TOOLS, *WEB_TOOLS, *SYSTEM_TOOLS, ]