Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

sys_base64

Encode or decode text using Base64, with optional URL-safe mode for safe transmission in URLs.

Instructions

Base64 编码或解码文本。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes要处理的文本
actionNoencode(编码)或 decode(解码)encode
url_safeNo是否使用 URL-safe Base64(默认 false)

Implementation Reference

  • The _sys_base64 function implements the core Base64 encode/decode logic. It takes 'text', 'action' (encode/decode), and 'url_safe' parameters. For encoding, it uses base64.b64encode or base64.urlsafe_b64encode. For decoding, it handles padding and uses base64.b64decode or base64.urlsafe_b64decode. On error, it returns an error message with ❌ prefix.
    def _sys_base64(args: dict) -> list[types.TextContent]:
        text     = args["text"]
        action   = args.get("action", "encode")
        url_safe = bool(args.get("url_safe", False))
    
        try:
            if action == "encode":
                data = text.encode("utf-8")
                result = (
                    base64.urlsafe_b64encode(data)
                    if url_safe else base64.b64encode(data)
                ).decode()
            else:
                padding = 4 - len(text) % 4
                padded  = text + ("=" * (padding % 4))
                result  = (
                    base64.urlsafe_b64decode(padded)
                    if url_safe else base64.b64decode(padded)
                ).decode("utf-8")
        except Exception as e:
            return [types.TextContent(type="text", text=f"❌ {action} 失败: {e}")]
    
        return [types.TextContent(type="text", text=result)]
  • The Tool definition for 'sys_base64' including the inputSchema. It defines three properties: 'text' (required string), 'action' (optional enum encode/decode, default encode), and 'url_safe' (optional boolean, default false).
    types.Tool(
        name="sys_base64",
        description="Base64 编码或解码文本。",
        inputSchema={
            "type": "object",
            "properties": {
                "text": {
                    "type":        "string",
                    "description": "要处理的文本",
                },
                "action": {
                    "type":        "string",
                    "description": "encode(编码)或 decode(解码)",
                    "enum":        ["encode", "decode"],
                    "default":     "encode",
                },
                "url_safe": {
                    "type":        "boolean",
                    "description": "是否使用 URL-safe Base64(默认 false)",
                    "default":     False,
                },
            },
            "required": ["text"],
        },
    ),
  • The handle_system function acts as the dispatcher/router. It maps the tool name 'sys_base64' to the handler function _sys_base64 and calls it with the arguments dict.
    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)
  • Import of the 'base64' standard library module, which provides the underlying b64encode, b64decode, urlsafe_b64encode, and urlsafe_b64decode functions used by the handler.
    import base64
    import hashlib
    import json
    import urllib.parse
    import uuid as _uuid
    from datetime import datetime
    from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
    
    import mcp.types as types
Behavior2/5

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

No annotations provided. Description does not disclose behavioral traits beyond schema (e.g., error handling, output format). Minimal insight.

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

Conciseness5/5

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

Single sentence, front-loaded, no wasted words.

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

Completeness3/5

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

Simple tool with 3 params and no output schema. Description is adequate but lacks output expectations and edge cases.

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

Parameters3/5

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

Schema description coverage is 100%. Description adds no extra meaning beyond schema; baseline 3 is appropriate.

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?

Description clearly states verb+resource: 'Base64 encode or decode text.' It distinguishes from sibling tools like sys_url_encode or sys_hash.

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

Usage Guidelines2/5

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

No guidance on when to use this tool vs alternatives. Does not mention when not to use or provide contextual hints.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/onion-ai/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server