Skip to main content
Glama

export_to_unity

Export AI-generated 2D assets directly to Unity projects by specifying asset name, type, and folder structure for immediate use in game development.

Instructions

Export a generated asset directly to a Unity project.

Args:
    image_base64: Base64 encoded image to export
    asset_name: Name for the asset file (without extension)
    asset_type: Unity folder type (Sprites, Textures, UI, etc.)
    subfolder: Optional subfolder within the asset type folder

Returns:
    JSON with export status and file path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_base64Yes
asset_nameYes
asset_typeNoSprites
subfolderNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'export_to_unity' tool, decorated with @mcp.tool() for registration. It decodes the base64 image, validates the Unity assets directory from env var UNITY_ASSETS_DIR, ensures the target directory exists, writes the PNG file, and returns JSON with success status and file path.
    async def export_to_unity(
        image_base64: str,
        asset_name: str,
        asset_type: str = "Sprites",
        subfolder: str = ""
    ) -> str:
        """Export a generated asset directly to a Unity project.
        
        Args:
            image_base64: Base64 encoded image to export
            asset_name: Name for the asset file (without extension)
            asset_type: Unity folder type (Sprites, Textures, UI, etc.)
            subfolder: Optional subfolder within the asset type folder
        
        Returns:
            JSON with export status and file path
        """
        if not UNITY_ASSETS_DIR:
            return json.dumps({
                "success": False,
                "error": "UNITY_ASSETS_DIR environment variable not set"
            }, indent=2)
        
        unity_path = Path(UNITY_ASSETS_DIR)
        if not unity_path.exists():
            return json.dumps({
                "success": False,
                "error": f"Unity assets directory not found: {UNITY_ASSETS_DIR}"
            }, indent=2)
        
        # Build target path
        target_dir = unity_path / asset_type
        if subfolder:
            target_dir = target_dir / subfolder
        
        # Validate path is within allowed roots
        if ALLOW_WRITE_ROOTS and ALLOW_WRITE_ROOTS[0]:
            if not validate_path(str(target_dir), ALLOW_WRITE_ROOTS):
                return json.dumps({
                    "success": False,
                    "error": "Target path not in allowed write roots"
                }, indent=2)
        
        ensure_directory(target_dir)
        
        import base64
        image_bytes = base64.b64decode(image_base64)
        
        file_path = target_dir / f"{asset_name}.png"
        file_path.write_bytes(image_bytes)
        
        return json.dumps({
            "success": True,
            "file_path": str(file_path),
            "asset_name": asset_name,
            "asset_type": asset_type
        }, indent=2)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool exports an asset and returns status/path, but lacks details on permissions required, side effects (e.g., file overwriting), error handling, or rate limits. For a write operation with zero annotation coverage, this is a significant gap in transparency.

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 well-structured and front-loaded with the core purpose, followed by clear sections for Args and Returns. Every sentence adds value: the first states the action, and the parameter/return explanations are essential. No redundant or verbose language is present.

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

Completeness4/5

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

Given the tool has an output schema (Returns JSON with status and path), the description doesn't need to detail return values. It covers the export process and parameters adequately. However, as a write tool with no annotations, it could benefit from more behavioral context (e.g., idempotency, errors) to be fully complete.

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 adds meaningful context for all parameters: image_base64 is explained as 'Base64 encoded image to export', asset_name as 'Name for the asset file (without extension)', asset_type as 'Unity folder type (Sprites, Textures, UI, etc.)', and subfolder as 'Optional subfolder within the asset type folder'. This clarifies purpose and usage beyond the bare schema titles.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool exports a generated asset to a Unity project, specifying the action (export) and target (Unity project). It distinguishes from siblings by focusing on export rather than generation (like generate_sprite) or management (like list_available_presets), though it doesn't explicitly differentiate from all siblings like create_sprite_atlas which might also involve Unity assets.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a generated asset first), compare to similar tools like create_sprite_atlas, or specify scenarios where export is appropriate versus other operations. Usage is implied only by the tool's name and description.

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/tuannguyen14/ComfyAI-MCP-GameAssets'

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