Skip to main content
Glama
liuyazui

Base64 MCP Server

base64_encode_image

Convert image files to Base64 encoded strings for embedding in web applications, documents, or data transmission.

Instructions

将图片转换为Base64编码

Args:
    image_path: 图片文件路径

Returns:
    Base64编码结果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_pathYes

Implementation Reference

  • The @mcp.tool() decorated function implementing the base64_encode_image tool. It reads the image file from the given path, encodes its binary content to base64, determines the MIME type using PIL, constructs a data URL, and returns previews of the encoded string and data URL.
    @mcp.tool()
    def base64_encode_image(image_path: str) -> str:
        """将图片转换为Base64编码
    
        Args:
            image_path: 图片文件路径
    
        Returns:
            Base64编码结果
        """
        try:
            if not os.path.exists(image_path):
                return f"错误: 文件 '{image_path}' 不存在"
    
            with open(image_path, "rb") as image_file:
                encoded = base64.b64encode(image_file.read()).decode("utf-8")
    
            # 获取MIME类型
            img = PILImage.open(image_path)
            mime_type = f"image/{img.format.lower()}"
    
            # 返回可在HTML中使用的Data URL格式
            data_url = f"data:{mime_type};base64,{encoded}"
            encoded_preview = f"图片Base64编码结果 (前100字符): {encoded[:100]}..."
            data_url_preview = f"完整Data URL (前100字符): {data_url[:100]}..."
            return f"{encoded_preview}\n\n{data_url_preview}"
        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. It states what the tool does (converts image to Base64) but lacks behavioral details like whether it reads local files vs URLs, file size limits, supported image formats, error handling, or performance characteristics. The return statement is minimal.

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 appropriately sized with three clear sections (purpose, args, returns). The first sentence states the core functionality, though the structure could be more front-loaded by integrating parameter details into the main description rather than separate 'Args' and 'Returns' lines.

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

Completeness2/5

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

Given no annotations, no output schema, and a single parameter with 0% schema coverage, the description is incomplete. It lacks details on input constraints (e.g., file types, size), output format specifics, error conditions, and comparison to sibling tools, which are needed for proper tool selection and invocation.

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 0%, so the description must compensate. It provides the parameter name 'image_path' and clarifies it's for image files, adding meaning beyond the schema's generic 'Image Path' title. However, it doesn't specify path format (absolute/relative) or supported file systems.

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 tool's purpose with a specific verb ('将图片转换为' - converts image to) and resource ('Base64编码' - Base64 encoding). It distinguishes from siblings by specifying it works with images rather than text, unlike base64_encode_text.

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

Usage Guidelines3/5

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

The description implies usage context through the parameter name 'image_path', suggesting this tool is for encoding image files. However, it doesn't explicitly state when to use this vs alternatives like base64_encode_text or when not to use it (e.g., for non-image files).

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