Skip to main content
Glama

ida_add_function_comment

Add comments to functions in the IDA database to enhance code understanding and documentation. Specify the function name and comment content for clear annotations.

Instructions

Add a comment to a function in the IDA database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commentYes
function_nameYes
is_repeatableNo

Implementation Reference

  • Core handler implementation in IDA plugin that executes idc.set_func_cmt to add the function comment, with validation and view refresh.
    def add_function_comment(self, function_name: str, comment: str, is_repeatable: bool) -> Dict[str, Any]: """Add a comment to a function""" return self._add_function_comment_internal(function_name, comment, is_repeatable) def _add_function_comment_internal(self, function_name: str, comment: str, is_repeatable: bool) -> Dict[str, Any]: """Internal implementation for add_function_comment without sync wrapper""" try: # Parameter validation if not function_name: return {"success": False, "message": "Function name cannot be empty"} if not comment: # Allow empty comment to clear the comment comment = "" # Get function address func_addr: int = ida_name.get_name_ea(0, function_name) if func_addr == idaapi.BADADDR: return {"success": False, "message": f"Function '{function_name}' not found"} # Check if it's a function func: Optional[ida_funcs.func_t] = ida_funcs.get_func(func_addr) if not func: return {"success": False, "message": f"'{function_name}' is not a function"} # Open pseudocode view ida_hexrays.open_pseudocode(func_addr, 0) # Add function comment # is_repeatable=True means show comment at all references to this function # is_repeatable=False means show comment only at function definition result: bool = idc.set_func_cmt(func_addr, comment, is_repeatable) if result: # Refresh view self._refresh_view_internal() comment_type: str = "repeatable" if is_repeatable else "regular" return {"success": True, "message": f"Added {comment_type} comment to function '{function_name}'"} else: return {"success": False, "message": f"Failed to add comment to function '{function_name}'"} except Exception as e: print(f"Error adding function comment: {str(e)}") traceback.print_exc() return {"success": False, "message": str(e)}
  • Pydantic input schema defining parameters: function_name, comment, is_repeatable.
    class AddFunctionComment(BaseModel): function_name: str comment: str is_repeatable: bool = False # Whether the comment should be repeatable
  • MCP tool registration in list_tools() with name 'ida_add_function_comment' and schema.
    Tool( name=IDATools.ADD_FUNCTION_COMMENT, description="Add a comment to a function in the IDA database", inputSchema=AddFunctionComment.schema(), ),
  • Handler in IDAProFunctions that sends the 'add_function_comment' socket request to IDA plugin.
    def add_function_comment(self, function_name: str, comment: str, is_repeatable: bool = False) -> str: """Add a comment to a function""" try: response: Dict[str, Any] = self.communicator.send_request( "add_function_comment", {"function_name": function_name, "comment": comment, "is_repeatable": is_repeatable} ) if "error" in response: return f"Error adding comment to function '{function_name}': {response['error']}" success: bool = response.get("success", False) message: str = response.get("message", "") if success: comment_type: str = "repeatable" if is_repeatable else "regular" return f"Successfully added {comment_type} comment to function '{function_name}': {message}" else: return f"Failed to add comment to function '{function_name}': {message}" except Exception as e: self.logger.error(f"Error adding function comment: {str(e)}", exc_info=True) return f"Error adding comment to function '{function_name}': {str(e)}"
  • Socket request dispatcher in IDA plugin that calls core.add_function_comment.
    elif request_type == "add_function_comment": response.update(self.core.add_function_comment( request_data.get("function_name", ""), request_data.get("comment", ""), request_data.get("is_repeatable", False) ))
  • Enum defining the tool name constant IDATools.ADD_FUNCTION_COMMENT = "ida_add_function_comment".
    class IDATools(str, Enum): GET_FUNCTION_ASSEMBLY_BY_NAME = "ida_get_function_assembly_by_name" GET_FUNCTION_ASSEMBLY_BY_ADDRESS = "ida_get_function_assembly_by_address" GET_FUNCTION_DECOMPILED_BY_NAME = "ida_get_function_decompiled_by_name" GET_FUNCTION_DECOMPILED_BY_ADDRESS = "ida_get_function_decompiled_by_address" GET_GLOBAL_VARIABLE_BY_NAME = "ida_get_global_variable_by_name" GET_GLOBAL_VARIABLE_BY_ADDRESS = "ida_get_global_variable_by_address" GET_CURRENT_FUNCTION_ASSEMBLY = "ida_get_current_function_assembly" GET_CURRENT_FUNCTION_DECOMPILED = "ida_get_current_function_decompiled" RENAME_LOCAL_VARIABLE = "ida_rename_local_variable" RENAME_GLOBAL_VARIABLE = "ida_rename_global_variable" RENAME_FUNCTION = "ida_rename_function" RENAME_MULTI_LOCAL_VARIABLES = "ida_rename_multi_local_variables" RENAME_MULTI_GLOBAL_VARIABLES = "ida_rename_multi_global_variables" RENAME_MULTI_FUNCTIONS = "ida_rename_multi_functions" ADD_ASSEMBLY_COMMENT = "ida_add_assembly_comment" ADD_FUNCTION_COMMENT = "ida_add_function_comment" ADD_PSEUDOCODE_COMMENT = "ida_add_pseudocode_comment" EXECUTE_SCRIPT = "ida_execute_script" EXECUTE_SCRIPT_FROM_FILE = "ida_execute_script_from_file"

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/MxIris-Reverse-Engineering/ida-mcp-server'

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