Skip to main content
Glama

list_functions

Retrieve a paginated list of all functions in the IDA Pro database. Specify offset and count to navigate and extract function data efficiently.

Instructions

List all functions in the database (paginated)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYesNumber of functions to list (100 is a good default, 0 means remainder)
offsetYesOffset to start listing from (start at 0)

Implementation Reference

  • Handler function implementing the list_funcs MCP tool. Lists functions from the current IDB with optional pagination (offset/count) and filtering by name pattern (glob/regex). Returns paginated results as Page[Function]. Uses helpers like pattern_filter and paginate.
    @tool
    @idaread
    def list_funcs(
        queries: Annotated[
            list[ListQuery] | ListQuery | str,
            "List functions with optional filtering and pagination",
        ],
    ) -> list[Page[Function]]:
        """List functions"""
        queries = normalize_dict_list(
            queries, lambda s: {"offset": 0, "count": 50, "filter": s}
        )
        all_functions = [get_function(addr) for addr in idautils.Functions()]
    
        results = []
        for query in queries:
            offset = query.get("offset", 0)
            count = query.get("count", 100)
            filter_pattern = query.get("filter", "")
    
            # Treat empty/"*" filter as "all"
            if filter_pattern in ("", "*"):
                filter_pattern = ""
    
            filtered = pattern_filter(all_functions, filter_pattern, "name")
            results.append(paginate(filtered, offset, count))
    
        return results
  • TypedDict schema for ListQuery input parameter used in list_funcs tool for filtering, offset, and count.
    class ListQuery(TypedDict, total=False):
        """Pagination query for listing operations"""
    
        filter: Annotated[str, "Optional glob pattern to filter results"]
        offset: Annotated[int, "Starting index (default: 0)"]
        count: Annotated[int, "Maximum number of results (default: 50, 0 for all)"]
  • TypedDict schema for Function output objects returned by list_funcs tool.
    class Function(TypedDict):
        addr: str
        name: str
        size: str
  • Generic Page schema wrapping paginated data with next_offset for list_funcs output.
    class Page(TypedDict, Generic[T]):
        data: list[T]
        next_offset: Optional[int]
  • Import of api_core module in package __init__.py which triggers registration of @tool decorated functions including list_funcs via the decorator.
    # Import all API modules to register @tool functions and @resource functions
    from . import api_core
  • paginate helper function used by list_funcs to handle pagination logic.
    def paginate(data: list[T], offset: int, count: int) -> Page[T]:
        if count == 0:
            count = len(data)
        next_offset = offset + count
        if next_offset >= len(data):
            next_offset = None
        return {
            "data": data[offset : offset + count],
            "next_offset": next_offset,
        }
  • pattern_filter helper used by list_funcs for filtering functions by name using glob, substring, or regex patterns.
    def pattern_filter(data: list[T], pattern: str, key: str) -> list[T]:
        if not pattern:
            return data
    
        regex = None
        use_glob = False
    
        # Regex pattern: /pattern/flags
        if pattern.startswith("/") and pattern.count("/") >= 2:
            last_slash = pattern.rfind("/")
            body = pattern[1:last_slash]
            flag_str = pattern[last_slash + 1 :]
    
            flags = 0
            for ch in flag_str:
                if ch == "i":
                    flags |= re.IGNORECASE
                elif ch == "m":
                    flags |= re.MULTILINE
                elif ch == "s":
                    flags |= re.DOTALL
    
            try:
                regex = re.compile(body, flags or re.IGNORECASE)
            except re.error:
                regex = None
        # Glob pattern: contains * or ?
        elif "*" in pattern or "?" in pattern:
            use_glob = True
    
        def get_value(item) -> str:
            try:
                v = item[key]
            except Exception:
                v = getattr(item, key, "")
            return "" if v is None else str(v)
    
        def matches(item) -> bool:
            text = get_value(item)
            if regex is not None:
                return bool(regex.search(text))
            if use_glob:
                return fnmatch.fnmatch(text.lower(), pattern.lower())
            return pattern.lower() in text.lower()
    
        return [item for item in data if matches(item)]

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/mrexodia/ida-pro-mcp'

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