Skip to main content
Glama

aptos_abi_generate

Generate ABI files for Aptos smart contracts to enable contract interaction and integration in TypeScript or JSON formats.

Instructions

Generate ABI for an Aptos contract.

Args:
    contract_path: Path to the contract directory
    output_format: Format of the output (ts, json)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contract_pathYes
output_formatNots

Implementation Reference

  • The handler function for the 'aptos_abi_generate' tool. It compiles an Aptos Move contract, generates ABI in JSON or TypeScript SDK format using aptos CLI tools, and returns the result or error messages. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def aptos_abi_generate(contract_path: str, output_format: str = "ts") -> str:
        """
        Generate ABI for an Aptos contract.
        
        Args:
            contract_path: Path to the contract directory
            output_format: Format of the output (ts, json)
        """
        contract_path = os.path.expanduser(contract_path)  # Expand ~ in paths
        
        if not os.path.exists(contract_path):
            return f"Contract path not found: {contract_path}"
        
        supported_formats = ["ts", "json"]
        if output_format not in supported_formats:
            return f"Unsupported output format. Choose from: {', '.join(supported_formats)}"
        
        try:
            # First compile the contract to get the ABI
            build_cmd = ["aptos", "move", "compile", "--save-metadata", "--path", contract_path]
            build_result = subprocess.run(build_cmd, capture_output=True, text=True)
            
            if build_result.returncode != 0:
                return f"Failed to compile contract:\n\n{build_result.stderr}"
            
            # Find the build directory and ABI files
            build_dir = os.path.join(contract_path, "build")
            if not os.path.exists(build_dir):
                return "Build directory not found after compilation"
            
            # Generate TypeScript client if requested
            if output_format == "ts":
                output_dir = os.path.join(contract_path, "generated")
                os.makedirs(output_dir, exist_ok=True)
                
                # Use aptos CLI to generate TS SDK
                gen_cmd = [
                    "aptos", "move", "aptos-sdk-generate", 
                    "--output-dir", output_dir,
                    "--package-dir", contract_path
                ]
                
                gen_result = subprocess.run(gen_cmd, capture_output=True, text=True)
                
                if gen_result.returncode != 0:
                    return f"Failed to generate TypeScript SDK:\n\n{gen_result.stderr}"
                
                return f"Successfully generated TypeScript SDK at {output_dir}"
            
            # If JSON format, just return the ABI files
            abi_files = []
            for root, _, files in os.walk(build_dir):
                for file in files:
                    if file.endswith("abi.json"):
                        abi_files.append(os.path.join(root, file))
            
            if not abi_files:
                return "No ABI files found after compilation"
            
            # Return the contents of ABI files
            result = []
            for abi_file in abi_files:
                with open(abi_file, "r") as f:
                    abi_content = f.read()
                
                result.append(f"# {os.path.basename(abi_file)}\n```json\n{abi_content}\n```")
            
            return "\n\n".join(result)
        
        except Exception as e:
            return f"Error generating ABI: {str(e)}"
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 action ('Generate ABI') but fails to describe key traits: it doesn't mention if this is a read-only operation, what permissions are required, potential side effects (e.g., file creation), or error handling. This leaves significant gaps in understanding the tool's behavior.

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 front-loaded with the main purpose, followed by a brief 'Args' section listing parameters. It's efficient with minimal waste, though the structure could be slightly improved by integrating parameter details more seamlessly. Overall, it's appropriately sized for its content.

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 the complexity (a code generation tool with 2 parameters), no annotations, and no output schema, the description is incomplete. It doesn't explain what the ABI output entails, how it's delivered (e.g., file path or direct return), or error cases. This inadequacy could hinder effective tool use by an agent.

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?

The description adds basic semantics for both parameters: 'contract_path' is explained as 'Path to the contract directory' and 'output_format' as 'Format of the output (ts, json)'. Since schema description coverage is 0%, this compensates somewhat by clarifying parameter meanings. However, it lacks details like format specifics or path requirements, keeping it at a baseline level.

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's purpose: 'Generate ABI for an Aptos contract.' It specifies the verb ('Generate') and resource ('ABI for an Aptos contract'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'generate_aptos_component' or 'test_aptos_contract', which may also involve contract-related operations, so it doesn't reach the highest score.

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 lacks context about prerequisites (e.g., needing a compiled contract), exclusions, or comparisons to sibling tools such as 'generate_aptos_component'. This absence leaves the agent without clear usage direction.

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/Tlazypanda/aptos-mcp-server'

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