Skip to main content
Glama

darwin_options_by_prefix

Find nix-darwin configuration options by prefix to browse categories or locate specific settings for macOS system configuration.

Instructions

Get nix-darwin options matching a specific prefix.

Useful for browsing options under a category or finding exact option names.

Args: option_prefix: The prefix to match (e.g., 'system.defaults' or 'services')

Returns: Plain text list of options with the given prefix, including descriptions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
option_prefixYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main async handler function for the 'darwin_options_by_prefix' tool. It calls parse_html_options with the DARWIN_URL and the given prefix to fetch matching nix-darwin options from HTML docs, formats them as plain text list.
    @mcp.tool()
    async def darwin_options_by_prefix(option_prefix: str) -> str:
        """Get nix-darwin options matching a specific prefix.
    
        Useful for browsing options under a category or finding exact option names.
    
        Args:
            option_prefix: The prefix to match (e.g., 'system.defaults' or 'services')
    
        Returns:
            Plain text list of options with the given prefix, including descriptions
        """
        try:
            options = parse_html_options(DARWIN_URL, "", option_prefix)
    
            if not options:
                return f"No nix-darwin options found with prefix '{option_prefix}'"
    
            results = []
            results.append(f"nix-darwin options with prefix '{option_prefix}' ({len(options)} found):\n")
    
            for opt in sorted(options, key=lambda x: x["name"]):
                results.append(f"• {opt['name']}")
                if opt["description"]:
                    results.append(f"  {opt['description']}")
                results.append("")
    
            return "\n".join(results).strip()
    
        except Exception as e:
            return error(str(e))
  • Shared helper function that parses HTML documentation pages (like nix-darwin manual) to extract configuration options matching a query or prefix. Used by multiple darwin_* tools including darwin_options_by_prefix.
    def parse_html_options(url: str, query: str = "", prefix: str = "", limit: int = 100) -> list[dict[str, str]]:
        """Parse options from HTML documentation."""
        try:
            resp = requests.get(url, timeout=30)  # Increase timeout for large docs
            resp.raise_for_status()
            # Use resp.content to let BeautifulSoup handle encoding detection
            # This prevents encoding errors like "unknown encoding: windows-1252"
            soup = BeautifulSoup(resp.content, "html.parser")
            options = []
    
            # Get all dt elements
            dts = soup.find_all("dt")
    
            for dt in dts:
                # Get option name
                name = ""
                if "home-manager" in url:
                    # Home Manager uses anchor IDs like "opt-programs.git.enable"
                    anchor = dt.find("a", id=True)
                    if anchor:
                        anchor_id = anchor.get("id", "")
                        # Remove "opt-" prefix and convert underscores
                        if anchor_id.startswith("opt-"):
                            name = anchor_id[4:]  # Remove "opt-" prefix
                            # Convert _name_ placeholders back to <name>
                            name = name.replace("_name_", "<name>")
                    else:
                        # Fallback to text content
                        name_elem = dt.find(string=True, recursive=False)
                        if name_elem:
                            name = name_elem.strip()
                        else:
                            name = dt.get_text(strip=True)
                else:
                    # Darwin and fallback - use text content
                    name = dt.get_text(strip=True)
    
                # Skip if it doesn't look like an option (must contain a dot)
                # But allow single-word options in some cases
                if "." not in name and len(name.split()) > 1:
                    continue
    
                # Filter by query or prefix
                if query and query.lower() not in name.lower():
                    continue
                if prefix and not (name.startswith(prefix + ".") or name == prefix):
                    continue
    
                # Find the corresponding dd element
                dd = dt.find_next_sibling("dd")
                if dd:
                    # Extract description (first p tag or direct text)
                    desc_elem = dd.find("p")
                    if desc_elem:
                        description = desc_elem.get_text(strip=True)
                    else:
                        # Get first text node, handle None case
                        text = dd.get_text(strip=True)
                        description = text.split("\n")[0] if text else ""
    
                    # Extract type info - look for various patterns
                    type_info = ""
                    # Pattern 1: <span class="term">Type: ...</span>
                    type_elem = dd.find("span", class_="term")
                    if type_elem and "Type:" in type_elem.get_text():
                        type_info = type_elem.get_text(strip=True).replace("Type:", "").strip()
                    # Pattern 2: Look for "Type:" in text
                    elif "Type:" in dd.get_text():
                        text = dd.get_text()
                        type_start = text.find("Type:") + 5
                        type_end = text.find("\n", type_start)
                        if type_end == -1:
                            type_end = len(text)
                        type_info = text[type_start:type_end].strip()
    
                    options.append(
                        {
                            "name": name,
                            "description": description[:200] if len(description) > 200 else description,
                            "type": type_info,
                        }
                    )
    
                    if len(options) >= limit:
                        break
    
            return options
        except Exception as exc:
            raise DocumentParseError(f"Failed to fetch docs: {str(exc)}") from exc
  • FastMCP decorator that registers the darwin_options_by_prefix function as an MCP tool, auto-generating schema from signature and docstring.
    @mcp.tool()
  • Tool docstring defining input schema (option_prefix: str) and output format (plain text list). FastMCP uses this for tool schema generation.
    """Get nix-darwin options matching a specific prefix.
    
    Useful for browsing options under a category or finding exact option names.
    
    Args:
        option_prefix: The prefix to match (e.g., 'system.defaults' or 'services')
    
    Returns:
        Plain text list of options with the given prefix, including descriptions
    """
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the return format ('Plain text list of options with the given prefix, including descriptions'), which is helpful. However, it doesn't cover other behavioral aspects like whether this is a read-only operation, potential rate limits, error conditions, or how it differs in behavior from similar tools like 'darwin_list_options'. The description adds some value but leaves gaps.

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: the first sentence states the core purpose, followed by usage guidelines, and then details on arguments and returns. Every sentence adds value without redundancy. It's appropriately sized for a single-parameter tool with clear functionality.

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's low complexity (1 parameter, no nested objects) and the presence of an output schema (which covers return values), the description is mostly complete. It explains the purpose, usage, parameter, and return format. However, with no annotations and many sibling tools, it could benefit from more differentiation or behavioral details to be fully comprehensive.

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?

The input schema has 1 parameter with 0% description coverage, so the description must compensate. It explains the parameter's purpose: 'option_prefix: The prefix to match (e.g., 'system.defaults' or 'services')', providing clear semantics and examples. This adds significant value beyond the bare schema. However, it doesn't detail constraints like format or length, so it's not a perfect score.

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: 'Get nix-darwin options matching a specific prefix.' It specifies the verb ('Get'), resource ('nix-darwin options'), and scope ('matching a specific prefix'). However, it doesn't explicitly differentiate from sibling tools like 'darwin_list_options' or 'darwin_search', which likely have overlapping functionality, 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 Guidelines4/5

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

The description provides clear context for when to use this tool: 'Useful for browsing options under a category or finding exact option names.' This gives practical guidance on its intended use cases. However, it doesn't explicitly state when not to use it or name alternatives among the many sibling tools, so it falls short of a perfect score.

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/utensils/mcp-nixos'

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