Skip to main content
Glama
liuyazui

Base64 MCP Server

base64_decode_image

Decode Base64-encoded strings into image files by specifying output path and MIME type to convert encoded data into usable images.

Instructions

将Base64编码解码为图片

Args:
    encoded: Base64编码的字符串
    output_path: 输出图片的路径
    mime_type: 图片的MIME类型 (默认为image/png)

Returns:
    解码结果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encodedYes
output_pathYes
mime_typeNoimage/png

Implementation Reference

  • The handler function for the 'base64_decode_image' tool. It decodes Base64-encoded image data (supporting data: URLs), creates output directory if needed, and saves the image file.
    @mcp.tool()
    def base64_decode_image(
        encoded: str, output_path: str, mime_type: str = "image/png"
    ) -> str:
        """将Base64编码解码为图片
    
        Args:
            encoded: Base64编码的字符串
            output_path: 输出图片的路径
            mime_type: 图片的MIME类型 (默认为image/png)
    
        Returns:
            解码结果
        """
        try:
            # 清理输入,移除可能的前缀和空白
            encoded = encoded.strip()
    
            # 如果输入是Data URL格式,提取实际的Base64部分
            if encoded.startswith("data:"):
                # 分离MIME类型和Base64内容
                header, encoded = encoded.split(",", 1)
                if ";base64" not in header:
                    return "错误: 输入不是有效的Base64编码的Data URL"
                # 提取MIME类型但不使用,因为我们使用参数中的mime_type
    
            # 解码Base64
            image_data = base64.b64decode(encoded)
    
            # 确保输出目录存在
            output_dir = os.path.dirname(output_path)
            if output_dir and not os.path.exists(output_dir):
                os.makedirs(output_dir)
    
            # 保存图片
            with open(output_path, "wb") as image_file:
                image_file.write(image_data)
    
            return f"图片已成功解码并保存到 {output_path}"
        except Exception as e:
            return f"图片解码失败: {str(e)}"
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it states the tool decodes Base64 to an image and saves it to a file path, it doesn't disclose important behavioral aspects like: what happens if the file path already exists (overwrites? fails?), what happens with invalid Base64 data, whether there are file size limits, or what specific '解码结果' (decoding result) is returned. The description provides basic operation but lacks critical implementation details.

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?

The description is perfectly structured and concise - a clear purpose statement followed by organized sections for Args and Returns. Every sentence earns its place, with no redundant information. The bilingual presentation (Chinese purpose, English parameter labels) is efficient for an international context.

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?

For a 3-parameter tool with no annotations and no output schema, the description provides adequate basic information but has significant gaps. It explains what the tool does and what parameters mean, but doesn't describe the return value ('解码结果') in any detail, doesn't cover error conditions, and doesn't provide behavioral transparency about file operations. Given the complexity of file I/O operations, more completeness would be expected.

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?

With 0% schema description coverage, the description compensates well by clearly explaining all three parameters: 'encoded' is the Base64 string, 'output_path' is where to save the image, and 'mime_type' is the image format with a default value. It adds meaningful context beyond the bare schema, though it could provide more guidance on valid mime_type values or output_path format requirements.

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 clearly states the specific action ('将Base64编码解码为图片' - decodes Base64 encoding to an image) and distinguishes it from sibling tools like base64_decode_text (which decodes to text) and base64_encode_image (which encodes from image). It precisely identifies both the input (Base64 string) and output (image) resources.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (when you have Base64-encoded image data that needs to be saved as an image file). It doesn't explicitly state when NOT to use it or name alternatives, but the sibling tool names make the distinction obvious - use this for image decoding, not text decoding or encoding operations.

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/liuyazui/base64_server'

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