Skip to main content
Glama

optimize_mirrors

Read-only

List, test, and optimize Arch Linux mirrors. Get speed-tested recommendations from archlinux.org or perform a full health check to identify issues.

Instructions

[MIRRORS] Smart mirror management - consolidates 4 mirror operations. Actions: 'status' (list configured mirrors), 'test' (test mirror speeds), 'suggest' (get optimal mirrors from archlinux.org), 'health' (full health check). Examples: optimize_mirrors(action='status', auto_test=True) lists and tests all mirrors; optimize_mirrors(action='suggest', country='US', limit=5) suggests top 5 US mirrors; optimize_mirrors(action='health') checks for issues and gives recommendations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesOperation to perform: 'status' (list mirrors), 'test' (test speeds), 'suggest' (get recommendations), 'health' (full check)
countryNoOptional country code for suggestions (e.g., 'US', 'DE') - action='suggest' only
mirror_urlNoSpecific mirror URL to test - action='test' only
limitNoNumber of mirrors for suggestions (default 10)
auto_testNoIf true, test mirrors after listing - action='status' only

Implementation Reference

  • The main handler function for the optimize_mirrors tool. It dispatches to sub-actions: 'status' (list mirrors), 'test' (test mirror speed), 'suggest' (get recommendations), and 'health' (full health check). Uses helper functions list_active_mirrors, test_mirror_speed, suggest_fastest_mirrors, check_mirrorlist_health.
    async def optimize_mirrors(
        action: str = "status",
        country: Optional[str] = None,
        mirror_url: Optional[str] = None,
        limit: int = 10,
        auto_test: bool = False
    ) -> Dict[str, Any]:
        """
        Smart mirror management tool that consolidates 4 mirror operations.
    
        Args:
            action: Operation to perform - "status" (list mirrors), "test" (test speed),
                    "suggest" (get recommendations), or "health" (full health check)
            country: Optional country code for suggestions (e.g., 'US', 'DE')
            mirror_url: Specific mirror URL to test (action="test" only)
            limit: Number of mirrors for suggestions (default 10)
            auto_test: If True, automatically test mirrors after listing (action="status" only)
    
        Returns:
            Dict with results based on action:
            - "status": Current mirror configuration with optional test results
            - "test": Speed test results for specified or all mirrors
            - "suggest": Recommended mirrors from archlinux.org
            - "health": Comprehensive health assessment with issues and recommendations
    
        Examples:
            # Check current mirror configuration
            optimize_mirrors(action="status")
    
            # Test specific mirror
            optimize_mirrors(action="test", mirror_url="https://mirror.example.com")
    
            # Get top 10 fastest mirrors for US
            optimize_mirrors(action="suggest", country="US", limit=10)
    
            # Full health check
            optimize_mirrors(action="health")
    
            # List mirrors and auto-test them
            optimize_mirrors(action="status", auto_test=True)
        """
        logger.info(f"Optimizing mirrors: action={action}, country={country}, auto_test={auto_test}")
    
        try:
            if action == "status":
                # Get current mirror configuration
                result = await list_active_mirrors()
                if "error" in result:
                    return result
    
                response = {
                    "action": "status",
                    "configuration": result
                }
    
                # Optionally run speed tests
                if auto_test:
                    logger.info("Auto-testing mirror speeds...")
                    test_result = await test_mirror_speed()
                    if "error" not in test_result:
                        response["speed_tests"] = test_result
    
                return response
    
            elif action == "test":
                # Test mirror speeds
                return {
                    "action": "test",
                    "results": await test_mirror_speed(mirror_url=mirror_url)
                }
    
            elif action == "suggest":
                # Get mirror suggestions
                return {
                    "action": "suggest",
                    "recommendations": await suggest_fastest_mirrors(country=country, limit=limit)
                }
    
            elif action == "health":
                # Comprehensive health check
                health_result = await check_mirrorlist_health()
    
                if "error" in health_result:
                    return health_result
    
                # Also get current configuration for context
                config_result = await list_active_mirrors()
                if "error" not in config_result:
                    health_result["configuration"] = {
                        "active_count": config_result.get("active_count", 0),
                        "commented_count": config_result.get("commented_count", 0),
                        "active_mirrors": config_result.get("active_mirrors", [])
                    }
    
                return {
                    "action": "health",
                    "assessment": health_result
                }
    
            else:
                return create_error_response(
                    "InvalidAction",
                    f"Invalid action '{action}'. Must be one of: status, test, suggest, health"
                )
    
        except Exception as e:
            logger.error(f"Mirror optimization failed: {e}")
            return create_error_response(
                "OptimizationError",
                f"Failed to optimize mirrors: {str(e)}"
            )
  • Tool registration in the MCP server via @server.list_tools(). Defines the tool name 'optimize_mirrors', description, inputSchema with 5 parameters (action, country, mirror_url, limit, auto_test), and read-only annotations.
    # Mirror Management Tools
    Tool(
        name="optimize_mirrors",
        description="[MIRRORS] Smart mirror management - consolidates 4 mirror operations. Actions: 'status' (list configured mirrors), 'test' (test mirror speeds), 'suggest' (get optimal mirrors from archlinux.org), 'health' (full health check). Examples: optimize_mirrors(action='status', auto_test=True) lists and tests all mirrors; optimize_mirrors(action='suggest', country='US', limit=5) suggests top 5 US mirrors; optimize_mirrors(action='health') checks for issues and gives recommendations.",
        inputSchema={
            "type": "object",
            "properties": {
                "action": {
                    "type": "string",
                    "enum": ["status", "test", "suggest", "health"],
                    "description": "Operation to perform: 'status' (list mirrors), 'test' (test speeds), 'suggest' (get recommendations), 'health' (full check)"
                },
                "country": {
                    "type": "string",
                    "description": "Optional country code for suggestions (e.g., 'US', 'DE') - action='suggest' only"
                },
                "mirror_url": {
                    "type": "string",
                    "description": "Specific mirror URL to test - action='test' only"
                },
                "limit": {
                    "type": "integer",
                    "description": "Number of mirrors for suggestions (default 10)",
                    "default": 10
                },
                "auto_test": {
                    "type": "boolean",
                    "description": "If true, test mirrors after listing - action='status' only",
                    "default": False
                }
            },
            "required": ["action"]
        },
        annotations=ToolAnnotations(readOnlyHint=True)
    ),
  • Tool invocation handler in @server.call_tool() that dispatches the 'optimize_mirrors' name to the async handler function, extracting arguments and calling optimize_mirrors().
    elif name == "optimize_mirrors":
        action = arguments.get("action")
        country = arguments.get("country")
        mirror_url = arguments.get("mirror_url")
        limit = arguments.get("limit", 10)
        auto_test = arguments.get("auto_test", False)
        
        result = await optimize_mirrors(
            action=action,
            country=country,
            mirror_url=mirror_url,
            limit=limit,
            auto_test=auto_test
        )
        return [TextContent(type="text", text=json.dumps(result, indent=2))]
  • ToolMetadata definition for optimize_mirrors. Categorized as 'mirrors', platform 'arch', permission 'read', workflow 'optimize'. Related tools: analyze_pacman_conf, check_disk_space.
    "optimize_mirrors": ToolMetadata(
        name="optimize_mirrors",
        category="mirrors",
        platform="arch",
        permission="read",
        workflow="optimize",
        related_tools=["analyze_pacman_conf", "check_disk_space"],
        prerequisite_tools=[]
    ),
  • Module export of optimize_mirrors from mirrors.py, making it available as a top-level import.
    from .mirrors import (
        list_active_mirrors,
        test_mirror_speed,
        suggest_fastest_mirrors,
        check_mirrorlist_health,
        optimize_mirrors,
    )
Behavior4/5

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

Annotations indicate readOnlyHint=true, and the description aligns with this by describing read-only operations like listing, testing, and suggesting. It adds behavioral context such as what each action does (e.g., health check gives recommendations).

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 well-structured with a tag, action list, and examples. It is informative without being overly verbose, though the examples could be slightly more compact.

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

Completeness3/5

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

While the description explains what each action does, it does not specify the return format or output structure. For a tool with no output schema, more detail on the response (e.g., list of mirrors, test results) would improve completeness.

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?

Schema coverage is 100%, so baseline is 3. The description adds examples showing parameter combinations (e.g., action='suggest' with country and limit), but the schema already documents all parameters and their constraints.

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

Purpose5/5

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

The description clearly states it is for 'smart mirror management' and lists four specific actions (status, test, suggest, health). It distinguishes itself from sibling tools which focus on system configuration analysis and package management.

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 each action with examples and notes which parameters apply to which action. However, it does not explicitly mention when not to use this tool or suggest alternatives among siblings.

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/nihalxkumar/arch-mcp'

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